Skip to main content

Point

Trait Point 

Source
pub trait Point: Geometry<Kind = PointTag, Point = Self> + Sized {
    type Scalar: CoordinateScalar;
    type Cs: CoordinateSystem;

    const DIM: usize;

    // Required method
    fn get<const D: usize>(&self) -> Self::Scalar;
}
Expand description

The Point concept.

Models doc/concept/point.qbk — equivalent in C++ to the five trait specialisations spelled out in boost/geometry/geometries/concepts/point_concept.hpp and the per-dimension accessor declared in boost/geometry/core/access.hpp:270-313. The five C++ pieces collapse here to four associated items plus the super-bound:

C++ traitRust counterpart
traits::tag<P> (core/tag.hpp)Geometry<Kind = PointTag>
traits::dimension<P> (core/coordinate_dimension.hpp)const DIM: usize
traits::coordinate_type<P> (core/coordinate_type.hpp)type Scalar
traits::coordinate_system<P> (core/coordinate_system.hpp)type Cs
traits::access<P, D>::get (core/access.hpp:270-313)fn get::<D>

The read-write half — traits::access<P, D>::set — lives on the PointMut subtrait, mirroring the way Boost’s mutating Point concept sits above the read-only ConstPoint.

The Point = Self projection on the Geometry super-trait is the Rust spelling of Boost’s “a Point is its own point type” invariant — point_type<P>::type = P whenever tag<P>::type = point_tag.

§Examples

use geometry_cs::Cartesian;
use geometry_tag::PointTag;
use geometry_trait::{Geometry, Point};

#[derive(Default)]
struct Xy { x: f64, y: f64 }

impl Geometry for Xy { type Kind = PointTag; type Point = Self; }

impl Point for Xy {
    type Scalar = f64;
    type Cs = Cartesian;
    const DIM: usize = 2;
    fn get<const D: usize>(&self) -> f64 { if D == 0 { self.x } else { self.y } }
}

let p = Xy { x: 3.0, y: 4.0 };
assert_eq!(p.get::<0>(), 3.0);

Required Associated Constants§

Source

const DIM: usize

The number of dimensions.

Mirrors boost::geometry::traits::dimension<P>::value (boost/geometry/core/coordinate_dimension.hpp).

Required Associated Types§

Source

type Scalar: CoordinateScalar

The scalar coordinate type.

Mirrors boost::geometry::traits::coordinate_type<P>::type (boost/geometry/core/coordinate_type.hpp).

Source

type Cs: CoordinateSystem

The coordinate system this point lives in.

Mirrors boost::geometry::traits::coordinate_system<P>::type (boost/geometry/core/coordinate_system.hpp).

Required Methods§

Source

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

Read coordinate D.

Mirrors boost::geometry::traits::access<P, D>::get(p) (boost/geometry/core/access.hpp:270-313). D is a const generic: passing an out-of-range index is rejected at the call site rather than at runtime.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§