@@ -5,9 +5,9 @@ use std::collections::HashMap;
5
5
use std:: path:: Path ;
6
6
7
7
use flatbuffers:: { ForwardsUOffset , Vector , WIPOffset } ;
8
- use geo:: { point , Coord , LineLocatePoint } ;
8
+ use geo:: Coord ;
9
9
10
- use crate :: curves:: { Curve , SphericalLineStringCurve } ;
10
+ use crate :: curves:: { Curve , CurveError , CurveProjection , SphericalLineStringCurve } ;
11
11
12
12
use crate :: lrs_generated:: { self , * } ;
13
13
use crate :: osm_helpers:: sort_edges;
@@ -260,8 +260,9 @@ impl<'fbb> Builder<'fbb> {
260
260
self . temp_traversal . len ( ) - 1
261
261
}
262
262
263
- /// Private function to add lrm
264
- fn add_lrm (
263
+ /// Create a linear referencing method where the distance is provided.
264
+ /// The [`Anchor`]s will be projected on the [`Curve`].
265
+ pub fn add_lrm (
265
266
& mut self ,
266
267
id : & str ,
267
268
traversal_index : usize ,
@@ -288,73 +289,6 @@ impl<'fbb> Builder<'fbb> {
288
289
. push ( LinearReferencingMethod :: create ( & mut self . fbb , & args) ) ;
289
290
}
290
291
291
- /// Create a linear referencing method where the distance is provided.
292
- /// The [`Anchor`]s will be projected on the [`Curve`].
293
- pub fn add_lrm_with_distances (
294
- & mut self ,
295
- id : & str ,
296
- traversal_index : usize ,
297
- anchors : & [ AnchorOnLrm ] ,
298
- properties : Properties ,
299
- ) {
300
- // Heuristic to know if the traversal needs to be reversed
301
- let anchor_coords: Vec < _ > = anchors
302
- . iter ( )
303
- . filter_map ( |anchor| match self . temp_anchors [ anchor. anchor_index ] {
304
- AnchorPosition :: Curve ( _) => None ,
305
- AnchorPosition :: Geographical ( coord) => Some ( coord) ,
306
- } )
307
- . collect ( ) ;
308
- if let [ first_coord, .., last_coord] = anchor_coords[ ..] {
309
- if let [ first_anchor, .., last_anchor] = anchors {
310
- let curve = & mut self . temp_traversal [ traversal_index] . curve ;
311
- let projected_first = curve
312
- . project ( first_coord. into ( ) )
313
- . expect ( "could not project anchor" ) ;
314
- let projected_last = curve
315
- . project ( last_coord. into ( ) )
316
- . expect ( "could not project anchor" ) ;
317
-
318
- let anchor_ord = first_anchor
319
- . distance_along_lrm
320
- . total_cmp ( & last_anchor. distance_along_lrm ) ;
321
- let projection_ord = projected_first
322
- . distance_along_curve
323
- . total_cmp ( & projected_last. distance_along_curve ) ;
324
- if anchor_ord != projection_ord {
325
- self . temp_traversal [ traversal_index] . reverse ( )
326
- }
327
- }
328
- }
329
- self . add_lrm ( id, traversal_index, anchors, properties)
330
- }
331
-
332
- /// Create a linear referencing method where the distance is provided.
333
- /// Compared to `Builder::add_lrm_with_distances`, this function takes a reference_traversal_index
334
- /// That is used to help orient the curve
335
- pub fn add_lrm_with_distances_with_orientation (
336
- & mut self ,
337
- id : & str ,
338
- traversal_index : usize ,
339
- reference_traversal_index : usize ,
340
- anchors : & [ AnchorOnLrm ] ,
341
- properties : Properties ,
342
- ) {
343
- if let [ first_point, .., last_point] =
344
- & self . temp_traversal [ traversal_index] . curve . geom . 0 [ ..]
345
- {
346
- let first = point ! { x: first_point. x, y: first_point. y} ;
347
- let last = point ! { x: last_point. x, y: last_point. y} ;
348
- let reference_curve = & self . temp_traversal [ reference_traversal_index] . curve . geom ;
349
- let first_distance = reference_curve. line_locate_point ( & first) ;
350
- let last_distance = reference_curve. line_locate_point ( & last) ;
351
-
352
- if first_distance > last_distance {
353
- self . temp_traversal [ traversal_index] . reverse ( )
354
- }
355
- }
356
- self . add_lrm ( id, traversal_index, anchors, properties)
357
- }
358
292
/// Private helper that projects [`Anchor`]s onto a [`Curve`].
359
293
fn project_anchors (
360
294
& mut self ,
@@ -552,6 +486,16 @@ impl<'fbb> Builder<'fbb> {
552
486
geo:: EuclideanDistance :: euclidean_distance ( a, b)
553
487
}
554
488
489
+ /// Returns the position along the curve of the traversal
490
+ /// The value will be between 0.0 and 1.0, both included
491
+ pub fn project (
492
+ & self ,
493
+ lrm_index : usize ,
494
+ point : geo:: Point ,
495
+ ) -> Result < CurveProjection , CurveError > {
496
+ self . temp_traversal [ lrm_index] . curve . project ( point)
497
+ }
498
+
555
499
/// Reverses the direction of the traversal
556
500
pub fn reverse ( & mut self , lrm_index : usize ) {
557
501
self . temp_traversal [ lrm_index] . reverse ( ) ;
0 commit comments