meowitzher / sepax2d

A safe Rust crate for finding and resolving collisions of convex polygons using the Separating Axis Theorem in two dimensions.
Other
13 stars 2 forks source link

Non-axis-aligned Rectangle Shape #1

Closed inodentry closed 2 years ago

inodentry commented 2 years ago

It would be nice and convenient to have a rectangle shape that can be rotated. Could be easier to use and more efficient than trying to use Polygon for this use case.

meowitzher commented 2 years ago

Done! To be included in the next release.

Implemented the Parallelogram shape, which supports arbitrary parallelograms (including rotated rectangles).

Rectangular parallelograms can be constructed using the Parallelogram::rectangle helper method.

Also implemented the Rotate trait, which enables Polygons, Circles, Capsules, and Parallelograms to be rotated via the rotate method. If doing multiple rotations by the same angle, you can use the rotate_sincos method to avoid re-computing the sine and cosine multiple times.