diff --git a/src/net/sourceforge/fidocadj/primitives/Arrow.java b/src/net/sourceforge/fidocadj/primitives/Arrow.java index 8e9494c1..1ed441f0 100644 --- a/src/net/sourceforge/fidocadj/primitives/Arrow.java +++ b/src/net/sourceforge/fidocadj/primitives/Arrow.java @@ -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, @@ -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); } diff --git a/src/net/sourceforge/fidocadj/primitives/PrimitiveBezier.java b/src/net/sourceforge/fidocadj/primitives/PrimitiveBezier.java index b06b8f7e..8fbc9fc8 100644 --- a/src/net/sourceforge/fidocadj/primitives/PrimitiveBezier.java +++ b/src/net/sourceforge/fidocadj/primitives/PrimitiveBezier.java @@ -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 @@ -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) diff --git a/src/net/sourceforge/fidocadj/primitives/PrimitiveComplexCurve.java b/src/net/sourceforge/fidocadj/primitives/PrimitiveComplexCurve.java index bde5aec9..9987bd78 100644 --- a/src/net/sourceforge/fidocadj/primitives/PrimitiveComplexCurve.java +++ b/src/net/sourceforge/fidocadj/primitives/PrimitiveComplexCurve.java @@ -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()) { @@ -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); + } } } @@ -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) diff --git a/src/net/sourceforge/fidocadj/primitives/PrimitiveLine.java b/src/net/sourceforge/fidocadj/primitives/PrimitiveLine.java index f2921811..0645f034 100644 --- a/src/net/sourceforge/fidocadj/primitives/PrimitiveLine.java +++ b/src/net/sourceforge/fidocadj/primitives/PrimitiveLine.java @@ -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);