Skip to content

Commit 4367930

Browse files
committed
continue pushing generic numeric type through the library, breaking all the things
1 parent 8a8c4eb commit 4367930

32 files changed

+182
-182
lines changed

src/aabb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ pub struct Aabb<T: Scalar> {
66
pub maxs: Point3<T>,
77
}
88

9-
impl<T> Aabb<T: Scalar> {
9+
impl<T> Aabb<T> {
1010
#[inline]
1111
pub const fn new(mins: Point3<T>, maxs: Point3<T>) -> Self {
1212
Self { mins, maxs }
1313
}
1414

15-
pub fn intersects(&self, other: &Aabb) -> bool {
15+
pub fn intersects(&self, other: &Aabb<T>) -> bool {
1616
self.max.x >= other.min.x && self.min.x <= other.max.x &&
1717
self.max.y >= other.min.y && self.min.y <= other.max.y &&
1818
self.max.z >= other.min.z && self.min.z <= other.max.z

src/io/amf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::math_ndsp::Point3;
1010
use std::fmt::Debug;
1111
use std::io::Write;
1212

13-
impl<S: Clone + Debug + Send + Sync> Mesh<S> {
13+
impl<S: Clone + Debug + Send + Sync, T> Mesh<S, T> {
1414
/// Export this Mesh to AMF format as a string
1515
///
1616
/// Creates an AMF (Additive Manufacturing File Format) file containing:
@@ -246,7 +246,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
246246
}
247247
}
248248

249-
impl<S: Clone + Debug + Send + Sync> Sketch<S> {
249+
impl<S: Clone + Debug + Send + Sync, T> Sketch<S, T> {
250250
/// Export this Mesh to AMF format as a string
251251
///
252252
/// Creates an AMF (Additive Manufacturing File Format) file containing:

src/io/dxf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use dxf::Drawing;
1616
#[cfg(feature = "dxf-io")]
1717
use dxf::entities::*;
1818

19-
impl<S: Clone + Debug + Send + Sync> Mesh<S> {
19+
impl<S: Clone + Debug + Send + Sync, T> Mesh<S, T> {
2020
/// Import a Mesh object from DXF data.
2121
///
2222
/// ## Parameters
@@ -26,7 +26,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
2626
/// ## Returns
2727
/// A `Result` containing the Mesh object or an error if parsing fails.
2828
#[cfg(feature = "dxf-io")]
29-
pub fn from_dxf(dxf_data: &[u8], metadata: Option<S>) -> Result<Mesh<S>, Box<dyn Error>> {
29+
pub fn from_dxf(dxf_data: &[u8], metadata: Option<S>) -> Result<Mesh<S, T>, Box<dyn Error>> {
3030
// Load the DXF drawing from the provided data
3131
let drawing = Drawing::load(&mut Cursor::new(dxf_data))?;
3232

src/io/obj.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::math_ndsp::{Point3, Vector3};
1313
use std::fmt::Debug;
1414
use std::io::{BufRead, Write};
1515

16-
impl<S: Clone + Debug + Send + Sync> Mesh<S> {
16+
impl<S: Clone + Debug + Send + Sync, T> Mesh<S, T> {
1717
/// Export this Mesh to OBJ format as a string
1818
///
1919
/// Creates a Wavefront OBJ file containing:
@@ -142,7 +142,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
142142
/// # Ok(())
143143
/// # }
144144
/// ```
145-
pub fn from_obj<R: BufRead>(reader: R, metadata: Option<S>) -> std::io::Result<Mesh<S>> {
145+
pub fn from_obj<R: BufRead>(reader: R, metadata: Option<S>) -> std::io::Result<Mesh<S, T>> {
146146
let mut vertices = Vec::new();
147147
let mut normals = Vec::new();
148148
let mut polygons = Vec::new();
@@ -295,7 +295,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
295295
}
296296
}
297297

298-
impl<S: Clone + Debug + Send + Sync> Sketch<S> {
298+
impl<S: Clone + Debug + Send + Sync, T> Sketch<S, T> {
299299
/// Export this Mesh to OBJ format as a string
300300
///
301301
/// Creates a Wavefront OBJ file containing:

src/io/ply.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct PlyVertex {
1818
normal: Vector3<Real>,
1919
}
2020

21-
impl<S: Clone + Debug + Send + Sync> Mesh<S> {
21+
impl<S: Clone + Debug + Send + Sync, T> Mesh<S, T> {
2222
/// Export this Mesh to PLY format as a string
2323
///
2424
/// Creates a Stanford PLY file containing:
@@ -121,7 +121,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
121121
}
122122
}
123123

124-
impl<S: Clone + Debug + Send + Sync> Sketch<S> {
124+
impl<S: Clone + Debug + Send + Sync, T> Sketch<S, T> {
125125
/// Export this Sketch to PLY format as a string
126126
///
127127
/// Creates a Stanford PLY file containing:

src/io/stl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core2::io::Cursor;
1212

1313
use stl_io;
1414

15-
impl<S: Clone + Debug + Send + Sync> Mesh<S> {
15+
impl<S: Clone + Debug + Send + Sync, T> Mesh<S, T> {
1616
/// Export to ASCII STL
1717
/// Convert this Mesh to an **ASCII STL** string with the given `name`.
1818
///
@@ -117,7 +117,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
117117

118118
/// Create a Mesh object from STL data using 'stl_io'.
119119
#[cfg(feature = "stl-io")]
120-
pub fn from_stl(stl_data: &[u8], metadata: Option<S>) -> Result<Mesh<S>, std::io::Error> {
120+
pub fn from_stl(stl_data: &[u8], metadata: Option<S>) -> Result<Mesh<S, T>, std::io::Error> {
121121
// Create an in-memory cursor from the STL data
122122
let mut cursor = Cursor::new(stl_data);
123123

@@ -176,7 +176,7 @@ impl<S: Clone + Debug + Send + Sync> Mesh<S> {
176176
}
177177
}
178178

179-
impl<S: Clone + Debug + Send + Sync> Sketch<S> {
179+
impl<S: Clone + Debug + Send + Sync, T> Sketch<S, T> {
180180
/// Export to ASCII STL
181181
/// Convert this Sketch to an **ASCII STL** string with the given 'name'.
182182
///

src/io/svg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ pub trait ToSVG {
539539
fn to_svg(&self) -> String;
540540
}
541541

542-
impl<S: Clone> ToSVG for Sketch<S> {
542+
impl<S: Clone, T> ToSVG for Sketch<S, T> {
543543
fn to_svg(&self) -> String {
544544
use geo::Geometry::*;
545545
use svg::node::element;

src/math_ndsp.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ impl<T: Scalar> Rotation3<T> {
11291129

11301130
/// Create a rotation from an (optionally non-unit) axis and angle (radians).
11311131
/// Matches nalgebra’s `Rotation3::from_axis_angle`.
1132-
pub fn from_axis_angle(axis: &Vector3, angle: T) -> Self {
1132+
pub fn from_axis_angle(axis: &Vector3<T>, angle: T) -> Self {
11331133
let mut k = *axis;
11341134
let n2 = k.dot(&k);
11351135
if n2 <= consts::EPSILON * consts::EPSILON {
@@ -1161,7 +1161,7 @@ impl<T: Scalar> Rotation3<T> {
11611161

11621162
/// Small, numerically robust equivalent of nalgebra’s `rotation_between`.
11631163
/// Returns `None` if an input is near-zero length.
1164-
pub fn rotation_between(a: &Vector3, b: &Vector3) -> Option<Self> {
1164+
pub fn rotation_between(a: &Vector3<T>, b: &Vector3<T>) -> Option<Self> {
11651165
let la = a.norm();
11661166
let lb = b.norm();
11671167
if la <= consts::EPSILON || lb <= consts::EPSILON {
@@ -1203,17 +1203,17 @@ impl<T: Scalar> Rotation3<T> {
12031203
}
12041204
}
12051205

1206-
impl core::ops::Mul for Rotation3 {
1207-
type Output = Rotation3;
1206+
impl<T> core::ops::Mul for Rotation3<T> {
1207+
type Output = Rotation3<T>;
12081208
#[inline]
1209-
fn mul(self, rhs: Rotation3) -> Rotation3 {
1209+
fn mul(self, rhs: Rotation3<T>) -> Rotation3<T> {
12101210
Rotation3 { mat: self.mat * rhs.mat }
12111211
}
12121212
}
12131213

12141214
impl<T: Scalar> From<Matrix3<T>> for Rotation3<T> {
12151215
#[inline]
1216-
fn from(mat: Matrix3) -> Self { Self { mat } }
1216+
fn from(mat: Matrix3<T>) -> Self { Self { mat } }
12171217
}
12181218

12191219
// ------------------------------------------------------------
@@ -1236,7 +1236,7 @@ impl<T: Scalar> Translation3<T> {
12361236

12371237
/// Matches nalgebra’s `Translation3::from(Vector3)`.
12381238
#[inline]
1239-
pub fn from(v: Vector3) -> Self {
1239+
pub fn from(v: Vector3<T>) -> Self {
12401240
Self { v }
12411241
}
12421242

@@ -1248,7 +1248,7 @@ impl<T: Scalar> Translation3<T> {
12481248

12491249
impl<T: Scalar> From<Vector3<T>> for Translation3<T> {
12501250
#[inline]
1251-
fn from(v: Vector3) -> Self { Self { v } }
1251+
fn from(v: Vector3<T>) -> Self { Self { v } }
12521252
}
12531253

12541254
// ------------------------------------------------------------
@@ -1259,7 +1259,7 @@ pub struct Isometry3<T> {
12591259
pub rotation: Rotation3<T>,
12601260
}
12611261

1262-
impl Isometry3 {
1262+
impl<T> Isometry3<T> {
12631263
#[inline]
12641264
pub fn identity() -> Self {
12651265
Self { translation: Translation3::identity(),
@@ -1268,15 +1268,15 @@ impl Isometry3 {
12681268

12691269
/// Keep nalgebra’s call site working: `Isometry3::from_parts(Translation3, rot.into())`.
12701270
#[inline]
1271-
pub fn from_parts<R>(translation: Translation3, rotation: R) -> Self
1271+
pub fn from_parts<R>(translation: Translation3<T>, rotation: R) -> Self
12721272
where
12731273
R: Into<Rotation3>,
12741274
{
12751275
Self { translation, rotation: rotation.into() }
12761276
}
12771277

12781278
#[inline]
1279-
pub fn to_homogeneous(&self) -> Matrix4 {
1279+
pub fn to_homogeneous(&self) -> Matrix4<T> {
12801280
Matrix4::from_rotation_translation(self.rotation.mat, self.translation.v)
12811281
}
12821282

@@ -1290,7 +1290,7 @@ impl Isometry3 {
12901290

12911291
/// Vector transform (ignores translation): v' = R·v
12921292
#[inline]
1293-
pub fn transform_vector(&self, v: &Vector3) -> Vector3 {
1293+
pub fn transform_vector(&self, v: &Vector3<T>) -> Vector3<T> {
12941294
self.rotation.mat * *v
12951295
}
12961296
}

src/mesh/bsp.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ use std::fmt::Debug;
1313

1414
/// A [BSP](https://en.wikipedia.org/wiki/Binary_space_partitioning) tree node, containing polygons plus optional front/back subtrees
1515
#[derive(Debug, Clone)]
16-
pub struct Node<S: Clone> {
16+
pub struct Node<S: Clone, T> {
1717
/// Splitting plane for this node *or* **None** for a leaf that
1818
/// only stores polygons.
19-
pub plane: Option<Plane>,
19+
pub plane: Option<Plane<T>>,
2020

2121
/// Polygons in *front* half‑spaces.
22-
pub front: Option<Box<Node<S>>>,
22+
pub front: Option<Box<Node<S, T>>>,
2323

2424
/// Polygons in *back* half‑spaces.
25-
pub back: Option<Box<Node<S>>>,
25+
pub back: Option<Box<Node<S, T>>>,
2626

2727
/// Polygons that lie *exactly* on `plane`
2828
/// (after the node has been built).
2929
pub polygons: Vec<Polygon<S, T>>,
3030
}
3131

32-
impl<S: Clone + Send + Sync + Debug> Default for Node<S> {
32+
impl<S: Clone + Send + Sync + Debug, T> Default for Node<S, T> {
3333
fn default() -> Self {
3434
Self::new()
3535
}
3636
}
3737

38-
impl<S: Clone + Send + Sync + Debug> Node<S> {
38+
impl<S: Clone + Send + Sync + Debug, T> Node<S, T> {
3939
/// Create a new empty BSP node
4040
pub const fn new() -> Self {
4141
Self {
@@ -47,7 +47,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
4747
}
4848

4949
/// Creates a new BSP node from polygons
50-
pub fn from_polygons(polygons: &[Polygon<S>]) -> Self {
50+
pub fn from_polygons(polygons: &[Polygon<S, T>]) -> Self {
5151
let mut node = Self::new();
5252
if !polygons.is_empty() {
5353
node.build(polygons);
@@ -74,7 +74,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
7474
std::mem::swap(&mut self.front, &mut self.back);
7575
}
7676

77-
pub fn pick_best_splitting_plane(&self, polygons: &[Polygon<S>]) -> Plane {
77+
pub fn pick_best_splitting_plane(&self, polygons: &[Polygon<S, T>]) -> Plane<T> {
7878
const K_SPANS: Real = 8.0; // Weight for spanning polygons
7979
const K_BALANCE: Real = 1.0; // Weight for front/back balance
8080

@@ -115,7 +115,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
115115
/// Polygons entirely in BACK half-space are clipped (removed).
116116
/// **Algorithm**: O(n log d) where n is polygon count, d is tree depth.
117117
#[cfg(not(feature = "parallel"))]
118-
pub fn clip_polygons(&self, polygons: &[Polygon<S>]) -> Vec<Polygon<S>> {
118+
pub fn clip_polygons(&self, polygons: &[Polygon<S, T>]) -> Vec<Polygon<S, T>> {
119119
// If this node has no plane (i.e. it’s empty), just return
120120
if self.plane.is_none() {
121121
return polygons.to_vec();
@@ -161,7 +161,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
161161

162162
/// Remove all polygons in this BSP tree that are inside the other BSP tree
163163
#[cfg(not(feature = "parallel"))]
164-
pub fn clip_to(&mut self, bsp: &Node<S>) {
164+
pub fn clip_to(&mut self, bsp: &Node<S, T>) {
165165
self.polygons = bsp.clip_polygons(&self.polygons);
166166
if let Some(ref mut front) = self.front {
167167
front.clip_to(bsp);
@@ -173,7 +173,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
173173

174174
/// Return all polygons in this BSP tree using an iterative approach,
175175
/// avoiding potential stack overflow of recursive approach
176-
pub fn all_polygons(&self) -> Vec<Polygon<S>> {
176+
pub fn all_polygons(&self) -> Vec<Polygon<S, T>> {
177177
let mut result = Vec::new();
178178
let mut stack = vec![self];
179179

@@ -192,7 +192,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
192192

193193
/// Build a BSP tree from the given polygons
194194
#[cfg(not(feature = "parallel"))]
195-
pub fn build(&mut self, polygons: &[Polygon<S>]) {
195+
pub fn build(&mut self, polygons: &[Polygon<S, T>]) {
196196
if polygons.is_empty() {
197197
return;
198198
}
@@ -238,7 +238,7 @@ impl<S: Clone + Send + Sync + Debug> Node<S> {
238238
/// - All polygons that are coplanar with the plane (within EPSILON),
239239
/// - A list of line‐segment intersections (each a [Vertex; 2]) from polygons that span the plane.
240240
#[cfg(not(feature = "parallel"))]
241-
pub fn slice(&self, slicing_plane: &Plane) -> (Vec<Polygon<S>>, Vec<[Vertex; 2]>) {
241+
pub fn slice(&self, slicing_plane: &Plane<T>) -> (Vec<Polygon<S, T>>, Vec<[Vertex; 2]>) {
242242
let all_polys = self.all_polygons();
243243

244244
let mut coplanar_polygons = Vec::new();

src/mesh/connectivity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl VertexIndexMap {
6262
}
6363
}
6464

65-
impl<S: Clone + Debug + Send + Sync> Mesh<S> {
65+
impl<S: Clone + Debug + Send + Sync, T> Mesh<S, T> {
6666
/// **Mathematical Foundation: Robust Mesh Connectivity Analysis**
6767
///
6868
/// Build a proper vertex adjacency graph using epsilon-based vertex matching:

0 commit comments

Comments
 (0)