Class Geometry


  • public class Geometry
    extends Object
    • Constructor Detail

      • Geometry

        public Geometry()
    • Method Detail

      • lineIntersectionPoint

        public static Point2D.Float lineIntersectionPoint​(float x1,
                                                          float y1,
                                                          float x2,
                                                          float y2,
                                                          float x3,
                                                          float y3,
                                                          float x4,
                                                          float y4)
        Find the point where two lines intersect.
        Parameters:
        x1 - X coordinate of the first endpoint of the first line.
        y1 - Y coordinate of the first endpoint of the first line.
        x2 - X coordinate of the second endpoint of the first line.
        y2 - Y coordinate of the second endpoint of the first line.
        x3 - X coordinate of the first endpoint of the second line.
        y3 - Y coordinate of the first endpoint of the second line.
        x4 - X coordinate of the second endpoint of the second line.
        y4 - Y coordinate of the second endpoint of the second line.
        Returns:
        The intersection point of the lines, or null if the lines don't intersect.
      • intersectionPoints

        public static List<Point2D.Float> intersectionPoints​(Shape shape,
                                                             float x1,
                                                             float y1,
                                                             float x2,
                                                             float y2)
        Find the intersection points between a Shape and a line.
        Parameters:
        shape - The shape.
        x1 - X coordinate of the first endpoint of the line.
        y1 - Y coordinate of the first endpoint of the line.
        x2 - X coordinate of the second endpoint of the line.
        y2 - Y coordinate of the second endpoint of the line.
        Returns:
        A list with the intersection points.
      • transformPath

        public static GeneralPath transformPath​(PathIterator it,
                                                Consumer<float[]> method)
        Transforms the points in a path according to a method.
        Parameters:
        it - The iterator of the path to change the points on.
        method - The method to use to transform the points. Takes a float[2] array with x and y coordinates as parameter.
        Returns:
        The transformed path.
      • transformPath

        public static GeneralPath transformPath​(GeneralPath path,
                                                Consumer<float[]> method)
        Transforms the points in a path according to a method.
        Parameters:
        path - The path to change the points on.
        method - The method to use to transform the points. Takes a float[2] array with x and y coordinates as parameter.
        Returns:
        The transformed path.
      • splitIntoSegments

        public static GeneralPath splitIntoSegments​(PathIterator it,
                                                    float segmentLength)
        Splits a path into smaller segments. For example, calling this on a path with a line of length 6, with desired segment length of 2, would split the path into 3 consecutive lines of length 2.
        Parameters:
        it - The iterator of the path to modify.
        segmentLength - The desired length to use for the segments.
        Returns:
        The modified path.
      • splitIntoSegments

        public static GeneralPath splitIntoSegments​(GeneralPath path,
                                                    float segmentLength)
        Splits a path into smaller segments. For example, calling this on a path with a line of length 6, with desired segment length of 2, would split the path into 3 consecutive lines of length 2.
        Parameters:
        path - The path to modify.
        segmentLength - The desired length to use for the segments.
        Returns:
        The modified path.
      • filterPath

        public static GeneralPath filterPath​(PathIterator it,
                                             BiPredicate<float[],​float[]> method)
        Removes lines from a path according to a method.
        Parameters:
        it - The iterator of the path to filter.
        method - The method to use to decide which lines to remove. Takes two float[2] arrays with x and y coordinates of the endpoints of the line. Lines for which the predicate returns false are removed.
        Returns:
        The filtered path.
      • filterPath

        public static GeneralPath filterPath​(GeneralPath path,
                                             BiPredicate<float[],​float[]> method)
        Removes lines from a path according to a method.
        Parameters:
        path - The path to filter.
        method - The method to use to decide which lines to remove. Takes two float[2] arrays with x and y coordinates of the endpoints of the line. Lines for which the predicate returns false are removed.
        Returns:
        The filtered path.
      • clipPath

        public static GeneralPath clipPath​(PathIterator it,
                                           Shape shape)
        Removes lines from a path that lie outside the clipping area and cuts lines intersecting with the clipping area so the resulting lines lie within the clipping area.
        Parameters:
        it - The iterator of the path to clip.
        shape - The clipping area to clip with.
        Returns:
        The clipped path.
      • clipPath

        public static GeneralPath clipPath​(GeneralPath path,
                                           Shape shape)
        Removes lines from a path that lie outside the clipping area and cuts lines intersecting with the clipping area so the resulting lines lie within the clipping area.
        Parameters:
        path - The path to clip.
        shape - The clipping area to clip with.
        Returns:
        The clipped path.