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
//! Strategy for summing the length of a sequence of points.
//!
//! Mirrors three pieces of Boost.Geometry that collaborate to make
//! `boost::geometry::length(g)` and `boost::geometry::perimeter(g)`
//! work for any linestring / ring / polygon in any coordinate system:
//!
//! * `boost/geometry/strategies/length/services.hpp` — the
//! `services::default_strategy<G>` metafunction that picks the
//! per-CS length strategy.
//! * `boost/geometry/strategies/length/cartesian.hpp` —
//! `strategies::length::cartesian<>` plus its
//! `services::default_strategy<Geometry, cartesian_tag>`
//! specialisation; the Cartesian implementation hands a
//! `strategy::distance::pythagoras<>` to the algorithm.
//! * `boost/geometry/algorithms/length.hpp:80-107` —
//! `detail::length::range_length` walks the iterator pair and sums
//! the per-segment distances; this file performs the same walk in
//! Rust against the [`Linestring`] / [`Ring`] traits.
//!
//! T33 lands the Cartesian implementation only — Boost's
//! Spherical/Geographic length strategies arrive alongside the
//! Haversine / Andoyer / Vincenty distance strategies in later
//! tasks (T40+).
use CoordinateScalar;
use ;
use SameAs;
use ;
use cratePythagoras;
use crateDistanceStrategy;
/// A strategy for computing the length of a sequence of points.
///
/// Mirrors the per-CS length-strategy concept declared in
/// `boost/geometry/strategies/length/services.hpp` and refined per
/// coordinate system in `strategies/length/{cartesian,spherical,
/// geographic}.hpp`. The Boost concept exposes a `distance(p1, p2)`
/// helper that hands the algorithm a point-to-point distance kernel;
/// the Rust analogue collapses the two layers (strategy + algorithm
/// walk) into a single method [`LengthStrategy::length`] keyed on the
/// geometry type, because the walk shape is identical for every CS —
/// only the inner distance kernel changes.
///
/// # Associated items
///
/// * [`Self::Out`] — the scalar the length comes back as.
/// Equivalent to Boost's `default_length_result<Geometry>::type`
/// (`strategies/default_length_result.hpp`); typically the
/// coordinate scalar of `G`'s point type.
/// Cartesian length: sum of Pythagorean distances between
/// consecutive points (linestring case).
///
/// Mirrors `boost::geometry::strategies::length::cartesian<>` from
/// `strategies/length/cartesian.hpp:29-39`. The strategy carries no
/// state — `cartesian<>::distance(p1, p2)` returns a fresh
/// `strategy::distance::pythagoras<>` each call, which on the Rust
/// side is the unit-struct [`Pythagoras`] used directly below.
;
/// Cartesian perimeter: sum of Pythagorean distances between
/// consecutive points of a ring, plus the closing edge when the ring
/// is open.
///
/// Separate from [`CartesianLength`] because Rust's coherence rules
/// cannot prove that a single type does not implement both
/// [`Linestring`] and [`Ring`]; splitting the strategy keeps the
/// per-tag dispatch disjoint at the impl level.
;
// ---- Linestring ------------------------------------------------------
//
// Mirrors the `dispatch::length<Geometry, linestring_tag>` arm at
// `algorithms/length.hpp:132-135`, which inherits from
// `detail::length::range_length<Geometry, closed>`. A linestring is
// already "closed" in the range_length sense: the closing edge from
// last to first is *not* added — that is the perimeter case (rings).
// ---- Ring ------------------------------------------------------------
//
// Mirrors the `dispatch::perimeter<Geometry, ring_tag>` arm at
// `algorithms/perimeter.hpp:66-73`, which inherits from
// `detail::length::range_length<Geometry, closure<Geometry>::value>`.
// For a closed ring the closing edge is already encoded as the
// repeated last point; for an open ring we add the explicit
// last->first segment. Boost achieves the same via
// `views::closeable_view` at `algorithms/length.hpp:90`.
/// Walk `it` summing Pythagorean distances between consecutive
/// points. Returns `P::Scalar::ZERO` for an empty or single-point
/// range — same as Boost's `range_length` whose initial sum is
/// default-constructed (`return_type sum = return_type();`,
/// `algorithms/length.hpp:89`).
// Zero-on-mismatched-kind (Boost `length.hpp:75-80`: length of a
// point / polygon / multi-point is 0) is NOT expressed as a static
// `LengthStrategy` impl here: `CartesianLength` carries a blanket
// `impl<L: Linestring>` (so downstream `register_linestring!` types
// work), and Rust coherence forbids adding a disjoint concrete-type
// impl alongside a blanket one — the compiler cannot prove a foreign
// `Point`/`Polygon` will never also implement `Linestring`. The
// zero-length contract therefore lives on the *dynamic* path only:
// `geometry_algorithm::length_dyn` returns 0 for the non-linear arms
// (KC4.T1). The static `length<G: Linestring>` keeps v1's
// compile-error stance for non-linear kinds, which is a clearer signal
// when the kind is known at compile time.
// ---- Default length strategy per CS family --------------------------
/// "Which length strategy do we pick by default for this CS family?"
///
/// Mirrors v1's [`DefaultDistance`](crate::distance::DefaultDistance)
/// for the length algorithm — the Rust analogue of Boost's
/// `services::default_strategy<Geometry, cs_tag>` in
/// `strategies/length/services.hpp`, specialised per CS in
/// `strategies/length/{cartesian,spherical,geographic}.hpp`.
///
/// Length is unary, so — unlike `DefaultDistance` — there is exactly
/// one family type parameter (there is no second geometry). Each
/// family reports its default length strategy:
///
/// ```ignore
/// impl DefaultLength<CartesianFamily> for CartesianFamily { type Strategy = CartesianLength; }
/// impl DefaultLength<SphericalFamily> for SphericalFamily { type Strategy = SphericalLength; }
/// impl DefaultLength<GeographicFamily> for GeographicFamily { type Strategy = GeographicLength; }
/// ```
///
/// The `Strategy: Default` bound matches Boost's expectation that
/// `services::default_strategy<...>::type` is default-constructible.
/// Cartesian family defaults to [`CartesianLength`].
///
/// Mirrors the `services::default_strategy<Geometry, cartesian_tag>`
/// specialisation in `strategies/length/cartesian.hpp`.
/// Spherical family defaults to [`SphericalLength`](crate::spherical::SphericalLength).
///
/// Mirrors the `services::default_strategy<Geometry, spherical_tag>`
/// specialisation in `strategies/length/spherical.hpp`.
/// Geographic family defaults to [`GeographicLength`](crate::geographic::GeographicLength).
///
/// Mirrors the `services::default_strategy<Geometry, geographic_tag>`
/// specialisation in `strategies/length/geographic.hpp`.
/// Type alias resolving the default length strategy for geometry `G`
/// by walking `G -> G::Point -> Cs -> Family -> DefaultLength::Strategy`.
///
/// Mirrors [`DefaultDistanceStrategy`](crate::distance::DefaultDistanceStrategy)
/// for the length algorithm; the free-function `length(g)`
/// monomorphises against this at the call site.
pub type DefaultLengthStrategy<G> =
Strategy;