Skip to content

Commit

Permalink
Update arc end points again due to mutual dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
NicEastvillage committed Dec 15, 2023
1 parent b3c28ce commit a63ce8f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/main/java/pipe/gui/petrinet/graphicElements/Arc.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,19 @@ public PlaceTransitionObject getTarget() {
* the bounds
*/
public void updateArcPosition() {
if (source != null) {
// The positions of end points are mutually dependant, so we update both an extra time
if (target != null) {
target.updateEndPoint(this);
}
if (source != null) {
source.updateEndPoint(this);
}
if (target != null) {
target.updateEndPoint(this);
}
if (source != null) {
source.updateEndPoint(this);
}
myPath.createPath();
}

Expand Down Expand Up @@ -291,7 +298,7 @@ public void paintComponent(Graphics g) {
g2.translate(myPath.getPoint(myPath.getEndIndex()).getX(), myPath.getPoint(myPath.getEndIndex()).getY());

//Rotate to match arrowhead to arc angle
g2.rotate(myPath.getEndAngle() + Math.PI);
g2.rotate(-myPath.getEndAngle() - Math.PI/2);
g2.setColor(java.awt.Color.WHITE);

g2.transform(Zoomer.getTransform(getZoom()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void setVisibilityLock(boolean lock) {
public double getAngle(Point2D.Double p2) {
double angle;

angle = Math.atan2( (getPoint().x - p2.x), (p2.y - getPoint().y) );
angle = Math.atan2( (p2.y - getPoint().y), (getPoint().x - p2.x) );

return angle;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/pipe/gui/petrinet/graphicElements/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ public void updateEndPoint(Arc arc) {
+ (getDiameter() * 0.5));
double angle = arc.getArcPath().getStartAngle();
arc.setSourceLocation(positionX + centreOffsetLeft()
- (0.5 * getDiameter() * (Math.sin(angle))), positionY
- (0.5 * getDiameter() * (Math.cos(angle))), positionY
+ centreOffsetTop()
+ (0.5 * getDiameter() * (Math.cos(angle))));
+ (0.5 * getDiameter() * (Math.sin(angle))));
} else {
// Make it calculate the angle from the centre of the place rather
// than the current target point
arc.setTargetLocation(positionX + (getDiameter() * 0.5), positionY
+ (getDiameter() * 0.5));
double angle = arc.getArcPath().getEndAngle();
arc.setTargetLocation(positionX + centreOffsetLeft()
- (0.5 * getDiameter() * (Math.sin(angle))), positionY
- (0.5 * getDiameter() * (Math.cos(angle))), positionY
+ centreOffsetTop()
+ (0.5 * getDiameter() * (Math.cos(angle))));
+ (0.5 * getDiameter() * (Math.sin(angle))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void updateEndPoints() {
transform.concatenate(Zoomer.getTransform(getZoom()));

arcIterator = top.iterator();
transform.transform(new Point2D.Double(1, 0.5 * TRANSITION_HEIGHT), transformed); // +1 due to rounding making it off by 1
transform.transform(new Point2D.Double(1, 0.5 * TRANSITION_HEIGHT), transformed); // 1 on x due to rounding error
while (arcIterator.hasNext()) {
ArcAngleCompare thisArc = arcIterator.next();

Expand All @@ -290,7 +290,7 @@ public void updateEndPoints() {
}

arcIterator = bottom.iterator();
transform.transform(new Point2D.Double(0, -0.5 * TRANSITION_HEIGHT), transformed);
transform.transform(new Point2D.Double(-1, -0.5 * TRANSITION_HEIGHT), transformed); // -1 on x due to rounding error
while (arcIterator.hasNext()) {
ArcAngleCompare thisArc = arcIterator.next();

Expand Down

0 comments on commit a63ce8f

Please sign in to comment.