lgeo

Crates.iolgeo
lib.rslgeo
version1.0.7
sourcesrc
created_at2022-04-06 14:40:44.754083
updated_at2022-04-11 18:23:23.189879
description2D Geometry library, focusing on collision computation
homepagehttps://github.com/Carbone13/lgeo
repositoryhttps://github.com/Carbone13/lgeo
max_upload_size
id563172
size20,750
Lucas Michaudel (Carbone13)

documentation

README

L-Geo

Documentation Version License

2D Geometry library, written in Rust and based on lmaths.

Provides classic 2D shapes, such as :

  • Circles
  • Rectangles
  • Convex Polygons

It implements the GJK algorithm to compute collision and EPA (yet to be developped) to extrude collision informations.

Examples :

First, always create a GJK struct, which hold your settings, like the contact tolerance :

let gjk = GJK::new();

Then you can start spawning shapes :

let c = Circle::new(Vector2::new(4.6, -3.2), 1.43);
let r = AABB::new(Vector2::new(-1.0, 0.5), Vector2::new(2.0, 1.0));
let p = Polygon::new(Vector2::new(0.0, 0.0),
                    vec![Vector2::new(0.0, 0.5),
                         Vector2::new(-1.5, -0.5),
                         Vector2::new(-3.0, 0.5),
                    ]);

Finally, you can check for collisions between them. Converting the result to a boolean is done by calling result.is_some(), as the intersect() function return the final Simplex of GJK.

let c_vs_r = gjk.intersect(&c, &r).is_some(); // False
let c_vs_p = gjk.intersect(&c, &p).is_some(); // False
let r_vs_p = gjk.intersect(&r, &p).is_some(); // True
Commit count: 21

cargo fmt