Skip to content

Commit

Permalink
#172. Arrow lenght can be negative. In this case, the arrow extends o…
Browse files Browse the repository at this point in the history
…utside of the element.
  • Loading branch information
DarwinNE committed Apr 21, 2020
1 parent 1afb1f1 commit e0f08ef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 28 deletions.
8 changes: 6 additions & 2 deletions src/net/sourceforge/fidocadj/primitives/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ public PointG drawArrowPixels(GraphicsInterface g, int x, int y, int xc,
@param xc the x coordinate of the direction point.
@param yc the y coordinate of the direction point.
@param Pbase return the coordinate of the base point of the arrow head.
If Pbase is specified, it modifies its values. If it is null,
nothing will be stored.
@return true if the coordinates are inside the arrow.
*/
public boolean isInArrow(int xs, int ys, int x, int y, int xc, int yc,
Expand All @@ -373,8 +375,10 @@ public boolean isInArrow(int xs, int ys, int x, int y, int xc, int yc,
yp[1]=(int)Math.round(P[1].y);
yp[2]=(int)Math.round(P[2].y);

Pbase.x=(int)Math.round(P[0].x);
Pbase.y=(int)Math.round(P[0].y);
if(Pbase!=null) {
Pbase.x=(int)Math.round(P[0].x);
Pbase.y=(int)Math.round(P[0].y);
}
return GeometricDistances.pointInPolygon(xp,yp,3,xs,ys);
}

Expand Down
51 changes: 38 additions & 13 deletions src/net/sourceforge/fidocadj/primitives/PrimitiveBezier.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,22 @@ public void draw(GraphicsInterface g, MapCoordinates coordSys,
// Check if there are arrows to be drawn and eventually draw them.
if (arrowData.atLeastOneArrow()) {
h=arrowData.prepareCoordinateMapping(coordSys);
if (arrowData.isArrowStart())
P0=drawArrow(g, coordSys, 0,1,2,3);
// If the arrow length is negative, the arrow extends
// outside the line, so the limits must not be changed.

if (arrowData.isArrowStart()) {
if(arrowData.getArrowLength()>0)
P0=drawArrow(g, coordSys, 0,1,2,3);
else
drawArrow(g, coordSys, 0,1,2,3);
}

if (arrowData.isArrowEnd())
P3=drawArrow(g, coordSys, 3,2,1,0);
if (arrowData.isArrowEnd()) {
if(arrowData.getArrowLength()>0)
P3=drawArrow(g, coordSys, 3,2,1,0);
else
drawArrow(g, coordSys, 3,2,1,0);
}
}

// in the Bézier primitive, the four virtual points represent
Expand Down Expand Up @@ -367,15 +378,29 @@ public int getDistanceToPoint(int px, int py)
// We work with logic coordinates (default for MapCoordinates).
MapCoordinates m=new MapCoordinates();
arrowData.prepareCoordinateMapping(m);
if (arrowData.isArrowStart())
t=arrowData.isInArrow(px, py,
virtualPoint[0].x, virtualPoint[0].y,
virtualPoint[1].x, virtualPoint[1].y, P0);

if (arrowData.isArrowEnd())
r=arrowData.isInArrow(px, py,
virtualPoint[3].x, virtualPoint[3].y,
virtualPoint[2].x, virtualPoint[2].y, P3);
if (arrowData.isArrowStart()) {
if(arrowData.getArrowLength()>0) {
t=arrowData.isInArrow(px, py,
virtualPoint[0].x, virtualPoint[0].y,
virtualPoint[1].x, virtualPoint[1].y, P0);
} else {
t=arrowData.isInArrow(px, py,
virtualPoint[0].x, virtualPoint[0].y,
virtualPoint[1].x, virtualPoint[1].y, null);
}
}

if (arrowData.isArrowEnd()) {
if(arrowData.getArrowLength()>0) {
r=arrowData.isInArrow(px, py,
virtualPoint[3].x, virtualPoint[3].y,
virtualPoint[2].x, virtualPoint[2].y, P3);
} else {
r=arrowData.isInArrow(px, py,
virtualPoint[3].x, virtualPoint[3].y,
virtualPoint[2].x, virtualPoint[2].y, null);
}
}

// Click on one of the arrows.
if(r||t)
Expand Down
26 changes: 17 additions & 9 deletions src/net/sourceforge/fidocadj/primitives/PrimitiveComplexCurve.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ public CurveStorage createComplexCurve(MapCoordinates coordSys)
(int)Math.round(Y[0].eval(0)),
(int)Math.round(X[0].eval(0.05)),
(int)Math.round(Y[0].eval(0.05)), P);
xPoints[0]=P.x;
yPoints[0]=P.y;
if(arrowData.getArrowLength()>0) {
xPoints[0]=P.x;
yPoints[0]=P.y;
}
}

if (arrowData.isArrowEnd()) {
Expand All @@ -282,15 +284,21 @@ public CurveStorage createComplexCurve(MapCoordinates coordSys)
(int)Math.round(Y[l].eval(1)),
(int)Math.round(X[l].eval(0.95)),
(int)Math.round(Y[l].eval(0.95)), P);
xPoints[nPoints-1]=P.x;
yPoints[nPoints-1]=P.y;
if(arrowData.getArrowLength()>0) {
xPoints[nPoints-1]=P.x;
yPoints[nPoints-1]=P.y;
}
}
// Since the arrow will occupy a certain size, the curve has
// to be recalculated. This means that the previous evaluation
// are just approximations, but the practice shows that they
// are enough for all purposes that can be foreseen.
X = calcNaturalCubic(nPoints-1, xPoints);
Y = calcNaturalCubic(nPoints-1, yPoints);
// This is not needed if the length is negative, as in this
// case the arrow extends outside the curve.
if(arrowData.getArrowLength()>0) {
X = calcNaturalCubic(nPoints-1, xPoints);
Y = calcNaturalCubic(nPoints-1, yPoints);
}
}
}

