@@ -159,6 +159,7 @@ impl<Frame> Ransac<Frame> {
159
159
& mut self ,
160
160
random_number_generator : & mut impl Rng ,
161
161
iterations : usize ,
162
+ fit_two_lines : bool ,
162
163
maximum_score_distance : f32 ,
163
164
maximum_inclusion_distance : f32 ,
164
165
) -> RansacResult < Frame > {
@@ -184,14 +185,27 @@ impl<Frame> Ransac<Frame> {
184
185
185
186
let best_feature = ( 0 ..iterations)
186
187
. map ( |_| {
187
- let mut points = self
188
- . unused_points
189
- . choose_multiple ( random_number_generator, 3 ) ;
190
- let feature = RansacFeature :: from_points (
191
- * points. next ( ) . unwrap ( ) ,
192
- * points. next ( ) . unwrap ( ) ,
193
- * points. next ( ) . unwrap ( ) ,
194
- ) ;
188
+ let feature = if fit_two_lines {
189
+ let mut points = self
190
+ . unused_points
191
+ . choose_multiple ( random_number_generator, 3 ) ;
192
+
193
+ RansacFeature :: from_points (
194
+ * points. next ( ) . unwrap ( ) ,
195
+ * points. next ( ) . unwrap ( ) ,
196
+ * points. next ( ) . unwrap ( ) ,
197
+ )
198
+ } else {
199
+ let mut points = self
200
+ . unused_points
201
+ . choose_multiple ( random_number_generator, 2 ) ;
202
+
203
+ RansacFeature :: Line ( Line :: from_points (
204
+ * points. next ( ) . unwrap ( ) ,
205
+ * points. next ( ) . unwrap ( ) ,
206
+ ) )
207
+ } ;
208
+
195
209
let score = feature. score (
196
210
self . unused_points . iter ( ) ,
197
211
maximum_score_distance,
@@ -232,7 +246,7 @@ mod test {
232
246
let mut ransac = Ransac :: < SomeFrame > :: new ( vec ! [ ] ) ;
233
247
let mut rng = ChaChaRng :: from_entropy ( ) ;
234
248
assert_eq ! (
235
- ransac. next_feature( & mut rng, 10 , 5.0 , 5.0 ) ,
249
+ ransac. next_feature( & mut rng, 10 , false , 5.0 , 5.0 ) ,
236
250
RansacResult :: default ( )
237
251
) ;
238
252
}
@@ -242,7 +256,7 @@ mod test {
242
256
let mut ransac = Ransac :: < SomeFrame > :: new ( vec ! [ ] ) ;
243
257
let mut rng = ChaChaRng :: from_entropy ( ) ;
244
258
assert_eq ! (
245
- ransac. next_feature( & mut rng, 10 , 5.0 , 5.0 ) ,
259
+ ransac. next_feature( & mut rng, 10 , false , 5.0 , 5.0 ) ,
246
260
RansacResult :: default ( )
247
261
) ;
248
262
}
@@ -256,7 +270,7 @@ mod test {
256
270
let RansacResult {
257
271
feature,
258
272
used_points,
259
- } = ransac. next_feature ( & mut rng, 10 , 5.0 , 5.0 ) ;
273
+ } = ransac. next_feature ( & mut rng, 10 , false , 5.0 , 5.0 ) ;
260
274
println ! ( "{feature:#?}" ) ;
261
275
println ! ( "{used_points:#?}" ) ;
262
276
@@ -282,7 +296,7 @@ mod test {
282
296
283
297
let mut ransac = Ransac :: < SomeFrame > :: new ( points. clone ( ) ) ;
284
298
let mut rng = ChaChaRng :: from_entropy ( ) ;
285
- let result = ransac. next_feature ( & mut rng, 15 , 1.0 , 1.0 ) ;
299
+ let result = ransac. next_feature ( & mut rng, 15 , false , 1.0 , 1.0 ) ;
286
300
287
301
if let RansacFeature :: Line ( line) = result. feature {
288
302
assert_relative_eq ! ( line. slope( ) , slope, epsilon = 0.0001 ) ;
0 commit comments