Crates.io | lgeo |
lib.rs | lgeo |
version | 1.0.7 |
source | src |
created_at | 2022-04-06 14:40:44.754083 |
updated_at | 2022-04-11 18:23:23.189879 |
description | 2D Geometry library, focusing on collision computation |
homepage | https://github.com/Carbone13/lgeo |
repository | https://github.com/Carbone13/lgeo |
max_upload_size | |
id | 563172 |
size | 20,750 |
2D Geometry library, written in Rust and based on lmaths.
Provides classic 2D shapes, such as :
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