Expand Down Expand Up @@ -855,16 +863,16 @@ public int getDistanceToPoint(int px, int py)
// We work with logic coordinates (default for MapCoordinates).
MapCoordinates m=new MapCoordinates();
arrowData.prepareCoordinateMapping(m);
PointG P=new PointG();
if (arrowData.isArrowStart())
t=arrowData.isInArrow(px, py,
virtualPoint[0].x, virtualPoint[0].y,
xpoints[0], ypoints[0], P);
xpoints[0], ypoints[0], null);

if (arrowData.isArrowEnd())
r=arrowData.isInArrow(px, py,
xpoints[q.getNpoints()-1], ypoints[q.getNpoints()-1],
virtualPoint[nPoints-1].x, virtualPoint[nPoints-1].y, P);
virtualPoint[nPoints-1].x, virtualPoint[nPoints-1].y,
null);

// Click on one of the arrows.
if(r||t)
Expand Down
16 changes: 12 additions & 4 deletions src/net/sourceforge/fidocadj/primitives/PrimitiveLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,22 @@ public void draw(GraphicsInterface g, MapCoordinates coordSys,
if (arrowData.isArrowStart()) {
PointG p=arrowData.drawArrow(g,x1,y1,x2,y2);
// This fixes issue #172
xstart=p.x;
ystart=p.y;
// If the arrow length is negative, the arrow extends
// outside the line, so the limits must not be changed.
if(arrowData.getArrowLength()>0) {
xstart=p.x;
ystart=p.y;
}
}
if (arrowData.isArrowEnd()) {
PointG p=arrowData.drawArrow(g,x2,y2,x1,y1);
// This fixes issue #172
xend=p.x;
yend=p.y;
// If the arrow length is negative, the arrow extends
// outside the line, so the limits must not be changed.
if(arrowData.getArrowLength()>0) {
xend=p.x;
yend=p.y;
}
}
}
g.drawLine(xstart,ystart,xend,yend);
Expand Down

0 comments on commit e0f08ef

Please sign in to comment.