Class ShapeUtilities

java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.referencing.j2d.ShapeUtilities

public final class ShapeUtilities extends Static
Static methods operating on shapes from the java.awt.geom package.
Since:
0.5
Version:
1.2
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
    Threshold value for determining whether two points are the same, or whether two lines are colinear.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Do not allow instantiation of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
    Returns the center of a circle passing by the 3 given points.
    colinearPoint(double x1, double y1, double x2, double y2, double x, double y, double distance)
    Returns a point on the given line segment located at the given distance from that line.
    fitParabol(double x1, double y1, double px, double py, double x2, double y2, boolean horizontal)
    Returns a quadratic curve passing by the 3 given points.
    intersectionPoint(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2)
    Returns the intersection point between two line segments.
    nearestColinearPoint(double x1, double y1, double x2, double y2, double x, double y)
    Returns the point on the given line segment which is closest to the given point.
    parabolicControlPoint(double x1, double y1, double px, double py, double x2, double y2, boolean horizontal)
    Returns the control point of a quadratic curve passing by the 3 given points.
    static Shape
    Attempts to replace an arbitrary shape by one of the standard Java2D constructs.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EPS

      private static final double EPS
      Threshold value for determining whether two points are the same, or whether two lines are colinear.
      See Also:
  • Constructor Details

    • ShapeUtilities

      private ShapeUtilities()
      Do not allow instantiation of this class.
  • Method Details

    • intersectionPoint

      public static Point2D.Double intersectionPoint(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2)
      Returns the intersection point between two line segments. The lines do not continue to infinity; if the intersection does not occur between the ending points P1 and P2 of the two line segments, then this method returns null.
      Parameters:
      ax1 - x value of the first point on the first line.
      ay1 - y value of the first point on the first line.
      ax2 - x value of the last point on the first line.
      ay2 - y value of the last point on the first line.
      bx1 - x value of the first point on the second line.
      by1 - y value of the first point on the second line.
      bx2 - x value of the last point on the second line.
      by2 - y value of the last point on the second line.
      Returns:
      the intersection point, or null if none.
      See Also:
    • nearestColinearPoint

      public static Point2D.Double nearestColinearPoint(double x1, double y1, double x2, double y2, double x, double y)
      Returns the point on the given line segment which is closest to the given point. Let result be the returned point. This method guarantees (except for rounding errors) that:
      • result is a point on the line segment. It is located between the P1 and P2 ending points of that line segment.
      • The distance between the result point and the given point is the shortest distance among the set of points meeting the previous condition. This distance can be obtained with point.distance(result).
      Parameters:
      x1 - x value of the first point on the line.
      y1 - y value of the first point on the line.
      x2 - x value of the last point on the line.
      y2 - y value of the last point on the line.
      x - x value of a point close to the given line.
      y - y value of a point close to the given line.
      Returns:
      the nearest point on the given line.
      See Also:
    • colinearPoint

      public static Point2D.Double colinearPoint(double x1, double y1, double x2, double y2, double x, double y, double distance)
      Returns a point on the given line segment located at the given distance from that line. Let result be the returned point. If result is not null, then this method guarantees (except for rounding error) that:
      • result is a point on the line segment. It is located between the P1 and P2 ending points of that line segment.
      • The distance between the result and the given point is exactly equal to distance.
      If no result point meets those conditions, then this method returns null. If two result points met those conditions, then this method returns the point which is the closest to line.getP1().
      Parameters:
      x1 - x value of the first point on the line.
      y1 - y value of the first point on the line.
      x2 - x value of the last point on the line.
      y2 - y value of the last point on the line.
      x - x value of a point close to the given line.
      y - y value of a point close to the given line.
      distance - the distance between the given point and the point to be returned.
      Returns:
      a point on the given line located at the given distance from the given point.
      See Also:
    • fitParabol

      public static QuadCurve2D.Double fitParabol(double x1, double y1, double px, double py, double x2, double y2, boolean horizontal)
      Returns a quadratic curve passing by the 3 given points. There is an infinity of quadratic curves passing by 3 points. We can express the curve we are looking for as a parabolic equation of the form y=ax²+bx+c but where the x axis is not necessarily horizontal. The orientation of the x axis in the above equation is determined by the horizontal parameter:
      • A value of true means that the x axis must be horizontal. The quadratic curve will then looks like an ordinary parabolic curve as we see in mathematic school book.
      • A value of false means that the x axis must be parallel to the line segment joining the P0 and P2 ending points.
      Note that if P0.y == P2.y, then both horizontal values produce the same result.
      Parameters:
      x1 - x value of the starting point.
      y1 - y value of the starting point.
      px - x value of a passing point.
      py - y value of a passing point.
      x2 - x value of the ending point.
      y2 - y value of the ending point.
      horizontal - if true, the x axis is considered horizontal while computing the y=ax²+bx+c equation terms. If false, it is considered parallel to the line joining the P0 and P2 points.
      Returns:
      a quadratic curve passing by the given points. The curve starts at P0 and ends at P2. If two points are too close or if the three points are colinear, then this method returns null.
    • parabolicControlPoint

      public static Point2D.Double parabolicControlPoint(double x1, double y1, double px, double py, double x2, double y2, boolean horizontal)
      Returns the control point of a quadratic curve passing by the 3 given points. There is an infinity of quadratic curves passing by 3 points. We can express the curve we are looking for as a parabolic equation of the form y = ax²+bx+c, but the x axis is not necessarily horizontal. The x axis orientation in the above equation is determined by the horizontal parameter:
      • A value of true means that the x axis must be horizontal. The quadratic curve will then look like an ordinary parabolic curve as we see in mathematic school book.
      • A value of false means that the x axis must be parallel to the line segment joining the P0 and P2 ending points.
      Note that if P0.y == P2.y, then both horizontal values produce the same result.
      Parameters:
      x1 - x value of the starting point.
      y1 - y value of the starting point.
      px - x value of a passing point.
      py - y value of a passing point.
      x2 - x value of the ending point.
      y2 - y value of the ending point.
      horizontal - if true, the x axis is considered horizontal while computing the y = ax²+bx+c equation terms. If false, it is considered parallel to the line joining the P0 and P2 points.
      Returns:
      the control point of a quadratic curve passing by the given points. The curve starts at (x0,y0) and ends at (x2,y2). If two points are too close or if the three points are colinear, then this method returns null.
    • circleCentre

      public static Point2D.Double circleCentre(double x1, double y1, double x2, double y2, double x3, double y3)
      Returns the center of a circle passing by the 3 given points. The distance between the returned point and any of the given points will be constant; it is the circle radius.
      Parameters:
      x1 - x value of the first point.
      y1 - y value of the first point.
      x2 - x value of the second point.
      y2 - y value of the second point.
      x3 - x value of the third point.
      y3 - y value of the third point.
      Returns:
      the center of a circle passing by the given points.
      See Also:
    • toPrimitive

      public static Shape toPrimitive(Shape path)
      Attempts to replace an arbitrary shape by one of the standard Java2D constructs. For example if the given path is a Path2D containing only a single line or a quadratic curve, then this method replaces it by a Line2D or QuadCurve2D object respectively.
      Parameters:
      path - the shape to replace by a simpler Java2D construct. This is generally an instance of Path2D, but not necessarily.
      Returns:
      a simpler Java construct, or path if no better construct is proposed.