Expand description
A struct representing a capsule, i.e. a rotated rectangle capped by half circles. The position is located in the center of the rectangle, with the arm vector denoting half of the capsule’s length. Radius represents half of the capsule’s width, which corresponds to the radius of the half circles.
Examples
use sepax2d::prelude::*;
let capsule = Capsule::new((0.0, 0.0), (0.0, 1.0), 2.0);
//A capsule formed from a rectangle with vertices (-1, 1), (1,1), (-1,-1), and (1,-1)
let hexagon = Polygon::from_vertices((1.5, 0.0), vec![(0.0, 0.0), (0.0, 1.0), (1.0, 2.0), (2.0, 1.0), (2.0, 0.0)]);
let square = AABB::new((2.0, 3.0), 4.0, 0.5);
assert!(sat_overlap(&capsule, &hexagon));
assert!(!sat_overlap(&square, &capsule));
Fields
position: (f32, f32)
radius: f32
Implementations
sourceimpl Capsule
impl Capsule
sourcepub fn new(position: (f32, f32), arm: (f32, f32), radius: f32) -> Capsule
pub fn new(position: (f32, f32), arm: (f32, f32), radius: f32) -> Capsule
Create a new capsule with the given center position, arm, and radius.
sourcepub fn set_radius(&mut self, radius: f32)
pub fn set_radius(&mut self, radius: f32)
Used to change the radius of the capsule.
Trait Implementations
sourceimpl Rotate for Capsule
impl Rotate for Capsule
sourcefn rotate(&mut self, angle: f32)
fn rotate(&mut self, angle: f32)
Rotate the shape by the given angle, with the rotation counterclockwise when the Y-axis points up. Read more
sourcefn rotate_sincos(&mut self, sin: f32, cos: f32)
fn rotate_sincos(&mut self, sin: f32, cos: f32)
Rotate the shape using the given sine and cosine of an angle. Use this when you are rotating multiple shapes by the same angle and don’t want to re-calculate the trig functions. Read more
sourceimpl Shape for Capsule
impl Shape for Capsule
sourcefn set_position(&mut self, position: (f32, f32))
fn set_position(&mut self, position: (f32, f32))
Set the location of the shape.
sourcefn num_axes(&self) -> usize
fn num_axes(&self) -> usize
The number of axes the shape provides for testing. For polygons, it is the same as the number of vertices, but for circles it is simply one. Read more
sourcefn get_axis(&self, index: usize, target: (f32, f32)) -> (f32, f32)
fn get_axis(&self, index: usize, target: (f32, f32)) -> (f32, f32)
The method used to access the axes during the SAT calculations. This is used to avoid the memory allocation of a new vector or array each time we calculate collisions. Read more
sourcefn project(&self, axis: (f32, f32), normalize: bool) -> (f32, f32)
fn project(&self, axis: (f32, f32), normalize: bool) -> (f32, f32)
Getting the minimum and maximum projection of the shape onto the given axis to look for overlap. Normalize denotes whether or not the axis passed in is a unit vector to avoid repeating calculations. Read more
sourcefn needs_closest(&self, index: usize) -> bool
fn needs_closest(&self, index: usize) -> bool
Determine whether or not the shape needs access to the closest vertex of another shape to check collisions. Read more
impl Copy for Capsule
Auto Trait Implementations
impl RefUnwindSafe for Capsule
impl Send for Capsule
impl Sync for Capsule
impl Unpin for Capsule
impl UnwindSafe for Capsule
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more