@@ -49,7 +49,12 @@ struct Fragment {
4949/// * `threshold` - The threshold value.
5050/// * `dx` - The number of columns in the grid.
5151/// * `dy` - The number of rows in the grid.
52- pub fn contour_rings ( values : & [ Float ] , threshold : Float , dx : u32 , dy : u32 ) -> Result < Vec < Ring > > {
52+ pub fn contour_rings (
53+ values : & [ Float ] ,
54+ threshold : Float ,
55+ dx : usize ,
56+ dy : usize ,
57+ ) -> Result < Vec < Ring > > {
5358 let mut isoring = IsoRingBuilder :: new ( dx, dy) ;
5459 isoring. compute ( values, threshold)
5560}
@@ -59,8 +64,8 @@ pub struct IsoRingBuilder {
5964 fragment_by_start : FxHashMap < usize , usize > ,
6065 fragment_by_end : FxHashMap < usize , usize > ,
6166 f : Slab < Fragment > ,
62- dx : u32 ,
63- dy : u32 ,
67+ dx : usize ,
68+ dy : usize ,
6469 is_empty : bool ,
6570}
6671
@@ -70,7 +75,7 @@ impl IsoRingBuilder {
7075 ///
7176 /// * `dx` - The number of columns in the grid.
7277 /// * `dy` - The number of rows in the grid.
73- pub fn new ( dx : u32 , dy : u32 ) -> Self {
78+ pub fn new ( dx : usize , dy : usize ) -> Self {
7479 IsoRingBuilder {
7580 fragment_by_start : FxHashMap :: default ( ) ,
7681 fragment_by_end : FxHashMap :: default ( ) ,
@@ -103,8 +108,8 @@ impl IsoRingBuilder {
103108 self . clear ( ) ;
104109 }
105110 let mut result = Vec :: new ( ) ;
106- let dx = self . dx as i32 ;
107- let dy = self . dy as i32 ;
111+ let dx = self . dx as i64 ;
112+ let dy = self . dy as i64 ;
108113 let mut x = -1 ;
109114 let mut y = -1 ;
110115 let mut t0;
@@ -113,68 +118,63 @@ impl IsoRingBuilder {
113118 let mut t3;
114119
115120 // Special case for the first row (y = -1, t2 = t3 = 0).
116- t1 = ( values[ 0 ] >= threshold) as u32 ;
117- case_stitch ! ( ( t1 << 1 ) as usize , x, y, & mut result) ;
121+ t1 = ( values[ 0 ] >= threshold) as usize ;
122+ case_stitch ! ( t1 << 1 , x, y, & mut result) ;
118123 x += 1 ;
119124 while x < dx - 1 {
120125 t0 = t1;
121- t1 = ( values[ ( x + 1 ) as usize ] >= threshold) as u32 ;
122- case_stitch ! ( ( t0 | t1 << 1 ) as usize , x, y, & mut result) ;
126+ t1 = ( values[ ( x + 1 ) as usize ] >= threshold) as usize ;
127+ case_stitch ! ( t0 | t1 << 1 , x, y, & mut result) ;
123128 x += 1 ;
124129 }
125- case_stitch ! ( t1 as usize , x, y, & mut result) ;
130+ case_stitch ! ( t1, x, y, & mut result) ;
126131
127132 // General case for the intermediate rows.
128133 y += 1 ;
129134 while y < dy - 1 {
130135 x = -1 ;
131- t1 = ( values[ ( y * dx + dx) as usize ] >= threshold) as u32 ;
132- t2 = ( values[ ( y * dx) as usize ] >= threshold) as u32 ;
133- case_stitch ! ( ( t1 << 1 | t2 << 2 ) as usize , x, y, & mut result) ;
136+ t1 = ( values[ ( y * dx + dx) as usize ] >= threshold) as usize ;
137+ t2 = ( values[ ( y * dx) as usize ] >= threshold) as usize ;
138+ case_stitch ! ( t1 << 1 | t2 << 2 , x, y, & mut result) ;
134139 x += 1 ;
135140 while x < dx - 1 {
136141 t0 = t1;
137- t1 = ( values[ ( y * dx + dx + x + 1 ) as usize ] >= threshold) as u32 ;
142+ t1 = ( values[ ( y * dx + dx + x + 1 ) as usize ] >= threshold) as usize ;
138143 t3 = t2;
139- t2 = ( values[ ( y * dx + x + 1 ) as usize ] >= threshold) as u32 ;
140- case_stitch ! (
141- ( t0 | t1 << 1 | t2 << 2 | t3 << 3 ) as usize ,
142- x,
143- y,
144- & mut result
145- ) ;
144+ t2 = ( values[ ( y * dx + x + 1 ) as usize ] >= threshold) as usize ;
145+ case_stitch ! ( t0 | t1 << 1 | t2 << 2 | t3 << 3 , x, y, & mut result) ;
146146 x += 1 ;
147147 }
148- case_stitch ! ( ( t1 | t2 << 3 ) as usize , x, y, & mut result) ;
148+ case_stitch ! ( t1 | t2 << 3 , x, y, & mut result) ;
149149 y += 1 ;
150150 }
151151
152152 // Special case for the last row (y = dy - 1, t0 = t1 = 0).
153153 x = -1 ;
154- t2 = ( values[ ( y * dx) as usize ] >= threshold) as u32 ;
155- case_stitch ! ( ( t2 << 2 ) as usize , x, y, & mut result) ;
154+ t2 = ( values[ ( y * dx) as usize ] >= threshold) as usize ;
155+ case_stitch ! ( t2 << 2 , x, y, & mut result) ;
156156 x += 1 ;
157157 while x < dx - 1 {
158158 t3 = t2;
159- t2 = ( values[ ( y * dx + x + 1 ) as usize ] >= threshold) as u32 ;
160- case_stitch ! ( ( t2 << 2 | t3 << 3 ) as usize , x, y, & mut result) ;
159+ t2 = ( values[ ( y * dx + x + 1 ) as usize ] >= threshold) as usize ;
160+ case_stitch ! ( t2 << 2 | t3 << 3 , x, y, & mut result) ;
161161 x += 1 ;
162162 }
163- case_stitch ! ( ( t2 << 3 ) as usize , x, y, & mut result) ;
163+ case_stitch ! ( t2 << 3 , x, y, & mut result) ;
164164 self . is_empty = false ;
165165 Ok ( result)
166166 }
167167
168168 fn index ( & self , point : & Pt ) -> usize {
169- ( point. x * 2.0 + point. y * ( self . dx as Float + 1. ) * 4. ) as usize
169+ ( point. x as usize ) * 2 + ( point. y as usize ) * ( self . dx + 1usize ) * 4
170170 }
171171
172172 // Stitchs segments to rings.
173173 fn stitch (
174174 & mut self ,
175175 line : & [ Vec < Float > ] ,
176- x : i32 ,
177- y : i32 ,
176+ x : i64 ,
177+ y : i64 ,
178178 result : & mut Vec < Ring > ,
179179 ) -> Result < ( ) > {
180180 let start = Pt {
0 commit comments