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: f64x-component of the Cartesian coordinates.
1: f64y-component of the Cartesian coordinates.
Implementations§
Source§impl Coordinate
impl Coordinate
Sourcepub fn new(x: f64, y: f64) -> Self
pub fn new(x: f64, y: f64) -> Self
Creates and returns a Coordinate w.r.t. the given argument.
§Argument
x: x-component of theCoordinate.y: y-component of theCoordinate.
§Example
let c1 = geo_buf::Coordinate::new(3., 4.);
assert_eq!(c1, (3., 4.).into());Sourcepub fn get_val(&self) -> (f64, f64)
pub fn get_val(&self) -> (f64, f64)
Returns a tuple wihch has values of each component.
§Example
let c1 = geo_buf::Coordinate::new(3., 4.);
let t1 = c1.get_val();
assert_eq!(t1, (3., 4.));Sourcepub fn inner_product(&self, rhs: &Self) -> f64
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_buf::Coordinate::new(1., 2.);
let c2 = geo_buf::Coordinate::new(3., 4.);
let ip = c1.inner_product(&c2);
assert_eq!(ip, 11.);§Notes
- This operation is linear.
- This operation is commutative.
Sourcepub fn outer_product(&self, rhs: &Self) -> f64
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_buf::Coordinate::new(1., 2.);
let c2 = geo_buf::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.)
Sourcepub fn norm(&self) -> f64
pub fn norm(&self) -> f64
Returns the Euclidean norm (i.e. magnitude, or L2 norm) of the given vector.
§Example
let c1 = geo_buf::Coordinate::new(3., 4.);
assert_eq!(c1.norm(), 5.);Sourcepub fn dist_coord(&self, rhs: &Coordinate) -> f64
pub fn dist_coord(&self, rhs: &Coordinate) -> f64
Returns the distance between two Cartesian coordinates.
§Example
let c1 = geo_buf::Coordinate::new(3., 4.);
let c2 = geo_buf::Coordinate::new(7., 7.);
assert_eq!(c1.dist_coord(&c2), 5.);Sourcepub fn dist_ray(&self, rhs: &Ray) -> f64
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_buf::{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);Sourcepub fn eq(&self, rhs: &Self) -> bool
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
trueif the given coordinates are the same.falseotherwise.
§Example
let c1 = geo_buf::Coordinate::new(0.1, 0.2);
let c2 = geo_buf::Coordinate::new(0.2, 0.3);
let c3 = geo_buf::Coordinate::new(0.3, 0.5);
let c4 = c1 + c2;
assert!(c3.eq(&c4));§Example (this example panics)
let c1 = geo_buf::Coordinate::new(0.1, 0.2);
let c2 = geo_buf::Coordinate::new(0.2, 0.3);
let c3 = geo_buf::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 errorsTrait Implementations§
Source§impl Add for Coordinate
impl Add for Coordinate
Source§impl Clone for Coordinate
impl Clone for Coordinate
Source§fn clone(&self) -> Coordinate
fn clone(&self) -> Coordinate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Coordinate
impl Debug for Coordinate
Source§impl Default for Coordinate
impl Default for Coordinate
Source§fn default() -> Coordinate
fn default() -> Coordinate
Source§impl Div<f64> for Coordinate
impl Div<f64> for Coordinate
Source§impl Div for Coordinate
impl Div for Coordinate
Source§impl From<Coord> for Coordinate
impl From<Coord> for Coordinate
Source§impl Mul<f64> for Coordinate
impl Mul<f64> for Coordinate
Source§impl PartialEq for Coordinate
impl PartialEq for Coordinate
Source§impl PartialOrd for Coordinate
impl PartialOrd for Coordinate
Source§impl Sub for Coordinate
impl Sub for Coordinate
impl Copy for Coordinate
impl StructuralPartialEq for Coordinate
Auto Trait Implementations§
impl Freeze for Coordinate
impl RefUnwindSafe for Coordinate
impl Send for Coordinate
impl Sync for Coordinate
impl Unpin for Coordinate
impl UnwindSafe for Coordinate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more