File-By-File
Shape

Shape

A shape is... well, a shape. This interface defines the common contract for various geometric shapes within the Pathfinder library. It provides methods for determining point containment, collision detection, and geometric transformations like rotation, shifting, and scaling.

The Shape interface uses a ray casting algorithm to determine if a point is inside of a polygon. Click here to learn more. (opens in a new tab)

Type Parameter

  • <T>: Represents the type of the shape itself, allowing methods like rotate, shift, moveTo, scale, and growBy to return an instance of the specific shape type (e.g., Rectangle, Circle).

Static Methods

getIntersections(Line line, List<Line> allLines)

Returns a List of Line segments from allLines that intersect with the given line.

getIntersectionsCount(Line line, List<Line> allLines)

Returns the count of Line segments from allLines that intersect with the given line.

doesIntersectOdd(Line line, List<Line> allLines)

Checks if the given line intersects an odd number of Line segments in allLines. This is part of the ray casting algorithm for point-in-polygon tests.

doesIntersectEven(Line line, List<Line> allLines)

Checks if the given line intersects an even number of Line segments in allLines. This is part of the ray casting algorithm for point-in-polygon tests.

getIntersections(Line line, Line... allLines)

Varargs version of getIntersections(Line line, List<Line> allLines).

getIntersectionsCount(Line line, Line... allLines)

Varargs version of getIntersectionsCount(Line line, List<Line> allLines).

doesIntersectOdd(Line line, Line... allLines)

Varargs version of doesIntersectOdd(Line line, List<Line> allLines).

doesIntersectEven(Line line, Line... allLines)

Varargs version of doesIntersectEven(Line line, List<Line> allLines).

Instance Methods

getClosestPoint(PointXY reference)

Returns the PointXY within the shape that is closest to the given reference point.

isPointInShape(PointXY reference)

Determines if the given reference point lies inside or on the boundary of the shape.

doesCollideWith(Shape<?> shape)

Checks if this shape collides with another Shape.

getCenter()

Returns the PointXY representing the geometric center of the shape.

rotate(Angle rotation)

Rotates the shape by the specified rotation angle around its own center. Returns a new instance of the shape type T.

rotate(Angle rotation, PointXY centerOfRotation)

Rotates the shape by the specified rotation angle around a given centerOfRotation. Returns a new instance of the shape type T.

shift(double shiftX, double shiftY)

Translates (shifts) the shape by shiftX along the X-axis and shiftY along the Y-axis. Returns a new instance of the shape type T.

moveTo(PointXY newCenter)

Moves the shape so that its center is at the newCenter PointXY. Returns a new instance of the shape type T.

scale(double scale)

Resizes the shape by a scale factor. For example, a scale of 2.0 doubles the size, while 0.5 halves it. Returns a new instance of the shape type T.

growBy(double growth)

Resizes the shape by adding a growth value to its dimensions. This effectively expands or contracts the shape from its center. Returns a new instance of the shape type T.