@@ -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 ( ) ;
0 commit comments