Skip to content

eliminated dependencies: arr_macro, num-integer, cfg-if, indexmap #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions jagua-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ homepage = "https://github.com/JeroenGar/jagua-rs"
ndarray = "0.16"
rand = { version = "0.9.0", features = [ "small_rng" ] }
rand_distr = "0.5"
num-integer = "0.1"
ordered-float = "5.0"
indexmap = "2.7"
serde = { version = "1.0", features = ["derive"] }
log = "0.4"
itertools = "0.14"
tribool = "0.3"
arr_macro = "0.2"
cfg-if = "1.0.0"
rayon = "1.9"
slotmap = "1.0"
float-cmp = "0.10"
Expand Down
16 changes: 8 additions & 8 deletions jagua-rs/src/collision_detection/cd_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::geometry::primitives::simple_polygon::SimplePolygon;
use crate::geometry::transformation::Transformation;
use crate::util::assertions;
use crate::util::config::CDEConfig;
use indexmap::IndexSet;
use itertools::Itertools;
use tribool::Tribool;

/// The Collision Detection Engine (CDE).
Expand Down Expand Up @@ -151,17 +151,17 @@ impl CDEngine {
/// Restores the CDE to a previous state, as described by the snapshot.
pub fn restore(&mut self, snapshot: &CDESnapshot) {
//Quadtree
let mut hazards_to_remove = self
.dynamic_hazards
.iter()
.map(|h| h.entity)
.collect::<IndexSet<HazardEntity>>();
let mut hazards_to_remove = self.dynamic_hazards.iter().map(|h| h.entity).collect_vec();
debug_assert!(hazards_to_remove.len() == self.dynamic_hazards.len());
let mut hazards_to_add = vec![];

for hazard in snapshot.dynamic_hazards.iter() {
let hazard_already_present = hazards_to_remove.swap_remove(&hazard.entity);
if !hazard_already_present {
let hazard_already_present = hazards_to_remove.iter().position(|h| h == &hazard.entity);
if let Some(idx) = hazard_already_present {
//the hazard is already present in the CDE, remove it from the hazards to remove
hazards_to_remove.swap_remove(idx);
} else {
//the hazard is not present in the CDE, add it to the list of hazards to add
hazards_to_add.push(hazard.clone());
}
}
Expand Down
9 changes: 4 additions & 5 deletions jagua-rs/src/collision_detection/quadtree/qt_hazard.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::array;
use std::borrow::Borrow;
use std::sync::Arc;

use arr_macro::arr;

use crate::collision_detection::hazard::Hazard;
use crate::collision_detection::hazard::HazardEntity;
use crate::collision_detection::quadtree::qt_partial_hazard::{PartialQTHaz, RelevantEdges};
Expand Down Expand Up @@ -49,8 +48,8 @@ impl QTHazard {
debug_assert!(assertions::quadrants_have_valid_layout(&quadrants));

match &self.presence {
QTHazPresence::None => arr![None;4],
QTHazPresence::Entire => arr![Some(self.clone());4],
QTHazPresence::None => array::from_fn(|_| None),
QTHazPresence::Entire => array::from_fn(|_| Some(self.clone())),
QTHazPresence::Partial(partial_haz) => {
//If the hazard is partially present, it may produce different hazards for each quadrant

Expand All @@ -59,7 +58,7 @@ impl QTHazard {
let haz_q_rels = quadrants.map(|q| haz_bbox.relation_to(q));

//find the presence of the hazard in each quadrant, initially set to None (not yet determined)
let mut q_presences = arr![None;4];
let mut q_presences = array::from_fn(|_| None);

//Check if one of the quadrants entirely contains the hazard
let enclosed_haz_quad_index =
Expand Down
4 changes: 1 addition & 3 deletions jagua-rs/src/geometry/primitives/simple_polygon.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Borrow;

use itertools::Itertools;
use num_integer::Integer;
use ordered_float::{NotNan, OrderedFloat};

use crate::fsize;
Expand Down Expand Up @@ -307,8 +306,7 @@ impl CollidesWith<Point> for SimplePolygon {
n_intersections += 1;
}
}

n_intersections.is_odd()
n_intersections % 2 == 1
}
}
}
Expand Down
35 changes: 18 additions & 17 deletions jagua-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ pub mod io;
/// Helper functions
pub mod util;

cfg_if::cfg_if! {
if #[cfg(feature = "double-precision")] {
/// The floating point type used in jagua-rs.
/// ```f32``` by default, ```f64``` when feature **double-precision** is enabled.
#[allow(non_camel_case_types)]
pub type fsize = f64;
/// π as [fsize].
pub const PI : fsize = std::f64::consts::PI;
} else {
/// The floating point type used in jagua-rs.
/// ```f32``` by default, ```f64``` when feature **double-precision** is enabled.
#[allow(non_camel_case_types)]
pub type fsize = f32;
/// π as [fsize].
pub const PI: fsize = std::f32::consts::PI;
}
}
#[allow(non_camel_case_types)]
#[cfg(feature = "double-precision")]
/// The floating point type used in jagua-rs.
/// ```f32``` by default, ```f64``` when feature **double-precision** is enabled.
pub type fsize = f64;
#[cfg(feature = "double-precision")]
/// π as [fsize].
pub const PI: fsize = std::f64::consts::PI;

#[allow(non_camel_case_types)]
#[cfg(not(feature = "double-precision"))]
/// The floating point type used in jagua-rs.
/// ```f32``` by default, ```f64``` when feature **double-precision** is enabled.
pub type fsize = f32;

#[cfg(not(feature = "double-precision"))]
/// π as [fsize].
pub const PI: fsize = std::f32::consts::PI;