Struct Coordinate

Source
pub struct Coordinate(pub f64, pub f64);
Expand description

This structure conceptually represents a point or a vector on the 2-dimensional Cartesian plane.

It may be vary on the context which represents which.

Tuple Fields§

§0: f64

x-component of the Cartesian coordinates.

§1: f64

y-component of the Cartesian coordinates.

Implementations§

Source§

impl Coordinate

Source

pub fn new(x: f64, y: f64) -> Self

Creates and returns a Coordinate w.r.t. the given argument.

§Argument
  • x: x-component of the Coordinate.
  • y: y-component of the Coordinate.
§Example
let c1 = geo_buffer::Coordinate::new(3., 4.);
assert_eq!(c1, (3., 4.).into());
Source

pub fn get_val(&self) -> (f64, f64)

Returns a tuple wihch has values of each component.

§Example
let c1 = geo_buffer::Coordinate::new(3., 4.);
let t1 = c1.get_val();
assert_eq!(t1, (3., 4.));
Source

pub fn inner_product(&self, rhs: &Self) -> f64

Returns a value of inner product (i.e. dot product) of the Cartesian coordinates of two vectors.

§Argument
  • self: The Cartesian coordinates of the first vector, a.
  • rhs: The Cartesian coordinates of the second vector, b.
§Return

a · b

§Example
let c1 = geo_buffer::Coordinate::new(1., 2.);
let c2 = geo_buffer::Coordinate::new(3., 4.);
let ip = c1.inner_product(&c2);
assert_eq!(ip, 11.);
§Notes
  • This operation is linear.
  • This operation is commutative.
Source

pub fn outer_product(&self, rhs: &Self) -> f64

Returns a value of the magnitude of cross product of the Cartesian coordinates of two vectors.

§Argument
  • self: The Cartesian coordinates of the first vector, a.
  • rhs: The Cartesian coordinates of the second vector, b.
§Return

a × b

§Example
let c1 = geo_buffer::Coordinate::new(1., 2.);
let c2 = geo_buffer::Coordinate::new(3., 4.);
let op = c1.outer_product(&c2);
assert_eq!(op, -2.);
§Notes
  • This operation is linear.
  • This operation is not commutative. (More precisely, it is anti-commutative.)
  • The sign of cross product indicates the orientation of a and b. If a lies before b in the counter-clockwise (CCW for short) ordering, the sign of the result will be positive. If a lies after b in CCW ordering, the sign will be negative. The result will be zero if two vectors are colinear. (I.e. lay on the same line.)
Source

pub fn norm(&self) -> f64

Returns the Euclidean norm (i.e. magnitude, or L2 norm) of the given vector.

§Example
let c1 = geo_buffer::Coordinate::new(3., 4.);
assert_eq!(c1.norm(), 5.);
Source

pub fn dist_coord(&self, rhs: &Coordinate) -> f64

Returns the distance between two Cartesian coordinates.

§Example
let c1 = geo_buffer::Coordinate::new(3., 4.);
let c2 = geo_buffer::Coordinate::new(7., 7.);
assert_eq!(c1.dist_coord(&c2), 5.);
Source

pub fn dist_ray(&self, rhs: &Ray) -> f64

Returns the distance from self to the given ray.

Note that this function considers the given ray as a open-ended line. That is, the foot of perpendicular may lay on the extended line of the given ray.

§Example
use geo_buffer::{Coordinate, Ray};
 
let r1 = Ray::new((0., 3.).into(), (4., 0.).into());
let c1 = Coordinate::new(0., 0.);
assert_eq!(c1.dist_ray(&r1), 2.4);
Source

pub fn eq(&self, rhs: &Self) -> bool

Checks whether the given two Cartesian coordinates are the same (by the equality test with a small epsilon).

§Result
  • true if the given coordinates are the same.
  • false otherwise.
§Example
let c1 = geo_buffer::Coordinate::new(0.1, 0.2);
let c2 = geo_buffer::Coordinate::new(0.2, 0.3);
let c3 = geo_buffer::Coordinate::new(0.3, 0.5);
let c4 = c1 + c2;
assert!(c3.eq(&c4));
§Example (this example panics)
let c1 = geo_buffer::Coordinate::new(0.1, 0.2);
let c2 = geo_buffer::Coordinate::new(0.2, 0.3);
let c3 = geo_buffer::Coordinate::new(0.3, 0.5);
let c4 = c1 + c2;
assert_eq!(c3, c4); // should panic since 0.1 + 0.2 != 0.3 due to floating point errors

Trait Implementations§

Source§

impl Add for Coordinate

Source§

type Output = Coordinate

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for Coordinate

Source§

fn clone(&self) -> Coordinate

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Coordinate

Source§

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

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

impl Default for Coordinate

Source§

fn default() -> Coordinate

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

impl Div<f64> for Coordinate

Source§

type Output = Coordinate

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Coordinate

Source§

type Output = f64

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl From<(f64, f64)> for Coordinate

Source§

fn from(item: (f64, f64)) -> Coordinate

Converts to this type from the input type.
Source§

impl From<Coord> for Coordinate

Source§

fn from(value: Coord<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Coordinate> for (f64, f64)

Source§

fn from(item: Coordinate) -> (f64, f64)

Converts to this type from the input type.
Source§

impl From<Coordinate> for Coord<f64>

Source§

fn from(value: Coordinate) -> Coord<f64>

Converts to this type from the input type.
Source§

impl Mul<f64> for Coordinate

Source§

type Output = Coordinate

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for Coordinate

Source§

fn eq(&self, other: &Coordinate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Coordinate

Source§

fn partial_cmp(&self, other: &Coordinate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Coordinate

Source§

type Output = Coordinate

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl Copy for Coordinate

Source§

impl StructuralPartialEq for Coordinate

Auto Trait Implementations§

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> 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.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool