1use serde::Serialize;
3
4#[serde_with::skip_serializing_none]
5#[derive(Serialize, Debug, Clone, Default, PartialEq)]
6struct AutoCostingOptionsInner {
7 maneuver_penalty: Option<f32>,
8 gate_cost: Option<f32>,
9 gate_penalty: Option<f32>,
10 private_access_penalty: Option<f32>,
11 destination_only_penalty: Option<f32>,
12 toll_booth_cost: Option<f32>,
13 toll_booth_penalty: Option<f32>,
14 ferry_cost: Option<f32>,
15 use_ferry: Option<f32>,
16 use_highways: Option<f32>,
17 use_tolls: Option<f32>,
18 use_living_streets: Option<f32>,
19 use_tracks: Option<f32>,
20 service_penalty: Option<f32>,
21 service_factor: Option<f32>,
22 country_crossing_cost: Option<f32>,
23 country_crossing_penalty: Option<f32>,
24 shortest: Option<bool>,
25 use_distance: Option<f32>,
26 disable_hierarchy_pruning: Option<bool>,
27 top_speed: Option<f32>,
28 fixed_speed: Option<u32>,
29 closure_factor: Option<f32>,
30 ignore_closures: Option<bool>,
31 ignore_restrictions: Option<bool>,
32 ignore_oneways: Option<bool>,
33 ignore_non_vehicular_restrictions: Option<bool>,
34 ignore_access: Option<bool>,
35 speed_types: Option<UsedSpeedSources>,
37 height: Option<f32>,
38 width: Option<f32>,
39 exclude_unpaved: Option<bool>,
40 exclude_cash_only_tolls: Option<bool>,
41 include_hov2: Option<bool>,
42 include_hov3: Option<bool>,
43 include_hot: Option<bool>,
44}
45
46#[derive(Serialize, Debug, Clone, Default, PartialEq)]
47pub struct AutoCostingOptions {
49 auto: AutoCostingOptionsInner,
50}
51impl AutoCostingOptions {
52 #[must_use]
53 pub fn builder() -> Self {
55 Self::default()
56 }
57
58 pub fn gate_cost(mut self, gate_cost: f32) -> Self {
65 self.auto.gate_cost = Some(gate_cost);
66 self
67 }
68 pub fn gate_penalty(mut self, gate_penalty: f32) -> Self {
73 self.auto.gate_penalty = Some(gate_penalty);
74 self
75 }
76 pub fn private_access_penalty(mut self, private_access_penalty: f32) -> Self {
82 self.auto.private_access_penalty = Some(private_access_penalty);
83 self
84 }
85 pub fn destination_only_penalty(mut self, destination_only_penalty: f32) -> Self {
88 self.auto.destination_only_penalty = Some(destination_only_penalty);
89 self
90 }
91 pub fn toll_booth_cost(mut self, toll_booth_cost: f32) -> Self {
98 self.auto.toll_booth_cost = Some(toll_booth_cost);
99 self
100 }
101 pub fn toll_booth_penalty(mut self, toll_booth_penalty: f32) -> Self {
108 self.auto.toll_booth_penalty = Some(toll_booth_penalty);
109 self
110 }
111 pub fn ferry_cost(mut self, ferry_cost: f32) -> Self {
117 self.auto.ferry_cost = Some(ferry_cost);
118 self
119 }
120 pub fn use_ferry(mut self, use_ferry: f32) -> Self {
130 debug_assert!(use_ferry >= 0.0);
131 debug_assert!(use_ferry <= 1.0);
132 self.auto.use_ferry = Some(use_ferry);
133 self
134 }
135 pub fn use_highways(mut self, use_highways: f32) -> Self {
145 debug_assert!(use_highways >= 0.0);
146 debug_assert!(use_highways <= 1.0);
147 self.auto.use_highways = Some(use_highways);
148 self
149 }
150 pub fn use_tolls(mut self, use_tolls: f32) -> Self {
160 debug_assert!(use_tolls >= 0.0);
161 debug_assert!(use_tolls <= 1.0);
162 self.auto.use_tolls = Some(use_tolls);
163 self
164 }
165 pub fn use_living_streets(mut self, use_living_streets: f32) -> Self {
177 debug_assert!(use_living_streets >= 0.0);
178 debug_assert!(use_living_streets <= 1.0);
179 self.auto.use_living_streets = Some(use_living_streets);
180 self
181 }
182 pub fn use_tracks(mut self, use_tracks: f32) -> Self {
194 debug_assert!(use_tracks >= 0.0);
195 debug_assert!(use_tracks <= 1.0);
196 self.auto.use_tracks = Some(use_tracks);
197 self
198 }
199 pub fn service_penalty(mut self, service_penalty: f32) -> Self {
205 self.auto.service_penalty = Some(service_penalty);
206 self
207 }
208 pub fn service_factor(mut self, service_factor: f32) -> Self {
212 self.auto.service_factor = Some(service_factor);
213 self
214 }
215 pub fn country_crossing_cost(mut self, country_crossing_cost: f32) -> Self {
221 self.auto.country_crossing_cost = Some(country_crossing_cost);
222 self
223 }
224 pub fn country_crossing_penalty(mut self, country_crossing_penalty: f32) -> Self {
230 self.auto.country_crossing_penalty = Some(country_crossing_penalty);
231 self
232 }
233 pub fn only_consider_quasi_shortest(mut self) -> Self {
241 self.auto.shortest = Some(true);
242 self
243 }
244
245 pub fn use_distance(mut self, use_distance: f32) -> Self {
254 debug_assert!(use_distance >= 0.0);
255 debug_assert!(use_distance <= 1.0);
256 self.auto.use_distance = Some(use_distance);
257 self
258 }
259 pub fn disable_hierarchy_pruning(mut self) -> Self {
266 self.auto.disable_hierarchy_pruning = Some(true);
267 self
268 }
269 pub fn top_speed(mut self, top_speed: f32) -> Self {
278 debug_assert!(top_speed >= 10.0);
279 debug_assert!(top_speed <= 252.0);
280 self.auto.top_speed = Some(top_speed);
281 self
282 }
283 pub fn fixed_speed(mut self, fixed_speed: u32) -> Self {
291 debug_assert!(fixed_speed >= 1);
292 debug_assert!(fixed_speed <= 252);
293 self.auto.fixed_speed = Some(fixed_speed);
294 self
295 }
296 pub fn closure_factor(mut self, closure_factor: f32) -> Self {
310 self.auto.closure_factor = Some(closure_factor);
311 self
312 }
313 pub fn ignore_closures(mut self) -> Self {
318 self.auto.ignore_closures = Some(true);
319 self
320 }
321 pub fn ignore_restrictions(mut self) -> Self {
327 self.auto.ignore_restrictions = Some(true);
328 self
329 }
330 pub fn ignore_oneways(mut self) -> Self {
337 self.auto.ignore_oneways = Some(true);
338 self
339 }
340 pub fn ignore_non_vehicular_restrictions(mut self) -> Self {
345 self.auto.ignore_non_vehicular_restrictions = Some(true);
346 self
347 }
348 pub fn ignore_access(mut self) -> Self {
354 self.auto.ignore_access = Some(true);
355 self
356 }
357 pub fn speed_types(mut self, speed_types: UsedSpeedSources) -> Self {
368 if speed_types == UsedSpeedSources::All {
369 self.auto.speed_types = None
370 } else {
371 self.auto.speed_types = Some(speed_types);
372 }
373 self
374 }
375
376 pub fn height(mut self, height: f32) -> Self {
382 self.auto.height = Some(height);
383 self
384 }
385 pub fn width(mut self, width: f32) -> Self {
391 self.auto.width = Some(width);
392 self
393 }
394 pub fn exclude_unpaved(mut self) -> Self {
402 self.auto.exclude_unpaved = Some(true);
403 self
404 }
405 pub fn exclude_cash_only_tolls(mut self, exclude_cash_only_tolls: bool) -> Self {
409 self.auto.exclude_cash_only_tolls = Some(exclude_cash_only_tolls);
410 self
411 }
412 pub fn include_hov2(mut self, include_hov2: bool) -> Self {
416 self.auto.include_hov2 = Some(include_hov2);
417 self
418 }
419 pub fn include_hov3(mut self, include_hov3: bool) -> Self {
423 self.auto.include_hov3 = Some(include_hov3);
424 self
425 }
426 pub fn include_hot(mut self, include_hot: bool) -> Self {
430 self.auto.include_hot = Some(include_hot);
431 self
432 }
433}
434
435#[derive(Serialize, Debug, Clone, Copy, Eq, PartialEq)]
436pub enum UsedSpeedSources {
438 #[serde(rename = "all")]
439 All,
441 #[serde(rename = "freeflow")]
442 Freeflow,
444 #[serde(rename = "constrained")]
445 Constrained,
447 #[serde(rename = "predicted")]
448 Predicted,
450 #[serde(rename = "current")]
451 Current,
453}
454#[cfg(test)]
455mod test {
456 use super::*;
457 #[test]
458 fn serialisation() {
459 assert_eq!(
460 serde_json::to_value(AutoCostingOptions::default()).unwrap(),
461 serde_json::json!({"auto":{}})
462 );
463 }
464
465 #[test]
466 fn builder_returns_default() {
467 assert_eq!(AutoCostingOptions::builder(), AutoCostingOptions::default());
468 }
469
470 #[test]
471 fn gate_cost_sets_value() {
472 let opts = AutoCostingOptions::builder().gate_cost(45.0);
473 assert_eq!(opts.auto.gate_cost, Some(45.0));
474 }
475
476 #[test]
477 fn gate_penalty_sets_value() {
478 let opts = AutoCostingOptions::builder().gate_penalty(500.0);
479 assert_eq!(opts.auto.gate_penalty, Some(500.0));
480 }
481
482 #[test]
483 fn private_access_penalty_sets_value() {
484 let opts = AutoCostingOptions::builder().private_access_penalty(600.0);
485 assert_eq!(opts.auto.private_access_penalty, Some(600.0));
486 }
487
488 #[test]
489 fn destination_only_penalty_sets_value() {
490 let opts = AutoCostingOptions::builder().destination_only_penalty(100.0);
491 assert_eq!(opts.auto.destination_only_penalty, Some(100.0));
492 }
493
494 #[test]
495 fn toll_booth_cost_sets_value() {
496 let opts = AutoCostingOptions::builder().toll_booth_cost(20.0);
497 assert_eq!(opts.auto.toll_booth_cost, Some(20.0));
498 }
499
500 #[test]
501 fn toll_booth_penalty_sets_value() {
502 let opts = AutoCostingOptions::builder().toll_booth_penalty(250.0);
503 assert_eq!(opts.auto.toll_booth_penalty, Some(250.0));
504 }
505
506 #[test]
507 fn ferry_cost_sets_value() {
508 let opts = AutoCostingOptions::builder().ferry_cost(400.0);
509 assert_eq!(opts.auto.ferry_cost, Some(400.0));
510 }
511
512 #[test]
513 fn use_ferry_sets_value() {
514 let opts = AutoCostingOptions::builder().use_ferry(0.5);
515 assert_eq!(opts.auto.use_ferry, Some(0.5));
516 }
517
518 #[test]
519 fn use_highways_sets_value() {
520 let opts = AutoCostingOptions::builder().use_highways(0.8);
521 assert_eq!(opts.auto.use_highways, Some(0.8));
522 }
523
524 #[test]
525 fn use_tolls_sets_value() {
526 let opts = AutoCostingOptions::builder().use_tolls(0.3);
527 assert_eq!(opts.auto.use_tolls, Some(0.3));
528 }
529
530 #[test]
531 fn use_living_streets_sets_value() {
532 let opts = AutoCostingOptions::builder().use_living_streets(0.6);
533 assert_eq!(opts.auto.use_living_streets, Some(0.6));
534 }
535
536 #[test]
537 fn use_tracks_sets_value() {
538 let opts = AutoCostingOptions::builder().use_tracks(0.2);
539 assert_eq!(opts.auto.use_tracks, Some(0.2));
540 }
541
542 #[test]
543 fn service_penalty_sets_value() {
544 let opts = AutoCostingOptions::builder().service_penalty(10.0);
545 assert_eq!(opts.auto.service_penalty, Some(10.0));
546 }
547
548 #[test]
549 fn service_factor_sets_value() {
550 let opts = AutoCostingOptions::builder().service_factor(1.5);
551 assert_eq!(opts.auto.service_factor, Some(1.5));
552 }
553
554 #[test]
555 fn country_crossing_cost_sets_value() {
556 let opts = AutoCostingOptions::builder().country_crossing_cost(600.0);
557 assert_eq!(opts.auto.country_crossing_cost, Some(600.0));
558 }
559
560 #[test]
561 fn country_crossing_penalty_sets_value() {
562 let opts = AutoCostingOptions::builder().country_crossing_penalty(0.0);
563 assert_eq!(opts.auto.country_crossing_penalty, Some(0.0));
564 }
565
566 #[test]
567 fn use_distance_sets_value() {
568 let opts = AutoCostingOptions::builder().use_distance(0.9);
569 assert_eq!(opts.auto.use_distance, Some(0.9));
570 }
571
572 #[test]
573 fn disable_hierarchy_pruning_sets_value() {
574 let opts = AutoCostingOptions::builder().disable_hierarchy_pruning();
575 assert_eq!(opts.auto.disable_hierarchy_pruning, Some(true));
576 }
577
578 #[test]
579 fn only_consider_quasi_shortest_sets_value() {
580 let opts = AutoCostingOptions::builder().only_consider_quasi_shortest();
581 assert_eq!(opts.auto.shortest, Some(true));
582 }
583
584 #[test]
585 fn top_speed_sets_value() {
586 let opts = AutoCostingOptions::builder().top_speed(120.0);
587 assert_eq!(opts.auto.top_speed, Some(120.0));
588 }
589
590 #[test]
591 fn fixed_speed_sets_value() {
592 let opts = AutoCostingOptions::builder().fixed_speed(80);
593 assert_eq!(opts.auto.fixed_speed, Some(80));
594 }
595
596 #[test]
597 fn closure_factor_sets_value() {
598 let opts = AutoCostingOptions::builder().closure_factor(5.0);
599 assert_eq!(opts.auto.closure_factor, Some(5.0));
600 }
601
602 #[test]
603 fn ignore_closures_sets_value() {
604 let opts = AutoCostingOptions::builder().ignore_closures();
605 assert_eq!(opts.auto.ignore_closures, Some(true));
606 }
607
608 #[test]
609 fn ignore_restrictions_sets_value() {
610 let opts = AutoCostingOptions::builder().ignore_restrictions();
611 assert_eq!(opts.auto.ignore_restrictions, Some(true));
612 }
613
614 #[test]
615 fn ignore_oneways_sets_value() {
616 let opts = AutoCostingOptions::builder().ignore_oneways();
617 assert_eq!(opts.auto.ignore_oneways, Some(true));
618 }
619
620 #[test]
621 fn ignore_non_vehicular_restrictions_sets_value() {
622 let opts = AutoCostingOptions::builder().ignore_non_vehicular_restrictions();
623 assert_eq!(opts.auto.ignore_non_vehicular_restrictions, Some(true));
624 }
625
626 #[test]
627 fn ignore_access_sets_value() {
628 let opts = AutoCostingOptions::builder().ignore_access();
629 assert_eq!(opts.auto.ignore_access, Some(true));
630 }
631
632 #[test]
633 fn speed_types_sets_value() {
634 let opts = AutoCostingOptions::builder().speed_types(UsedSpeedSources::Freeflow);
635 assert_eq!(opts.auto.speed_types, Some(UsedSpeedSources::Freeflow));
636 }
637
638 #[test]
639 fn height_sets_value() {
640 let opts = AutoCostingOptions::builder().height(3.5);
641 assert_eq!(opts.auto.height, Some(3.5));
642 }
643
644 #[test]
645 fn width_sets_value() {
646 let opts = AutoCostingOptions::builder().width(2.5);
647 assert_eq!(opts.auto.width, Some(2.5));
648 }
649
650 #[test]
651 fn exclude_unpaved_sets_value() {
652 let opts = AutoCostingOptions::builder().exclude_unpaved();
653 assert_eq!(opts.auto.exclude_unpaved, Some(true));
654 }
655
656 #[test]
657 fn exclude_cash_only_tolls_sets_value() {
658 let opts = AutoCostingOptions::builder().exclude_cash_only_tolls(true);
659 assert_eq!(opts.auto.exclude_cash_only_tolls, Some(true));
660 }
661
662 #[test]
663 fn include_hov2_sets_value() {
664 let opts = AutoCostingOptions::builder().include_hov2(true);
665 assert_eq!(opts.auto.include_hov2, Some(true));
666 }
667
668 #[test]
669 fn include_hov3_sets_value() {
670 let opts = AutoCostingOptions::builder().include_hov3(true);
671 assert_eq!(opts.auto.include_hov3, Some(true));
672 }
673
674 #[test]
675 fn include_hot_sets_value() {
676 let opts = AutoCostingOptions::builder().include_hot(true);
677 assert_eq!(opts.auto.include_hot, Some(true));
678 }
679
680 #[test]
681 fn chaining_works() {
682 let opts = AutoCostingOptions::builder()
683 .gate_cost(45.0)
684 .use_highways(0.8)
685 .top_speed(120.0);
686 assert_eq!(opts.auto.gate_cost, Some(45.0));
687 assert_eq!(opts.auto.use_highways, Some(0.8));
688 assert_eq!(opts.auto.top_speed, Some(120.0));
689 }
690}