Skip to main content

Adapt

Struct Adapt 

Source
#[repr(transparent)]
pub struct Adapt<T>(pub T);
Expand description

Shape-only adapter wrapper.

#[repr(transparent)] so &Adapt<T> is layout-compatible with &T — no boxing, no allocation, the wrapper is purely a place to hang trait impls that coherence wouldn’t allow on T directly.

Defaults to Cs = Cartesian for every shape this crate adapts. Compose with WithCs<T, Cs> to re-tag with a different coordinate system.

Mirrors boost/geometry/geometries/adapted/{c_array, std_array, boost_tuple}.hpp collectively.

§Coordinate system default — silent-Cartesian warning

Adapt<T> defaults to Cartesian. This matters for adapted containers like [lat, lon] arrays or (lat, lon) tuples — by default the library will compute Cartesian Pythagorean distances over them, not great-circle distances. If your coordinates are spherical or geographic, wrap them with WithCs:

use geometry_adapt::{Adapt, WithCs};
use geometry_cs::{Degree, Geographic};

// WRONG — treats lon/lat as Cartesian, returns nonsense for distance.
let p = Adapt([4.9_f64, 52.4]);

// RIGHT — the Cs is in the type; distance() picks the right strategy
// (haversine / andoyer / vincenty) and Pythagoras refuses to compile.
let p = WithCs::<_, Geographic<Degree>>::new(Adapt([4.9_f64, 52.4]));

The matching compile-time diagnostic that catches a bare Adapt<[lat, lon]> from reaching Pythagoras lives on SameAs — see proposal §3.7 and §8 for the rationale and the mitigations.

§Borrowed arrays — read only

Adapt<&[T; N]> works just like Adapt<[T; N]> for the read-only algorithm surface (distance, length, area, …), without copying the storage. The borrow does not implement PointMut, so any algorithm that needs to output a Point (e.g. envelope) is a compile error — own your array if you need mutation.

use geometry_adapt::Adapt;
use geometry_algorithm::distance;

let a_storage = [0.0_f64, 0.0];
let b_storage = [3.0_f64, 4.0];
assert_eq!(distance(&Adapt(&a_storage), &Adapt(&b_storage)), 5.0);

Tuple Fields§

§0: T

Implementations§

Source§

impl<T> Adapt<T>

Source

pub const fn new(value: T) -> Self

Wrap a foreign value so the geometry concepts apply to it.

Source

pub fn into_inner(self) -> T

Unwrap, returning the foreign value.

Trait Implementations§

Source§

impl<T: Clone> Clone for Adapt<T>

Source§

fn clone(&self) -> Adapt<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for Adapt<T>

Source§

impl<T: Debug> Debug for Adapt<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for Adapt<T>

Source§

fn default() -> Adapt<T>

Returns the “default value” for a type. Read more
Source§

impl<T: Eq> Eq for Adapt<T>

Source§

impl<T: CoordinateScalar, const N: usize> Geometry for Adapt<[T; N]>

Source§

type Kind = PointTag

One of the *Tag types from geometry_tag. Read more
Source§

type Point = Adapt<[T; N]>

The point type this geometry is built from. For a value modelling Point, this is Self. Read more
Source§

impl<T: CoordinateScalar, const N: usize> Geometry for Adapt<&[T; N]>

Source§

type Kind = PointTag

One of the *Tag types from geometry_tag. Read more
Source§

type Point = Adapt<&[T; N]>

The point type this geometry is built from. For a value modelling Point, this is Self. Read more
Source§

impl<T: CoordinateScalar> Geometry for Adapt<(T, T)>

Source§

type Kind = PointTag

One of the *Tag types from geometry_tag. Read more
Source§

type Point = Adapt<(T, T)>

The point type this geometry is built from. For a value modelling Point, this is Self. Read more
Source§

impl<T: CoordinateScalar> Geometry for Adapt<(T, T, T)>

Source§

type Kind = PointTag

One of the *Tag types from geometry_tag. Read more
Source§

type Point = Adapt<(T, T, T)>

The point type this geometry is built from. For a value modelling Point, this is Self. Read more
Source§

impl<T: Hash> Hash for Adapt<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Adapt<T>

Source§

fn eq(&self, other: &Adapt<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: CoordinateScalar, const N: usize> Point for Adapt<[T; N]>

Source§

const DIM: usize = N

The number of dimensions. Read more
Source§

type Scalar = T

The scalar coordinate type. Read more
Source§

type Cs = Cartesian

The coordinate system this point lives in. Read more
Source§

fn get<const D: usize>(&self) -> T

Read coordinate D. Read more
Source§

impl<T: CoordinateScalar, const N: usize> Point for Adapt<&[T; N]>

Source§

const DIM: usize = N

The number of dimensions. Read more
Source§

type Scalar = T

The scalar coordinate type. Read more
Source§

type Cs = Cartesian

The coordinate system this point lives in. Read more
Source§

fn get<const D: usize>(&self) -> T

Read coordinate D. Read more
Source§

impl<T: CoordinateScalar> Point for Adapt<(T, T)>

Source§

const DIM: usize = 2

The number of dimensions. Read more
Source§

type Scalar = T

The scalar coordinate type. Read more
Source§

type Cs = Cartesian

The coordinate system this point lives in. Read more
Source§

fn get<const D: usize>(&self) -> T

Read coordinate D. Read more
Source§

impl<T: CoordinateScalar> Point for Adapt<(T, T, T)>

Source§

const DIM: usize = 3

The number of dimensions. Read more
Source§

type Scalar = T

The scalar coordinate type. Read more
Source§

type Cs = Cartesian

The coordinate system this point lives in. Read more
Source§

fn get<const D: usize>(&self) -> T

Read coordinate D. Read more
Source§

impl<T: CoordinateScalar, const N: usize> PointMut for Adapt<[T; N]>

Source§

fn set<const D: usize>(&mut self, value: T)

Write coordinate D. Read more
Source§

impl<T: CoordinateScalar> PointMut for Adapt<(T, T)>

Source§

fn set<const D: usize>(&mut self, value: T)

Write coordinate D. Read more
Source§

impl<T: CoordinateScalar> PointMut for Adapt<(T, T, T)>

Source§

fn set<const D: usize>(&mut self, value: T)

Write coordinate D. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Adapt<T>

Auto Trait Implementations§

§

impl<T> Freeze for Adapt<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Adapt<T>
where T: RefUnwindSafe,

§

impl<T> Send for Adapt<T>
where T: Send,

§

impl<T> Sync for Adapt<T>
where T: Sync,

§

impl<T> Unpin for Adapt<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Adapt<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Adapt<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SameAs<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.