rstar

Trait Point

Source
pub trait Point:
    Clone
    + PartialEq
    + Debug {
    type Scalar: RTreeNum;

    const DIMENSIONS: usize;

    // Required methods
    fn generate(generator: impl FnMut(usize) -> Self::Scalar) -> Self;
    fn nth(&self, index: usize) -> Self::Scalar;
    fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar;
}
Expand description

Defines a point type that is compatible with rstar.

This trait should be used for interoperability with other point types, not to define custom objects that can be inserted into r-trees. Use crate::RTreeObject or crate::primitives::GeomWithData instead. This trait defines points, not points with metadata.

Point is implemented out of the box for arrays like [f32; 2] or [f64; 7] (for any number of dimensions), and for tuples like (int, int) and (f64, f64, f64) so tuples with only elements of the same type (up to dimension 9).

§Implementation example

Supporting a custom point type might look like this:

use rstar::Point;

#[derive(Copy, Clone, PartialEq, Debug)]
struct IntegerPoint
{
    x: i32,
    y: i32
}

impl Point for IntegerPoint
{
  type Scalar = i32;
  const DIMENSIONS: usize = 2;

  fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self
  {
    IntegerPoint {
      x: generator(0),
      y: generator(1)
    }
  }

  fn nth(&self, index: usize) -> Self::Scalar
  {
    match index {
      0 => self.x,
      1 => self.y,
      _ => unreachable!()
    }
  }

  fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar
  {
    match index {
      0 => &mut self.x,
      1 => &mut self.y,
      _ => unreachable!()
    }
  }
}

Required Associated Constants§

Source

const DIMENSIONS: usize

The number of dimensions of this point type.

Required Associated Types§

Source

type Scalar: RTreeNum

The number type used by this point type.

Required Methods§

Source

fn generate(generator: impl FnMut(usize) -> Self::Scalar) -> Self

Creates a new point value with given values for each dimension.

The value that each dimension should be initialized with is given by the parameter generator. Calling generator(n) returns the value of dimension n, n will be in the range 0 .. Self::DIMENSIONS, and will be called with values of n in ascending order.

Source

fn nth(&self, index: usize) -> Self::Scalar

Returns a single coordinate of this point.

Returns the coordinate indicated by index. index is always smaller than Self::DIMENSIONS.

Source

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Mutable variant of nth.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<S> Point for (S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 2usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 3usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 4usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 5usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 6usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 7usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S, S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 8usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S, S, S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 9usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S, S, S, S, S, S, S, S, S, S)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 10usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S> Point for (S,)
where S: RTreeNum,

Source§

const DIMENSIONS: usize = 1usize

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Source§

impl<S, const N: usize> Point for [S; N]
where S: RTreeNum,

Source§

const DIMENSIONS: usize = N

Source§

type Scalar = S

Source§

fn generate(generator: impl FnMut(usize) -> S) -> Self

Source§

fn nth(&self, index: usize) -> Self::Scalar

Source§

fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar

Implementors§