geometry_adapt/adapt_array.rs
1//! [`Point`] impl for `Adapt<[T; N]>`.
2//!
3//! Mirrors `boost/geometry/geometries/adapted/c_array.hpp` (raw C
4//! arrays) and `boost/geometry/geometries/adapted/std_array.hpp`
5//! (`std::array<T, N>`) collapsed into one impl — Rust's `[T; N]`
6//! covers both shapes.
7//!
8//! # Silent-Cartesian warning
9//!
10//! This impl pins `type Cs = Cartesian`. A raw `Adapt::<[f64; 2]>(
11//! [lon, lat])` therefore satisfies *every* Cartesian-only strategy
12//! bound and will silently compute Pythagorean nonsense over
13//! lat/lon. Wrap geographic / spherical arrays with
14//! [`WithCs`](crate::WithCs) — see [`Adapt`](crate::Adapt)'s
15//! rustdoc for the worked example.
16
17use geometry_coords::CoordinateScalar;
18use geometry_cs::Cartesian;
19use geometry_tag::PointTag;
20use geometry_trait::{Geometry, Point, PointMut};
21
22use crate::Adapt;
23
24impl<T: CoordinateScalar, const N: usize> Geometry for Adapt<[T; N]> {
25 type Kind = PointTag;
26 type Point = Self;
27}
28
29impl<T: CoordinateScalar, const N: usize> Point for Adapt<[T; N]> {
30 type Scalar = T;
31 type Cs = Cartesian;
32 const DIM: usize = N;
33
34 #[inline]
35 fn get<const D: usize>(&self) -> T {
36 self.0[D]
37 }
38}
39
40impl<T: CoordinateScalar, const N: usize> PointMut for Adapt<[T; N]> {
41 #[inline]
42 fn set<const D: usize>(&mut self, value: T) {
43 self.0[D] = value;
44 }
45}