@@ -30,7 +30,7 @@ public Arc(Place place, int poids, double xOrigin, double yOrigin, boolean place
30
30
this .placeToTransition = placeToTransition ;
31
31
this .transition = transition ;
32
32
this .forme = new Line2D .Double (xOrigin , yOrigin , this .place .getX (), this .place .getY ());
33
- this .pointCtr1 = new PointControle ();
33
+ this .pointCtr1 = new PointControle (0 , 0 , this );
34
34
}
35
35
36
36
/**
@@ -54,6 +54,10 @@ public Arc(Place place, int poids){
54
54
*/
55
55
public Place getPlace () { return this .place ; }
56
56
57
+ public Transition getTransition () { return transition ; }
58
+
59
+ public boolean isPlaceToTransition () { return placeToTransition ; }
60
+
57
61
/**
58
62
* Méthode qui permet de récupérer le poids de l'arc.
59
63
* @return poids.
@@ -70,7 +74,12 @@ public Arc(Place place, int poids){
70
74
* Méthode qui permet de donner/modifier le poids d'un arc.
71
75
* @param poids Poids de l'arc
72
76
*/
73
- public void setPoids (int poids ) { this .poids = poids ; }
77
+ public void setPoids (int poids ) {
78
+ if (poids >= 1 ) {
79
+ this .poids = poids ;
80
+ }
81
+ }
82
+
74
83
75
84
/**
76
85
* Méthode qui permet d'afficher les caractéristiques de l'arc : {place,poids}.
@@ -81,13 +90,20 @@ public String toString() {
81
90
return "Arc{" +
82
91
"place=" + place +
83
92
", poids=" + poids +
93
+ ", placetoTransition=" + placeToTransition +
94
+ ", ptctrl= " + pointCtr1 +
84
95
'}' ;
85
96
}
86
97
87
98
/* Partie Graphique */
88
99
89
100
public Line2D .Double forme ;
101
+ public QuadCurve2D .Double courbe ;
90
102
public AffineTransform at ;
103
+ public AffineTransform reverse ;
104
+ public Path2D .Double hitbox ;
105
+ public Path2D arrowHead ;
106
+
91
107
92
108
/**
93
109
* Méthode qui permet de dessiner un arc.
@@ -116,30 +132,63 @@ private void drawArrow(Graphics2D g2, double oX, double oY, double dX, double dY
116
132
at .concatenate (AffineTransform .getRotateInstance (angle ));
117
133
g2 .transform (at );
118
134
135
+ reverse = getReverseAt ();
136
+
119
137
/* Ligne */
120
138
if (!this .pointCtr1 .getMoved ()) {
121
139
this .pointCtr1 .setX ((start + len -ARR_SIZE )/2 );
122
140
this .pointCtr1 .setY (0 );
123
141
}
124
142
125
143
/*point de controle*/
126
- pointCtr1 .draw (g2 );
127
-
128
- QuadCurve2D .Double courbe = new QuadCurve2D .Double (start , 0 , this .pointCtr1 .getX (), this .pointCtr1 .getY (), len , 0 );
129
- /* Référentiel */
144
+ //pointCtr1.draw(g2);
130
145
146
+ courbe = new QuadCurve2D .Double (start , 0 , this .pointCtr1 .getX (), this .pointCtr1 .getY (), len , 0 );
131
147
g2 .draw (courbe );
132
148
149
+
150
+ hitbox = new Path2D .Double (arcHitbox (len ));
151
+ //g2.draw(hitbox);
152
+
153
+ // Line between control Point and ArrowHead Point
154
+ Line2D .Double line1 = new Line2D .Double (0 ,0 ,len ,0 );
155
+ Line2D .Double line2 = new Line2D .Double (pointCtr1 .getX (),pointCtr1 .getY (),len ,0 );
156
+ //g2.draw(line1);
157
+ //g2.draw(line2);
158
+
133
159
/* Fléche */
134
- Path2D path = new Path2D .Double ();
135
- double [] xval = {len , len -ARR_SIZE , len -ARR_SIZE , len };
136
- double [] yval = {0 , -ARR_SIZE , ARR_SIZE , 0 };
137
- path .moveTo (xval [0 ], yval [0 ]);
160
+ arrowHead = new Path2D .Double ();
161
+ double [] xval = {line2 . getX2 (), line2 . getX2 () -ARR_SIZE , line2 . getX2 () -ARR_SIZE , line2 . getX2 () };
162
+ double [] yval = {line2 . getY2 () , -ARR_SIZE , ARR_SIZE , line2 . getY2 () };
163
+ arrowHead .moveTo (xval [0 ], yval [0 ]);
138
164
for (int i = 1 ; i < xval .length ; ++i ) {
139
- path .lineTo (xval [i ], yval [i ]);
165
+ arrowHead .lineTo (xval [i ], yval [i ]);
140
166
}
141
- path .closePath ();
142
- g2 .fill (path );
167
+ arrowHead .closePath ();
168
+
169
+ AffineTransform rotate = new AffineTransform (AffineTransform .getRotateInstance (Math .toRadians (angleBetween2Lines (line1 ,line2 )),line2 .getX2 (), line2 .getY2 ()));
170
+ arrowHead .transform (rotate );
171
+
172
+ g2 .fill (arrowHead );
173
+
174
+ /* Affichage du poids */
175
+ if (this .poids > 1 ) {
176
+ g2 .setFont (new Font ("Console" , Font .PLAIN , 15 ));
177
+ if (this .placeToTransition && this .transition .getX () < this .place .getX () || !this .placeToTransition && this .place .getX () < this .transition .getX ()){
178
+ g2 .scale (-1 ,-1 );
179
+ g2 .drawString (Integer .toString (poids ), (int ) -courbe .getCtrlX (), (int ) -(courbe .getCtrlY () - 15 ));
180
+ g2 .scale (1 ,1 );
181
+ }else {
182
+ g2 .drawString (Integer .toString (poids ), (int ) courbe .getCtrlX (), (int ) courbe .getCtrlY () + 15 );
183
+ }
184
+ }
185
+ }
186
+
187
+ public static double angleBetween2Lines (Line2D .Double line1 , Line2D .Double line2 )
188
+ {
189
+ double angle1 = Math .atan2 (line1 .getY1 () - line1 .getY2 (), line1 .getX1 () - line1 .getX2 ());
190
+ double angle2 = Math .atan2 (line2 .getY1 () - line2 .getY2 (), line2 .getX1 () - line2 .getX2 ());
191
+ return -(Math .toDegrees (Math .abs (angle1 -angle2 ))+360 )%360 ;
143
192
}
144
193
145
194
/**
@@ -173,6 +222,18 @@ public void draw(Graphics g) {
173
222
174
223
}
175
224
225
+ public Path2D .Double arcHitbox (double len ){
226
+ int ecart = 7 ;
227
+ Path2D .Double hitbox = new Path2D .Double ();
228
+ hitbox .moveTo (this .place .forme .width /2 ,-ecart );
229
+ hitbox .quadTo (this .pointCtr1 .getX (),this .pointCtr1 .getY () -ecart ,len ,-ecart );
230
+ hitbox .lineTo (len ,+ecart );
231
+ hitbox .quadTo (this .pointCtr1 .getX (),this .pointCtr1 .getY ()+ecart , this .place .forme .width /2 ,+ecart );
232
+ hitbox .lineTo (this .place .forme .width /2 ,-ecart );
233
+ hitbox .closePath ();
234
+ return hitbox ;
235
+ }
236
+
176
237
/**
177
238
* Retourne true lorsque la différence absolue entre les coordonnées du point
178
239
* d'origine et du point à comparer (toCompare) est inférieur à la valeur size
@@ -201,13 +262,16 @@ public boolean containsControlPoint1(double x, double y) {
201
262
Point .Double point = new Point .Double (pointCtr1 .getX (),pointCtr1 .getY ());
202
263
Point2D .Double pointDest = new Point .Double ();
203
264
204
- at .transform (point , pointDest );
265
+ getAt () .transform (point , pointDest );
205
266
206
267
System .out .println ("PtCtrlTRANSFORM:(" + pointDest .getX () + ":" + pointDest .getY () + ") PtCtrl:(" + pointCtr1 .getX () + ":" + pointCtr1 .getY ()+ ")" );
207
268
208
- boolean res = containing (pointDest , pointCtr1 .getSize (), new Point .Double (x ,y ));
209
- System .out .println (res );
210
- return res ;
269
+ boolean res = containing (pointDest , pointCtr1 .getSize ()+ pointCtr1 .getSize ()/2 , new Point .Double (x ,y ));
270
+
271
+ boolean result = pointCtr1 .contains (x ,y );
272
+ System .out .println (result );
273
+ return result ;
274
+
211
275
}
212
276
213
277
/**
@@ -218,6 +282,17 @@ public PointControle getPointCtr1() {
218
282
return pointCtr1 ;
219
283
}
220
284
285
+ public AffineTransform getAt () { return at ; }
286
+
287
+ public AffineTransform getReverseAt () {
288
+ try {
289
+ return at .createInverse ();
290
+ } catch (Exception e ) {
291
+ e .printStackTrace ();
292
+ }
293
+ return null ;
294
+ }
295
+
221
296
/**
222
297
* Méthode qui permet de mettre à jour les coordonnées de l'arc.
223
298
* @param x : x.
0 commit comments