Skip to content

Commit

Permalink
removed bevy_render dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
salam99823 committed Nov 12, 2024
1 parent 594e767 commit 42c750e
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 39 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ edges = "0.4.0"
bevy_rapier2d = { version = "0.27.0", optional = true }
avian2d = { version = "0.1.0", optional = true }
bevy_math = { version = "0.14", default-features = false }
bevy_render = { version = "0.14", default-features = false }
rayon = { version = "1.10.0", optional = true }
thiserror = "2.0.3"

Expand Down
83 changes: 66 additions & 17 deletions src/avian2d.rs
Original file line number Diff line number Diff line change
@@ -1,117 +1,166 @@
use edges::Edges;

use crate::utils::{
avian2d::{convex_hull_collider, convex_polyline_collider, heightfield_collider, Collider},
generate_collider, generate_multi_collider,
};
use bevy_render::prelude::Image;

/// Generate a single polyline collider from the image,
/// coordinates translated to either side of (0, 0)
#[must_use]
pub fn single_polyline_collider_translated(image: &Image) -> Collider {
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(image: &Image) -> Collider {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Collider {
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(image: &Image) -> Collider {
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(image: &Image) -> Vec<Collider> {
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(image: &Image) -> Vec<Collider> {
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(image: &Image) -> Vec<Option<Collider>> {
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(image: &Image) -> Vec<Option<Collider>> {
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(image: &Image) -> Vec<Collider> {
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(image: &Image) -> Vec<Collider> {
pub fn multi_heightfield_collider_raw<I>(image: I) -> Vec<Collider>
where
Edges: From<I>,
{
generate_multi_collider(image, heightfield_collider, false)
}

/// 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(image: &Image) -> Vec<Option<Collider>> {
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)
}

/// 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(image: &Image) -> Vec<Option<Collider>> {
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)
}
83 changes: 66 additions & 17 deletions src/rapier2d.rs
Original file line number Diff line number Diff line change
@@ -1,117 +1,166 @@
use edges::Edges;

use crate::utils::{
generate_collider, generate_multi_collider,
rapier2d::{convex_hull_collider, convex_polyline_collider, heightfield_collider, Collider},
};
use bevy_render::prelude::Image;

/// Generate a single polyline collider from the image,
/// coordinates translated to either side of (0, 0)
#[must_use]
pub fn single_polyline_collider_translated(image: &Image) -> Collider {
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(image: &Image) -> Collider {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Option<Collider> {
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(image: &Image) -> Collider {
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(image: &Image) -> Collider {
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(image: &Image) -> Vec<Collider> {
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(image: &Image) -> Vec<Collider> {
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(image: &Image) -> Vec<Option<Collider>> {
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(image: &Image) -> Vec<Option<Collider>> {
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(image: &Image) -> Vec<Collider> {
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(image: &Image) -> Vec<Collider> {
pub fn multi_heightfield_collider_raw<I>(image: I) -> Vec<Collider>
where
Edges: From<I>,
{
generate_multi_collider(image, heightfield_collider, false)
}

/// 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(image: &Image) -> Vec<Option<Collider>> {
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)
}

/// 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(image: &Image) -> Vec<Option<Collider>> {
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)
}
Loading

0 comments on commit 42c750e

Please sign in to comment.