1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
//! Batch processing for high-performance distance calculations.
//!
//! This module provides functions for calculating distances on collections of coordinates,
//! with both serial and parallel implementations. Parallel functions require the `batch` feature.
//!
//! # Performance Considerations
//!
//! **Serial vs Parallel:**
//! - **Serial**: Better for small datasets (< 1,000 points) due to no threading overhead
//! - **Parallel**: Better for large datasets (> 10,000 points) when multiple CPU cores available
//! - **Breakeven point**: Usually around 1,000-5,000 points depending on CPU and calculation type
//!
//! **Memory Allocation:**
//! - Functions ending in `_into` write to pre-allocated buffers (faster, no allocation)
//! - Functions without `_into` allocate and return new vectors (convenient but slower)
//! - Use `_into` variants for hot paths and high-frequency calculations
//!
//! **Feature Requirements:**
//! - Basic functions: No features required
//! - `*_par*` functions: Require `batch` feature (enables Rayon parallel processing)
//! - `*_vincenty*` functions: Require `vincenty` feature
//! - Combined functions: Require both features (`batch` + `vincenty`)
//!
//! # Examples
//!
//! ```no_run
//! use rapidgeo_distance::{LngLat, batch::*};
//!
//! let points = vec![
//! LngLat::new_deg(-122.4194, 37.7749), // San Francisco
//! LngLat::new_deg(-74.0060, 40.7128), // New York
//! LngLat::new_deg(-87.6298, 41.8781), // Chicago
//! ];
//!
//! // Serial path calculation
//! let total_distance = path_length_haversine(&points);
//!
//! // Parallel calculation (requires batch feature)
//! #[cfg(feature = "batch")]
//! let distances = pairwise_haversine_par(&points);
//!
//! // Memory-efficient calculation
//! let mut buffer = vec![0.0; points.len() - 1];
//! pairwise_haversine_into(&points, &mut buffer);
//! ```
use crate::;
use *;
/// Calculates haversine distances between consecutive points in a path.
///
/// Returns an iterator over the distances between each pair of consecutive points.
/// Memory-efficient as it processes points lazily without allocating a result vector.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
///
/// # Returns
///
/// Iterator yielding distances in meters. Length will be `pts.len() - 1`.
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::pairwise_haversine};
///
/// let path = [
/// LngLat::new_deg(0.0, 0.0),
/// LngLat::new_deg(1.0, 0.0),
/// LngLat::new_deg(1.0, 1.0),
/// ];
///
/// let distances: Vec<f64> = pairwise_haversine(&path).collect();
/// assert_eq!(distances.len(), 2);
/// // Each distance is roughly 111 km (1 degree)
/// assert!(distances[0] > 110_000.0 && distances[0] < 112_000.0);
/// ```
+ '_
/// Calculates the total haversine distance along a path.
///
/// Sums all consecutive point-to-point distances using the haversine formula.
/// Equivalent to `pairwise_haversine(pts).sum()` but more convenient.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
///
/// # Returns
///
/// Total path length in meters
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::path_length_haversine};
///
/// let path = [
/// LngLat::new_deg(0.0, 0.0),
/// LngLat::new_deg(1.0, 0.0),
/// LngLat::new_deg(1.0, 1.0),
/// ];
///
/// let total_distance = path_length_haversine(&path);
/// // Two 1-degree segments ≈ 222 km total
/// assert!(total_distance > 220_000.0 && total_distance < 224_000.0);
/// ```
/// Calculates initial bearings between consecutive points in a path.
///
/// Returns an iterator over the bearings from each point to the next point.
/// Memory-efficient as it processes points lazily without allocating a result vector.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
///
/// # Returns
///
/// Iterator yielding bearings in degrees (0-360°). Length will be `pts.len() - 1`.
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::pairwise_bearings};
///
/// let path = [
/// LngLat::new_deg(0.0, 0.0),
/// LngLat::new_deg(1.0, 0.0),
/// LngLat::new_deg(1.0, 1.0),
/// ];
///
/// let bearings: Vec<f64> = pairwise_bearings(&path).collect();
/// assert_eq!(bearings.len(), 2);
/// assert!((bearings[0] - 90.0).abs() < 1.0); // East
/// assert!((bearings[1] - 0.0).abs() < 1.0); // North
/// ```
+ '_
/// Calculates bearings between consecutive points, writing to a pre-allocated buffer.
///
/// Memory-efficient version of [`pairwise_bearings`] that writes results to an existing buffer
/// instead of allocating a new vector.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
/// * `output` - Mutable slice to write bearings to (must be at least `pts.len() - 1` long)
///
/// # Panics
///
/// Panics if output buffer is too small to hold all results.
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::pairwise_bearings_into};
///
/// let path = [
/// LngLat::new_deg(0.0, 0.0),
/// LngLat::new_deg(1.0, 0.0),
/// LngLat::new_deg(1.0, 1.0),
/// ];
///
/// let mut bearings = vec![0.0; path.len() - 1];
/// pairwise_bearings_into(&path, &mut bearings);
///
/// assert!((bearings[0] - 90.0).abs() < 1.0); // East
/// assert!((bearings[1] - 0.0).abs() < 1.0); // North
/// ```
/// Parallel version of [`pairwise_bearings`] that returns a vector.
///
/// Uses Rayon for parallel processing. More efficient for large datasets (>1,000 points)
/// but has overhead for small datasets. Requires the `batch` feature.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
///
/// # Returns
///
/// Vector of bearings in degrees (0-360°). Length will be `pts.len() - 1`.
///
/// # Examples
///
/// ```no_run
/// # #[cfg(feature = "batch")]
/// # {
/// use rapidgeo_distance::{LngLat, batch::pairwise_bearings_par};
///
/// let path: Vec<LngLat> = (0..10000)
/// .map(|i| LngLat::new_deg(i as f64 * 0.001, 0.0))
/// .collect();
///
/// let bearings = pairwise_bearings_par(&path);
/// assert_eq!(bearings.len(), path.len() - 1);
/// # }
/// ```
/// Parallel version of [`pairwise_bearings_into`] that writes to a pre-allocated buffer.
///
/// Uses Rayon for parallel processing. More efficient for large datasets (>1,000 points).
/// Requires the `batch` feature.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
/// * `output` - Mutable slice to write bearings to (must be at least `pts.len() - 1` long)
///
/// # Panics
///
/// Panics if output buffer is too small.
///
/// # Examples
///
/// ```no_run
/// # #[cfg(feature = "batch")]
/// # {
/// use rapidgeo_distance::{LngLat, batch::pairwise_bearings_par_into};
///
/// let path: Vec<LngLat> = (0..10000)
/// .map(|i| LngLat::new_deg(i as f64 * 0.001, 0.0))
/// .collect();
///
/// let mut bearings = vec![0.0; path.len() - 1];
/// pairwise_bearings_par_into(&path, &mut bearings);
/// # }
/// ```
/// Parallel version of [`pairwise_haversine`] that returns a vector.
///
/// Uses Rayon for parallel processing. More efficient for large datasets (>1,000 points)
/// but has overhead for small datasets. Requires the `batch` feature.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
///
/// # Returns
///
/// Vector of distances in meters. Length will be `pts.len() - 1`.
///
/// # Examples
///
/// ```no_run
/// # #[cfg(feature = "batch")]
/// # {
/// use rapidgeo_distance::{LngLat, batch::pairwise_haversine_par};
///
/// let path: Vec<LngLat> = (0..10000)
/// .map(|i| LngLat::new_deg(i as f64 * 0.001, 0.0))
/// .collect();
///
/// // Parallel processing beneficial for large datasets
/// let distances = pairwise_haversine_par(&path);
/// assert_eq!(distances.len(), path.len() - 1);
/// # }
/// ```
/// Parallel version of [`path_length_haversine`] that processes using [Rayon](https://docs.rs/rayon/).
///
/// Uses [Rayon](https://docs.rs/rayon/) for parallel processing of path segments across multiple CPU cores.
/// More efficient for large datasets (>10,000 points) but has threading overhead for small datasets.
/// Requires the `batch` feature.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
///
/// # Returns
///
/// Total path length in meters
///
/// # Examples
///
/// ```no_run
/// # #[cfg(feature = "batch")]
/// # {
/// use rapidgeo_distance::{LngLat, batch::path_length_haversine_par};
///
/// let path: Vec<LngLat> = (0..10000)
/// .map(|i| LngLat::new_deg(i as f64 * 0.001, 0.0))
/// .collect();
///
/// // Parallel processing beneficial for large datasets
/// let total_distance = path_length_haversine_par(&path);
/// assert!(total_distance > 0.0);
/// # }
/// ```
///
/// # Performance Notes
///
/// Parallel processing is most beneficial when:
/// - Dataset size > 1,000 points
/// - Multiple CPU cores are available
/// - CPU is not already saturated with other work
/// Calculates distances from multiple points to a single target point in parallel.
///
/// Uses [Rayon](https://docs.rs/rayon/) to compute haversine distances from each point
/// to the target in parallel. Beneficial for large point sets (>1,000 points).
///
/// # Arguments
///
/// * `points` - Slice of coordinates to measure from
/// * `target` - Target coordinate to measure to
///
/// # Returns
///
/// Vector of distances in meters, same length as input points
///
/// # Examples
///
/// ```no_run
/// # #[cfg(feature = "batch")]
/// # {
/// use rapidgeo_distance::{LngLat, batch::distances_to_point_par};
///
/// let points: Vec<LngLat> = vec![
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-74.0060, 40.7128), // New York
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// ];
/// let target = LngLat::new_deg(0.0, 0.0); // Prime Meridian
///
/// let distances = distances_to_point_par(&points, target);
/// assert_eq!(distances.len(), points.len());
/// # }
/// ```
/// Calculates high-precision distances from multiple points to a target using Vincenty in parallel.
///
/// Uses [Rayon](https://docs.rs/rayon/) to compute [Vincenty distances](https://en.wikipedia.org/wiki/Vincenty%27s_formulae)
/// from each point to the target in parallel. Provides ±1mm accuracy but slower than haversine.
/// Requires both `batch` and `vincenty` features.
///
/// # Arguments
///
/// * `points` - Slice of coordinates to measure from
/// * `target` - Target coordinate to measure to
///
/// # Returns
///
/// - `Ok(Vec<f64>)` - Vector of distances in meters, same length as input points
/// - `Err(VincentyError)` - If any calculation fails (antipodal points, invalid coordinates)
///
/// # Examples
///
/// ```no_run
/// # #[cfg(all(feature = "batch", feature = "vincenty"))]
/// # {
/// use rapidgeo_distance::{LngLat, batch::distances_to_point_vincenty_par};
///
/// let points = vec![
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-74.0060, 40.7128), // New York
/// ];
/// let target = LngLat::new_deg(0.0, 0.0);
///
/// match distances_to_point_vincenty_par(&points, target) {
/// Ok(distances) => println!("Precise distances: {:?}", distances),
/// Err(e) => eprintln!("Calculation failed: {:?}", e),
/// }
/// # }
/// ```
/// Calculates haversine distances between consecutive points, writing to a pre-allocated buffer.
///
/// Memory-efficient version of [`pairwise_haversine`] that writes results to an existing buffer
/// instead of allocating a new vector. Useful for high-frequency calculations or when
/// memory allocation should be avoided.
///
/// # Arguments
///
/// * `pts` - Slice of coordinates representing a path
/// * `output` - Mutable slice to write distances to (must be at least `pts.len() - 1` long)
///
/// # Panics
///
/// Panics if output buffer is too small to hold all results.
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::pairwise_haversine_into};
///
/// let path = [
/// LngLat::new_deg(0.0, 0.0),
/// LngLat::new_deg(1.0, 0.0),
/// LngLat::new_deg(1.0, 1.0),
/// ];
///
/// let mut distances = vec![0.0; path.len() - 1];
/// pairwise_haversine_into(&path, &mut distances);
///
/// // distances now contains the calculated values
/// assert_eq!(distances.len(), 2);
/// assert!(distances[0] > 100_000.0); // ~1 degree
/// ```
/// Calculates distances between consecutive point pairs using parallel processing.
///
/// Computes the [Haversine distance](https://en.wikipedia.org/wiki/Haversine_formula) between each
/// consecutive pair of points in the input slice, writing results directly to the output buffer.
/// Uses [Rayon](https://docs.rs/rayon/) for parallel computation when processing large datasets.
///
/// # Arguments
///
/// * `pts` - Slice of points to process
/// * `output` - Mutable buffer to write distances (must have length ≥ pts.len() - 1)
///
/// # Panics
///
/// Panics if output buffer is too small
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::pairwise_haversine_par_into};
///
/// let points = [
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// LngLat::new_deg(-74.0060, 40.7128), // New York
/// ];
///
/// let mut distances = vec![0.0; points.len() - 1];
/// pairwise_haversine_par_into(&points, &mut distances);
///
/// assert!(distances[0] > 2900000.0); // SF to Chicago ~2900km
/// assert!(distances[1] > 1100000.0); // Chicago to NYC ~1100km
/// ```
///
/// # Performance
///
/// Uses parallel processing for better performance on large datasets.
/// Consider using [`pairwise_haversine_into`] for small datasets (< 1000 points) to avoid parallelization overhead.
/// Calculates distances from multiple points to a single target point.
///
/// Computes the [Haversine distance](https://en.wikipedia.org/wiki/Haversine_formula) from each point
/// in the input slice to the target point, writing results directly to the output buffer.
/// Uses sequential processing - see [`distances_to_point_par_into`] for parallel version.
///
/// # Arguments
///
/// * `points` - Slice of points to measure from
/// * `target` - Target point to measure distances to
/// * `output` - Mutable buffer to write distances (must have length ≥ points.len())
///
/// # Panics
///
/// Panics if output buffer is too small
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::distances_to_point_into};
///
/// let points = [
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// LngLat::new_deg(-0.1278, 51.5074), // London
/// ];
/// let target = LngLat::new_deg(-74.0060, 40.7128); // New York
///
/// let mut distances = vec![0.0; points.len()];
/// distances_to_point_into(&points, target, &mut distances);
///
/// assert!(distances[0] > 4100000.0); // SF to NYC ~4100km
/// assert!(distances[1] > 1100000.0); // Chicago to NYC ~1100km
/// assert!(distances[2] > 5500000.0); // London to NYC ~5500km
/// ```
///
/// # Performance
///
/// Sequential processing suitable for small to medium datasets.
/// Use [`distances_to_point_par_into`] for better performance on large datasets.
/// Calculates distances from multiple points to a single target point using parallel processing.
///
/// Computes the [Haversine distance](https://en.wikipedia.org/wiki/Haversine_formula) from each point
/// in the input slice to the target point, writing results directly to the output buffer.
/// Uses [Rayon](https://docs.rs/rayon/) for parallel computation when processing large datasets.
///
/// # Arguments
///
/// * `points` - Slice of points to measure from
/// * `target` - Target point to measure distances to
/// * `output` - Mutable buffer to write distances (must have length ≥ points.len())
///
/// # Panics
///
/// Panics if output buffer is too small
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::distances_to_point_par_into};
///
/// let points = [
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// LngLat::new_deg(-0.1278, 51.5074), // London
/// ];
/// let target = LngLat::new_deg(-74.0060, 40.7128); // New York
///
/// let mut distances = vec![0.0; points.len()];
/// distances_to_point_par_into(&points, target, &mut distances);
///
/// assert!(distances[0] > 4100000.0); // SF to NYC ~4100km
/// assert!(distances[1] > 1100000.0); // Chicago to NYC ~1100km
/// assert!(distances[2] > 5500000.0); // London to NYC ~5500km
/// ```
///
/// # Performance
///
/// Uses parallel processing for better performance on large datasets.
/// Consider using [`distances_to_point_into`] for small datasets (< 1000 points) to avoid parallelization overhead.
/// Calculates high-precision distances from multiple points to a single target point.
///
/// Computes distances using [Vincenty's formulae](https://en.wikipedia.org/wiki/Vincenty%27s_formulae)
/// for the [WGS84 ellipsoid](https://en.wikipedia.org/wiki/World_Geodetic_System),
/// providing millimeter accuracy at the cost of slower computation.
/// Uses sequential processing - see [`distances_to_point_vincenty_par_into`] for parallel version.
///
/// # Arguments
///
/// * `points` - Slice of points to measure from
/// * `target` - Target point to measure distances to
/// * `output` - Mutable buffer to write distances (must have length ≥ points.len())
///
/// # Returns
///
/// `Ok(())` on success, `Err(VincentyError)` if algorithm fails to converge for any point pair
///
/// # Panics
///
/// Panics if output buffer is too small
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::distances_to_point_vincenty_into};
///
/// let points = [
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// ];
/// let target = LngLat::new_deg(-74.0060, 40.7128); // New York
///
/// let mut distances = vec![0.0; points.len()];
/// distances_to_point_vincenty_into(&points, target, &mut distances).unwrap();
///
/// // Vincenty provides millimeter precision
/// assert!(distances[0] > 4100000.0 && distances[0] < 4200000.0); // SF to NYC ~4150km
/// assert!(distances[1] > 1100000.0 && distances[1] < 1200000.0); // Chicago to NYC ~1150km
/// ```
///
/// # Errors
///
/// Returns [`geodesic::VincentyError::DidNotConverge`] for nearly antipodal points (opposite sides of Earth).
/// Consider using [`distances_to_point_into`] with Haversine as a fallback for such cases.
///
/// # Performance
///
/// Slower than Haversine but much more accurate. Sequential processing suitable for small to medium datasets.
/// Calculates high-precision distances from multiple points to a single target point using parallel processing.
///
/// Computes distances using [Vincenty's formulae](https://en.wikipedia.org/wiki/Vincenty%27s_formulae)
/// for the [WGS84 ellipsoid](https://en.wikipedia.org/wiki/World_Geodetic_System),
/// providing millimeter accuracy. Uses [Rayon](https://docs.rs/rayon/) for parallel computation.
///
/// # Arguments
///
/// * `points` - Slice of points to measure from
/// * `target` - Target point to measure distances to
/// * `output` - Mutable buffer to write distances (must have length ≥ points.len())
///
/// # Returns
///
/// `Ok(())` on success, `Err(VincentyError)` if algorithm fails to converge for any point pair
///
/// # Panics
///
/// Panics if output buffer is too small
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::distances_to_point_vincenty_par_into};
///
/// let points = [
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// LngLat::new_deg(-0.1278, 51.5074), // London
/// ];
/// let target = LngLat::new_deg(-74.0060, 40.7128); // New York
///
/// let mut distances = vec![0.0; points.len()];
/// distances_to_point_vincenty_par_into(&points, target, &mut distances).unwrap();
///
/// // Vincenty provides millimeter precision
/// assert!(distances[0] > 4100000.0 && distances[0] < 4200000.0); // SF to NYC ~4150km
/// ```
///
/// # Errors
///
/// Returns [`geodesic::VincentyError::DidNotConverge`] for nearly antipodal points.
/// All points are processed in parallel, but if any fail, the entire operation fails.
///
/// # Performance
///
/// Uses parallel processing for better performance on large datasets requiring high precision.
/// Consider [`distances_to_point_vincenty_into`] for small datasets to avoid parallelization overhead.
/// Calculates the total length of a path using high-precision geodesic distances.
///
/// Computes the sum of distances between consecutive points using [Vincenty's formulae](https://en.wikipedia.org/wiki/Vincenty%27s_formulae)
/// for the [WGS84 ellipsoid](https://en.wikipedia.org/wiki/World_Geodetic_System).
/// Provides millimeter accuracy for measuring GPS tracks, routes, and geographic paths.
///
/// # Arguments
///
/// * `pts` - Slice of points defining the path (minimum 2 points)
///
/// # Returns
///
/// `Ok(total_length_meters)` on success, `Err(VincentyError)` if algorithm fails to converge for any segment
///
/// # Examples
///
/// ```
/// use rapidgeo_distance::{LngLat, batch::path_length_vincenty_m};
///
/// // GPS track from San Francisco to NYC via Chicago
/// let path = [
/// LngLat::new_deg(-122.4194, 37.7749), // San Francisco
/// LngLat::new_deg(-87.6298, 41.8781), // Chicago
/// LngLat::new_deg(-74.0060, 40.7128), // New York City
/// ];
///
/// let total_length = path_length_vincenty_m(&path).unwrap();
/// assert!(total_length > 4000000.0); // > 4000km total
/// ```
///
/// # Use Cases
///
/// - GPS track analysis with millimeter precision
/// - Route planning and optimization
/// - Geographic survey measurements
/// - Research requiring geodetic accuracy
///
/// # Errors
///
/// Returns [`geodesic::VincentyError::DidNotConverge`] for paths containing nearly antipodal segments.
/// Consider using `path_length_haversine_m` as a fallback for such cases.
///
/// # Performance
///
/// Slower than Haversine-based path length calculation but provides surveyor-grade accuracy.
/// For paths with thousands of points, consider chunking or using approximate methods for real-time applications.