-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced: small functions with long names
- Loading branch information
1 parent
b607358
commit 618b5f7
Showing
6 changed files
with
164 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,85 @@ | ||
use edges::Edges; | ||
|
||
use crate::utils::{ | ||
avian2d::{convex_hull_collider, convex_polyline_collider, heightfield_collider, Collider}, | ||
generate_collider, generate_multi_collider, | ||
use avian2d::{ | ||
parry::{math::Point, shape::SharedShape}, | ||
prelude::Collider, | ||
}; | ||
use edges::Edges; | ||
|
||
/// Generate a single polyline collider from the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn single_polyline_collider_translated<I>(image: I) -> Collider | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, |points| Collider::polyline(points, None), true) | ||
} | ||
|
||
/// Generate a single polyline collider from the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn single_polyline_collider_raw<I>(image: I) -> Collider | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, |points| Collider::polyline(points, None), false) | ||
} | ||
|
||
/// Generate a single `convex_polyline` collider from the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn single_convex_polyline_collider_translated<I>(image: I) -> Option<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, convex_polyline_collider, true) | ||
} | ||
|
||
/// Generate a single `convex_polyline` collider from the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn single_convex_polyline_collider_raw<I>(image: I) -> Option<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, convex_polyline_collider, false) | ||
} | ||
|
||
/// Generate a single `convex_hull` collider from the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn single_convex_hull_collider_translated<I>(image: I) -> Option<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, convex_hull_collider, true) | ||
} | ||
|
||
/// Generate a single `convex_hull` collider from the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn single_convex_hull_collider_raw<I>(image: I) -> Option<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, convex_hull_collider, false) | ||
} | ||
|
||
/// Generate a single heightfield collider from the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn single_heightfield_collider_translated<I>(image: I) -> Collider | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, heightfield_collider, true) | ||
} | ||
|
||
/// Generate a single heightfield collider from the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn single_heightfield_collider_raw<I>(image: I) -> Collider | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_collider(image, heightfield_collider, false) | ||
} | ||
|
||
/// Generate as many polyline colliders as it can find in the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn multi_polyline_collider_translated<I>(image: I) -> Vec<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, |points| Collider::polyline(points, None), true) | ||
} | ||
|
||
/// Generate as many polyline colliders as it can find in the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn multi_polyline_collider_raw<I>(image: I) -> Vec<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, |points| Collider::polyline(points, None), false) | ||
} | ||
|
||
/// Generate as many `convex_polyline` colliders as it can find in the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn multi_convex_polyline_collider_translated<I>(image: I) -> Vec<Option<Collider>> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, convex_polyline_collider, true) | ||
} | ||
|
||
/// Generate as many `convex_polyline` colliders as it can find in the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn multi_convex_polyline_collider_raw<I>(image: I) -> Vec<Option<Collider>> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, convex_polyline_collider, false) | ||
} | ||
|
||
/// Generate as many heightfield colliders as it can find in the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn multi_heightfield_collider_translated<I>(image: I) -> Vec<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, heightfield_collider, true) | ||
} | ||
|
||
/// Generate as many heightfield colliders as it can find in the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn multi_heightfield_collider_raw<I>(image: I) -> Vec<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, heightfield_collider, false) | ||
} | ||
#[cfg(feature = "parallel")] | ||
use rayon::prelude::*; | ||
|
||
/// Generate as many `convex_hull` colliders as it can find in the image, | ||
/// coordinates translated to either side of (0, 0) | ||
#[must_use] | ||
pub fn multi_convex_hull_collider_translated<I>(image: I) -> Vec<Option<Collider>> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, convex_hull_collider, true) | ||
} | ||
use crate::{ | ||
utils::{generate_collider, generate_multi_collider, heights_and_scale}, | ||
ColliderType, | ||
}; | ||
|
||
/// Generate as many `convex_hull` colliders as it can find in the image, | ||
/// coordinates left alone and all in positive x and y | ||
#[must_use] | ||
pub fn multi_convex_hull_collider_raw<I>(image: I) -> Vec<Option<Collider>> | ||
where | ||
Edges: From<I>, | ||
{ | ||
generate_multi_collider(image, convex_hull_collider, false) | ||
/// Generate a single collider from the image. | ||
#[must_use] | ||
pub fn single_collider<I>( | ||
image: I, | ||
collider_type: ColliderType, | ||
translated: bool, | ||
) -> Option<Collider> | ||
where | ||
Edges: From<I>, | ||
{ | ||
let collider_fn = match collider_type { | ||
ColliderType::Polyline => |vertices| Some(Collider::polyline(vertices, None)), | ||
ColliderType::ConvexPolyline => |points: Vec<_>| { | ||
SharedShape::convex_polyline( | ||
{ | ||
#[cfg(not(feature = "parallel"))] | ||
let iterator = points.into_iter(); | ||
|
||
#[cfg(feature = "parallel")] | ||
let iterator = points.into_par_iter(); | ||
iterator | ||
} | ||
.map(Point::from) | ||
.collect(), | ||
) | ||
.map(Collider::from) | ||
}, | ||
ColliderType::ConvexHull => |points| Collider::convex_hull(points), | ||
ColliderType::Heightfield => |points| { | ||
let (heights, scale) = heights_and_scale(points); | ||
Some(Collider::heightfield(heights, scale)) | ||
}, | ||
}; | ||
generate_collider(image, collider_fn, translated) | ||
} | ||
|
||
/// Generate as many colliders as it can find in the image. | ||
#[must_use] | ||
pub fn multi_collider<I>( | ||
image: I, | ||
collider_type: ColliderType, | ||
translated: bool, | ||
) -> Vec<Option<Collider>> | ||
where | ||
Edges: From<I>, | ||
{ | ||
let collider_fn = match collider_type { | ||
ColliderType::Polyline => |vertices| Some(Collider::polyline(vertices, None)), | ||
ColliderType::ConvexPolyline => |points: Vec<_>| { | ||
SharedShape::convex_polyline( | ||
{ | ||
#[cfg(not(feature = "parallel"))] | ||
let iterator = points.into_iter(); | ||
|
||
#[cfg(feature = "parallel")] | ||
let iterator = points.into_par_iter(); | ||
iterator | ||
} | ||
.map(Point::from) | ||
.collect(), | ||
) | ||
.map(Collider::from) | ||
}, | ||
ColliderType::ConvexHull => |points| Collider::convex_hull(points), | ||
ColliderType::Heightfield => |points| { | ||
let (heights, scale) = heights_and_scale(points); | ||
Some(Collider::heightfield(heights, scale)) | ||
}, | ||
}; | ||
generate_multi_collider(image, collider_fn, translated) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
#![doc = include_str!("../README.md")] | ||
|
||
pub use edges::Edges; | ||
pub extern crate edges; | ||
|
||
#[cfg(feature = "avian2d")] | ||
pub mod avian2d; | ||
#[cfg(feature = "rapier2d")] | ||
pub mod rapier2d; | ||
mod utils; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub enum ColliderType { | ||
Polyline, | ||
ConvexPolyline, | ||
ConvexHull, | ||
Heightfield, | ||
} |
Oops, something went wrong.