Class LineSeg
java.lang.Object
org.eclipse.graphiti.ui.internal.util.draw2d.LineSeg
- All Implemented Interfaces:
Serializable,org.eclipse.draw2d.geometry.Translatable
public class LineSeg
extends Object
implements Serializable, org.eclipse.draw2d.geometry.Translatable
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEnumeration class for defining the keypoint along a line segment.static classEnumeration class for defining the orientations of a point relative to the line segment.static classStructure to hold onto trig values that represent an angle -
Constructor Summary
ConstructorsConstructorDescriptionLineSeg(org.eclipse.draw2d.geometry.Point ptStart, org.eclipse.draw2d.geometry.Point ptEnd) ConstructorLineSeg(LineSeg.KeyPoint start, int fromX, int fromY, float slope, long len, int xdir) Creates a segment using (fromX, fromY) as either the first point of the segment (start == Origin) or the midpoint of the segment (start == Midpoint), and using slope as its new slope and len as the new length. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancontainsPoint(org.eclipse.draw2d.geometry.Point aPoint, int tolerance) Checks if this line segment contains the given point within a tolerance value.final floatdistanceAlong(org.eclipse.draw2d.geometry.Point coord) Finds the percentage distance along this line segement where the given point resides.final longdistanceToPoint(int xCoord, int yCoord) Finds the perpendicular distance from a point coordinates to this line segment.booleandouble[]Returns array with 3 numbers in it, which are the coefficients of the generalized line equation of the line corresponding to this line segment a*x+b*y=c is the equation => result[0]=a, result[1]=b, result[2]=cfinal org.eclipse.draw2d.geometry.PointGet aPointrepresenting the lowest point value for this line segment.static double[]getLineEquation(double x1, double y1, double x2, double y2) Returns the coefficients of the generalized equation of the line passing through points (x1,y1) and (x2,y2) Generalized line equation: ax+by=c => a==result[0], b==result[1], c==result[2]org.eclipse.draw2d.geometry.PointListgetLineIntersectionsWithEllipse(org.eclipse.draw2d.geometry.Rectangle ellipseBounds) Calculates intersection points of the line of the line segment and ellipseorg.eclipse.draw2d.geometry.PointListgetLineIntersectionsWithLineSegs(org.eclipse.draw2d.geometry.PointList points) Calculates intersection points of the line that contains this line segment with a list of other line segments.org.eclipse.draw2d.geometry.PointListgetLinesIntersections(LineSeg line) Returns intersection points of two lines that contain this line segment and the argumet line segment.org.eclipse.draw2d.geometry.PointAccesssor to retrieve the origin point of the line segement.final LineSeggetParallelLineSegThroughPoint(org.eclipse.draw2d.geometry.Point ptLoc) Returns a newLineSegthat is parallel to this by the given distance.final org.eclipse.draw2d.geometry.PointGet points representing the highest point value for this line segment.org.eclipse.draw2d.geometry.PointAccesssor to retrieve the terminal point of the line segement.getTrigValues(org.eclipse.draw2d.geometry.Vector ptToVector) Gets the trig values associated with the angle from this line segment to the given vector.inthashCode()org.eclipse.draw2d.geometry.PointDetermines the intersect point between this line and the line passed in as a parameter.final booleanDetermines if this a horizontal segmentfinal booleanDetermines if this a vertical segmentfinal doublelength()Calculate the length of the line segment.final org.eclipse.draw2d.geometry.PointlocatePoint(double pctDist, long theHeight, LineSeg.Sign asOriented) Locates a point at a given height and distance along the line segment.voidperformScale(double factor) voidperformTranslate(int dx, int dy) final org.eclipse.draw2d.geometry.PointperpIntersect(int startX, int startY) Calculates the perpendicular intersection point on the line segment from the given point.final floatCalculates the perpendicular slope of this line segment.final booleanpointOn(long theDistance, LineSeg.KeyPoint fromKeyPoint, org.eclipse.draw2d.geometry.Point ptResult) Gets the point on the line segment at the given distance away from the key point.final LineSeg.SignpositionRelativeTo(org.eclipse.draw2d.geometry.Point rel) Returns out a positive or negative value (Positive / Negative) depending on the orientation of the given point to the line.final doubleprojection(int xCoord, int yCoord) Calculates the projection of the given point onto the line segment.voidsetOrigin(org.eclipse.draw2d.geometry.Point origin) Sets the origin point of the line segmentvoidsetTerminus(org.eclipse.draw2d.geometry.Point terminus) Sets the terminating point of the line segment.final floatslope()Calculates the slope of this line segment (y=mx+b)Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.draw2d.geometry.Translatable
performTranslate, performTranslate, performTranslate
-
Constructor Details
-
LineSeg
Creates a segment using (fromX, fromY) as either the first point of the segment (start == Origin) or the midpoint of the segment (start == Midpoint), and using slope as its new slope and len as the new length. xdir indicates which direction the segment should go in the x-axis.- Parameters:
start-KeyPointfrom which the other parameters are relative tofromX- int x value of startKeyPointfromY- int y value of startKeyPointslope-floatslope of the linelen-longlength of the linexdir- direction
-
LineSeg
public LineSeg(org.eclipse.draw2d.geometry.Point ptStart, org.eclipse.draw2d.geometry.Point ptEnd) Constructor- Parameters:
ptStart- Point indicating the start of the line segmentptEnd- Point indicating the end of the line segment
-
-
Method Details
-
getLineEquation
public static double[] getLineEquation(double x1, double y1, double x2, double y2) Returns the coefficients of the generalized equation of the line passing through points (x1,y1) and (x2,y2) Generalized line equation: ax+by=c => a==result[0], b==result[1], c==result[2]- Parameters:
x1- - x coordinate of the 1st pointy1- - y coordinate of the 1st pointx2- - x coordinate of the 2nd pointy2- - y coordinate of the 2nd point- Returns:
- the coefficients of the generalized equation of the line passing through points (x1,y1) and (x2,y2)
-
containsPoint
public final boolean containsPoint(org.eclipse.draw2d.geometry.Point aPoint, int tolerance) Checks if this line segment contains the given point within a tolerance value.- Parameters:
aPoint-Pointto test if contained in this line.tolerance- int tolerance value for detecting the intersection.- Returns:
booleantrueif the given point lies on this segment,falseotherwise.
-
distanceAlong
public final float distanceAlong(org.eclipse.draw2d.geometry.Point coord) Finds the percentage distance along this line segement where the given point resides.- Parameters:
coord-Pointto determine how far along the line segment it resides.- Returns:
floatthe distance along the line segment where the ptCoord is in a percentage from.
-
distanceToPoint
public final long distanceToPoint(int xCoord, int yCoord) Finds the perpendicular distance from a point coordinates to this line segment. If point is "inside" line segment, then use distance from point to the line, otherwise use distance to nearest endpoint of segment- Parameters:
xCoord- the x coordinate of the point.yCoord- the y coordinate of the point.- Returns:
longthe distance from the line segment to the given point.
-
equals
-
getEquation
public double[] getEquation()Returns array with 3 numbers in it, which are the coefficients of the generalized line equation of the line corresponding to this line segment a*x+b*y=c is the equation => result[0]=a, result[1]=b, result[2]=c- Returns:
- an array with 3 numbers in it, which are the coefficients of the generalized line equation
-
getInfimum
public final org.eclipse.draw2d.geometry.Point getInfimum()Get aPointrepresenting the lowest point value for this line segment.- Returns:
PointRepresenting the lowest point value.
-
getLineIntersectionsWithEllipse
public org.eclipse.draw2d.geometry.PointList getLineIntersectionsWithEllipse(org.eclipse.draw2d.geometry.Rectangle ellipseBounds) Calculates intersection points of the line of the line segment and ellipse- Parameters:
ellipseBounds- - width and height of the ellipse- Returns:
- -
PointListcontaining all intersection points
-
getLineIntersectionsWithLineSegs
public org.eclipse.draw2d.geometry.PointList getLineIntersectionsWithLineSegs(org.eclipse.draw2d.geometry.PointList points) Calculates intersection points of the line that contains this line segment with a list of other line segments. If the list of points (line segments) form a closedPolyLine, i.e form a closed polygon figure, then the method will claculate intersections of a line and a figure- Parameters:
points- - list of points that form linesegments, i.e thePolyLine- Returns:
- the intersection points of the line that contains this line segment with a list of other line segments.
-
getLinesIntersections
Returns intersection points of two lines that contain this line segment and the argumet line segment. The list of intersection points may contain at most two points and will contain 2 points if and only if the lines are equal. The 2 points will be the end points of the parameter line segment- Parameters:
line- - the line segment- Returns:
- intersection points of two lines that contain this line segment and the argumet line segment.
-
getOrigin
public org.eclipse.draw2d.geometry.Point getOrigin()Accesssor to retrieve the origin point of the line segement.- Returns:
Pointthe origin of the line segment.
-
getParallelLineSegThroughPoint
Returns a newLineSegthat is parallel to this by the given distance. Orientation is relative to the start and end. Negative implies to the left and Position implies to the right.- Parameters:
ptLoc-Pointvalue to constrain the line to.- Returns:
LineSegline that was calculated going through the given point
-
getSupremum
public final org.eclipse.draw2d.geometry.Point getSupremum()Get points representing the highest point value for this line segment.- Returns:
PointRepresenting the highest point value.
-
getTerminus
public org.eclipse.draw2d.geometry.Point getTerminus()Accesssor to retrieve the terminal point of the line segement.- Returns:
Pointthe terminating point of the line segment
-
getTrigValues
Gets the trig values associated with the angle from this line segment to the given vector.- Parameters:
ptToVector-Rayvalue to calculate trig values of.- Returns:
TrigValuesobject representing the trigonometry values for the angle of the passed inRayrelative tothisor null if calculation is not possible,
-
hashCode
public int hashCode() -
intersect
Determines the intersect point between this line and the line passed in as a parameter. If they intersect, then true is returned and the point reference passed in will be set to the intersect point. If they don't intersect, then the method returnsfalse.- Parameters:
line-LineSegto test the intersection against.nTolerance- int tolerance value for detecting the intersection.- Returns:
Pointthat represents the intersection with this line, ornullif the calculation is not possible.
-
isHorizontal
public final boolean isHorizontal()Determines if this a horizontal segment- Returns:
booleantrueif horizontal,falseotherwise.
-
isVertical
public final boolean isVertical()Determines if this a vertical segment- Returns:
booleantrueif vertical,falseotherwise.
-
length
public final double length()Calculate the length of the line segment.- Returns:
- the
doublelength of the line segment.
-
locatePoint
public final org.eclipse.draw2d.geometry.Point locatePoint(double pctDist, long theHeight, LineSeg.Sign asOriented) Locates a point at a given height and distance along the line segment. B (the point we are looking for) + | dist |h this segment P1-----------+-------------------> A get point A (on picture above)- Parameters:
pctDist-doubledistance along the linetheHeight-longheight above the lineasOriented-Signindicating relative position of the point to be located- Returns:
Pointvalue that was located on the line.
-
performScale
public void performScale(double factor) - Specified by:
performScalein interfaceorg.eclipse.draw2d.geometry.Translatable
-
performTranslate
public void performTranslate(int dx, int dy) - Specified by:
performTranslatein interfaceorg.eclipse.draw2d.geometry.Translatable
-
perpIntersect
public final org.eclipse.draw2d.geometry.Point perpIntersect(int startX, int startY) Calculates the perpendicular intersection point on the line segment from the given point.- Parameters:
startX- the x coordinate of the pointstartY- the y coordinate of the point- Returns:
Pointvalue containment the perpendicular intersection point.
-
perpSlope
public final float perpSlope()Calculates the perpendicular slope of this line segment. This calculates the slope and then inverts it. Again, to avoid divide by zero errors, the constantBIGSLOPEis returned if the calculated slope before inverting it was zero.- Returns:
floatthe perpendicular slope value of the line segment.
-
pointOn
public final boolean pointOn(long theDistance, LineSeg.KeyPoint fromKeyPoint, org.eclipse.draw2d.geometry.Point ptResult) Gets the point on the line segment at the given distance away from the key point.- Parameters:
theDistance-longdistance along the linefromKeyPoint-KeyPointto calculate the distance fromptResult-Pointwhere the resulting calculating value is stored.- Returns:
booleantrueif point can be calculated,falseotherwise.
-
positionRelativeTo
Returns out a positive or negative value (Positive / Negative) depending on the orientation of the given point to the line. Point on this side: Positive. P1------------------------------> this segment Point on this side: Negative.- Parameters:
rel-Pointto test the relative position against this line.- Returns:
Signvalue indicating the relative position of the given point.
-
projection
public final double projection(int xCoord, int yCoord) Calculates the projection of the given point onto the line segment.- Parameters:
xCoord- the x coordinate of the point.yCoord- the y coordinate of the point.- Returns:
doublevalue of the calculated projection.
-
setOrigin
public void setOrigin(org.eclipse.draw2d.geometry.Point origin) Sets the origin point of the line segment- Parameters:
origin- Point to set as origin
-
setTerminus
public void setTerminus(org.eclipse.draw2d.geometry.Point terminus) Sets the terminating point of the line segment.- Parameters:
terminus- Point to set as terminus
-
slope
public final float slope()Calculates the slope of this line segment (y=mx+b)- Returns:
floatthe slope of this segment. If the slope is not defined such as when the line segment is vertical, then the constantBIGSLOPEis returned to avoid divide by zero errors.
-