c2 0.2.0

2D Collision Detection
Documentation
  • Coverage
  • 54.55%
    42 out of 77 items documented1 out of 70 items with examples
  • Size
  • Source code size: 19.73 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • yeahross0/cute-c2
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yeahross0

Getting started

use c2::{prelude::*, AABB, Circle, Capsule, Poly, Transformation, Rotation};
use std::f32::consts::PI;

fn main() {
    let circle = Circle::new([0.0, 0.0], 15.0);
    let aabb = AABB::new([10.0, 5.0], [20.0, 30.0]);

    let collided = circle.collides_with(&aabb);
    assert!(collided);

    let capsule = Capsule::new([5.0, 5.0], [15.0, 10.0], 1.0);

    let poly = Poly::from_slice(&[
        [-1.0, -3.0],
        [1.0, -3.0],
        [1.0, 0.0],
        [0.0, 1.0],
        [-1.0, 0.0],
    ]);

    let collided = capsule.collides_with(&poly);
    assert!(!collided);

    let transformation =
        Transformation::new([5.0, 4.0], Rotation::radians(PI / 2.0));

    let collided = circle.collides_with(&(poly, transformation));
    assert!(collided);
    let manifold = circle.manifold(&poly);
    /*
        The manifold is used for resolving collisions and has the following methods:
        manifold.count() -> i32
        manifold.depths() -> [f32; 2]
        manifold.contact_points() -> [Vec2; 2]
        manifold.normal() -> Vec2
    */

    let gjk_response = poly.gjk(&circle).run();
    /*
        The result of the GJK algorithm:
        gjk_response.distance() -> f32
        gjk_response.closest_points() -> (Vec2, Vec2)
    */
}

Check out the library this builds on top of for additional documentation. Please note the section entitled NUMERIC ROBUSTNESS.