Class Shape
java.lang.Object
org.openpatch.scratch.Shape
A shape on the stage: a polygon, rectangle, circle, ellipse or triangle. Shapes serve as
hitboxes (
sprite.setHitbox(...)) and can be tested against each other. Circles and
ellipses are stored as polygons that stay within a quarter pixel of the true outline.
Shapes that only touch, along an edge or at a corner, do not intersect.
-
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(double x, double y) double[]booleanintersects(Shape other) rotate(double degrees, double anchorX, double anchorY) Turns the shape about a point, from the x axis towards the y axis (anticlockwise when y points up).scale(double scaleX, double scaleY) translate(double dx, double dy)
-
Method Details
-
getPoints
public double[] getPoints()- Returns:
- the outline's points
x0, y0, x1, y1, …(a copy)
-
contains
public boolean contains(double x, double y) - Parameters:
x- x of a pointy- y of a point- Returns:
- whether the point lies inside the shape
-
intersects
- Parameters:
other- another shape- Returns:
- whether the two shapes overlap with some area; shapes that only touch do not
-
scale
- Parameters:
scaleX- factor along x (negative mirrors)scaleY- factor along y- Returns:
- the shape scaled about the origin
-
translate
- Parameters:
dx- distance along xdy- distance along y- Returns:
- the shape moved
-
rotate
Turns the shape about a point, from the x axis towards the y axis (anticlockwise when y points up).- Parameters:
degrees- the angleanchorX- x of the point to turn aboutanchorY- y of the point to turn about- Returns:
- the shape turned
-
getBounds
- Returns:
- the smallest rectangle around the shape
-