annotate dwtx/draw2d/RoutingAnimator.d @ 103:2d6540440fe6

Replace static ctors with lazy init.
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 17:01:51 +0200
parents 95307ad235d9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2005 IBM Corporation and others.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14 module dwtx.draw2d.RoutingAnimator;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 import dwt.dwthelper.utils;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import dwtx.draw2d.geometry.Point;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 import dwtx.draw2d.geometry.PointList;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import dwtx.draw2d.Animator;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import dwtx.draw2d.RoutingListener;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import dwtx.draw2d.IFigure;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import dwtx.draw2d.Connection;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 import dwtx.draw2d.Animation;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 * Animates the routing of a connection. The animator will capture the effects of the
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 * connection's router, and the play back the placement of the routing, interpolating the
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 * intermediate routes.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 * <P>
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 * To use a routing animator, hook it as a routing listener for the connection whose
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 * points are to be animated, by calling {@link
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 * PolylineConnection#addRoutingListener(RoutingListener)}. An animator is active
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 * only when the Animation utility is activated.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 * @since 3.2
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 public class RoutingAnimator : Animator , RoutingListener {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39
103
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
40 private static RoutingAnimator INSTANCE_;
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
41 static RoutingAnimator INSTANCE(){
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
42 if( INSTANCE_ is null ){
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
43 synchronized( RoutingAnimator.classinfo ){
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
44 if( INSTANCE_ is null ){
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
45 INSTANCE_ = new RoutingAnimator();
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
46 }
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
47 }
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
48 }
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
49 return INSTANCE_;
98
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 }
103
2d6540440fe6 Replace static ctors with lazy init.
Frank Benoit <benoit@tionex.de>
parents: 98
diff changeset
51
98
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 * Constructs a routing animator for use with one or more connections. The default
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 * instance ({@link #getDefault()} can be used on any number of connections.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 *
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 * @since 3.2
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 protected this() { }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 * Overridden to sync initial and final states.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 * @see Animator#playbackStarting(IFigure)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 public void playbackStarting(IFigure connection) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 reconcileStates(cast(Connection)connection);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 * Returns the current state of the connection. Currently, this is a copy of the list of
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 * points. However this Object could change in future releases and should not be
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 * considered API.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 * @see Animator#getCurrentState(IFigure)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 protected Object getCurrentState(IFigure connection) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 return (cast(Connection)connection).getPoints().getCopy();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 * Returns the default instance.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 * @return the default instance
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 * @since 3.2
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 public static RoutingAnimator getDefault() {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 return INSTANCE;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 * Hooks invalidate for animation purposes.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 * @see RoutingListener#invalidate(Connection)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 public final void invalidate(Connection conn) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 if (Animation.isInitialRecording())
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 Animation.hookAnimator(conn, this);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 * Plays back the interpolated state.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 * @see Animator#playback(IFigure)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100 protected bool playback(IFigure figure) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 Connection conn = cast(Connection) figure;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 PointList list1 = cast(PointList)Animation.getInitialState(this, conn);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 PointList list2 = cast(PointList)Animation.getFinalState(this, conn);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 if (list1 is null) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 conn.setVisible(false);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107 return true;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 float progress = Animation.getProgress();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111 if (list1.size() is list2.size()) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112 Point pt1 = new Point(), pt2 = new Point();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 PointList points = conn.getPoints();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114 points.removeAllPoints();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
115 for (int i = 0; i < list1.size(); i++) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
116 list1.getPoint(pt2, i);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
117 list2.getPoint(pt1, i);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
118 pt1.x = cast(int)Math.round(pt1.x * progress + (1 - progress) * pt2.x);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
119 pt1.y = cast(int)Math.round(pt1.y * progress + (1 - progress) * pt2.y);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
120 points.addPoint(pt1);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
121 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
122 conn.setPoints(points);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
123 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
124 return true;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
125 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128 * Hooks post routing for animation purposes.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
129 * @see RoutingListener#postRoute(Connection)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
130 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
131 public final void postRoute(Connection connection) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132 if (Animation.isFinalRecording())
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 Animation.hookNeedsCapture(connection, this);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136 private void reconcileStates(Connection conn) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137 PointList points1 = cast(PointList)Animation.getInitialState(this, conn);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
138 PointList points2 = cast(PointList)Animation.getFinalState(this, conn);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 if (points1 !is null && points1.size() !is points2.size()) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 Point p = new Point(), q = new Point();
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 int size1 = points1.size() - 1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 int size2 = points2.size() - 1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
145
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
146 int i1 = size1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
147 int i2 = size2;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
148
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
149 double current1 = 1.0;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 double current2 = 1.0;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
152 double prev1 = 1.0;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
153 double prev2 = 1.0;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
154
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
155 while (i1 > 0 || i2 > 0) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 if (Math.abs(current1 - current2) < 0.1
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 && i1 > 0 && i2 > 0) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 //Both points are the same, use them and go on;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 prev1 = current1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 prev2 = current2;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 i1--;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
162 i2--;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
163 current1 = cast(double)i1 / size1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 current2 = cast(double)i2 / size2;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 } else if (current1 < current2) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166 //2 needs to catch up
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 // current1 < current2 < prev1
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
168 points1.getPoint(p, i1);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169 points1.getPoint(q, i1 + 1);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171 p.x = cast(int)(((q.x * (current2 - current1) + p.x * (prev1 - current2))
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 / (prev1 - current1)));
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173 p.y = cast(int)(((q.y * (current2 - current1) + p.y * (prev1 - current2))
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 / (prev1 - current1)));
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
175
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
176 points1.insertPoint(p, i1 + 1);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
177
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
178 prev1 = prev2 = current2;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
179 i2--;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
180 current2 = cast(double)i2 / size2;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
181
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
182 } else {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
183 //1 needs to catch up
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
184 // current2< current1 < prev2
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
185
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
186 points2.getPoint(p, i2);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
187 points2.getPoint(q, i2 + 1);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
188
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
189 p.x = cast(int)(((q.x * (current1 - current2) + p.x * (prev2 - current1))
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
190 / (prev2 - current2)));
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 p.y = cast(int)(((q.y * (current1 - current2) + p.y * (prev2 - current1))
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 / (prev2 - current2)));
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194 points2.insertPoint(p, i2 + 1);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 prev2 = prev1 = current1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
197 i1--;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 current1 = cast(double)i1 / size1;
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 * This callback is unused. Reserved for possible future use.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 * @see RoutingListener#remove(Connection)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
208 public final void remove(Connection connection) { }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211 * Hooks route to intercept routing during animation playback.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 * @see RoutingListener#route(Connection)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 public final bool route(Connection conn) {
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215 return Animation.isAnimating() && Animation.hookPlayback(conn, this);
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218 /**
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
219 * This callback is unused. Reserved for possible future use.
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220 * @see RoutingListener#setConstraint(Connection, Object)
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221 */
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 public final void setConstraint(Connection connection, Object constraint) { }
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223
95307ad235d9 Added Draw2d code, still work in progress
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224 }