Struct geo::Point [−][src]
pub struct Point<T>(pub Coordinate<T>)
where
T: CoordNum;
Expand description
A single point in 2D space.
Points can be created using the Point::new
constructor,
the point!
macro, or from a Coordinate
, two-element
tuples, or arrays – see the From
impl section for a
complete list.
Semantics
The interior of the point is itself (a singleton set),
and its boundary is empty. A point is valid if and
only if the Coordinate
is valid.
Examples
use geo_types::{Coordinate, Point};
let p1: Point<f64> = (0., 1.).into();
let c = Coordinate { x: 10., y: 20. };
let p2: Point<f64> = c.into();
Tuple Fields
0: Coordinate<T>
Implementations
Creates a new point.
Examples
use geo_types::Point;
let p = Point::new(1.234, 2.345);
assert_eq!(p.x(), 1.234);
assert_eq!(p.y(), 2.345);
Returns the x/horizontal component of the point.
Examples
use geo_types::Point;
let p = Point::new(1.234, 2.345);
assert_eq!(p.x(), 1.234);
Sets the x/horizontal component of the point.
Examples
use geo_types::Point;
let mut p = Point::new(1.234, 2.345);
p.set_x(9.876);
assert_eq!(p.x(), 9.876);
Returns the y/vertical component of the point.
Examples
use geo_types::Point;
let p = Point::new(1.234, 2.345);
assert_eq!(p.y(), 2.345);
Sets the y/vertical component of the point.
Examples
use geo_types::Point;
let mut p = Point::new(1.234, 2.345);
p.set_y(9.876);
assert_eq!(p.y(), 9.876);
Returns a tuple that contains the x/horizontal & y/vertical component of the point.
Examples
use geo_types::Point;
let mut p = Point::new(1.234, 2.345);
let (x, y) = p.x_y();
assert_eq!(y, 2.345);
assert_eq!(x, 1.234);
Returns the longitude/horizontal component of the point.
Examples
use geo_types::Point;
let p = Point::new(1.234, 2.345);
assert_eq!(p.lng(), 1.234);
Sets the longitude/horizontal component of the point.
Examples
use geo_types::Point;
let mut p = Point::new(1.234, 2.345);
p.set_lng(9.876);
assert_eq!(p.lng(), 9.876);
Returns the latitude/vertical component of the point.
Examples
use geo_types::Point;
let p = Point::new(1.234, 2.345);
assert_eq!(p.lat(), 2.345);
Returns the dot product of the two points:
dot = x1 * x2 + y1 * y2
Examples
use geo_types::{Coordinate, Point};
let point = Point(Coordinate { x: 1.5, y: 0.5 });
let dot = point.dot(Point(Coordinate { x: 2.0, y: 4.5 }));
assert_eq!(dot, 5.25);
Returns the cross product of 3 points. A positive value implies
self
→ point_b
→ point_c
is counter-clockwise, negative implies
clockwise.
Examples
use geo_types::{Coordinate, Point};
let point_a = Point(Coordinate { x: 1., y: 2. });
let point_b = Point(Coordinate { x: 3., y: 5. });
let point_c = Point(Coordinate { x: 7., y: 12. });
let cross = point_a.cross_prod(point_b, point_c);
assert_eq!(cross, 2.0)
Converts the (x,y) components of Point to degrees
Example
use geo_types::Point;
let p = Point::new(1.234, 2.345);
let (x, y): (f32, f32) = p.to_degrees().x_y();
assert_eq!(x.round(), 71.0);
assert_eq!(y.round(), 134.0);
Converts the (x,y) components of Point to radians
Example
use geo_types::Point;
let p = Point::new(180.0, 341.5);
let (x, y): (f32, f32) = p.to_radians().x_y();
assert_eq!(x.round(), 3.0);
assert_eq!(y.round(), 6.0);
Trait Implementations
Equality assertion with an absolute limit.
Examples
use geo_types::Point;
let a = Point::new(2.0, 3.0);
let b = Point::new(2.0, 3.0000001);
approx::assert_relative_eq!(a, b, epsilon=0.1)
The default tolerance to use when testing values that are close together. Read more
The inverse of AbsDiffEq::abs_diff_eq
.
Return the bounding rectangle for a Point
. It will have zero width
and zero height.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
Find the closest point between self
and p
.
type Scalar = T
fn calculate_coordinate_position(
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
_boundary_count: &mut usize
)
Return the number of coordinates in the Point
.
type Iter = Once<Coordinate<T>>
type ExteriorIter = Self::Iter
type Scalar = T
Iterate over all exterior and (if any) interior coordinates of a geometry. Read more
Iterate over all exterior coordinates of a geometry. Read more
Minimum distance from a Line to a Point
Minimum distance from a Point to a LineString
Minimum distance from a Point to a MultiLineString
Minimum distance from a Point to a MultiPoint
Minimum distance from a Point to a MultiPolygon
Minimum distance between two Points
Minimum distance from a MultiPoint to a Point
Minimum distance from a Line to a Point
Minimum distance from a LineString to a Point
Minimum distance from a MultiLineString to a Point
Minimum distance from a Polygon to a Point
Minimum distance from a MultiPolygon to a Point
Returns the distance between two geometries Read more
Minimum distance from a Point to a Polygon
Performs the conversion.
Performs the conversion.
Returns a new Point along a route between two existing points on an ellipsoidal model of the earth Read more
Some geometries, like a MultiPoint
, can have zero coordinates - we call these empty
. Read more
The dimensions of some geometries are fixed, e.g. a Point always has 0 dimensions. However
for others, the dimensionality depends on the specific geometry instance - for example
typical Rect
s are 2-dimensional, but it’s possible to create degenerate Rect
s which
have either 1 or 0 dimensions. Read more
The dimensions of the Geometry
’s boundary, as used by OGC-SFA. Read more
Returns a new Point using distance to the existing Point and a bearing for the direction Read more
Determine the distance between two geometries using the haversine formula. Read more
impl<T> Intersects<MultiPolygon<T>> for Point<T> where
MultiPolygon<T>: Intersects<Point<T>>,
T: CoordNum,
impl<T> Intersects<MultiPolygon<T>> for Point<T> where
MultiPolygon<T>: Intersects<Point<T>>,
T: CoordNum,
impl<T> Intersects<Point<T>> for Polygon<T> where
Point<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<Point<T>> for Polygon<T> where
Point<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> LineLocatePoint<T, Point<T>> for LineString<T> where
T: CoordFloat + AddAssign,
Line<T>: EuclideanDistance<T, Point<T>> + EuclideanLength<T>,
LineString<T>: EuclideanLength<T>,
impl<T> LineLocatePoint<T, Point<T>> for LineString<T> where
T: CoordFloat + AddAssign,
Line<T>: EuclideanDistance<T, Point<T>> + EuclideanLength<T>,
LineString<T>: EuclideanLength<T>,
impl<T> RelativeEq<Point<T>> for Point<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
impl<T> RelativeEq<Point<T>> for Point<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
Equality assertion within a relative limit.
Examples
use geo_types::Point;
let a = Point::new(2.0, 3.0);
let b = Point::new(2.0, 3.01);
approx::assert_relative_eq!(a, b, max_relative=0.1)
The default relative tolerance for testing values that are far-apart. Read more
The inverse of RelativeEq::relative_eq
.
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
Determine the distance between two geometries using Vincenty’s formulae. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Point<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Point<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Returns the squared euclidean distance of an object to a point.
pub fn contains_point(
&self,
point: &<<P as RTreeObject>::Envelope as Envelope>::Point
) -> bool
pub fn contains_point(
&self,
point: &<<P as RTreeObject>::Envelope as Envelope>::Point
) -> bool
Returns true if a point is contained within this object. Read more
pub fn distance_2_if_less_or_equal(
&self,
point: &<<P as RTreeObject>::Envelope as Envelope>::Point,
max_distance_2: <<<P as RTreeObject>::Envelope as Envelope>::Point as Point>::Scalar
) -> Option<<P as Point>::Scalar>
pub fn distance_2_if_less_or_equal(
&self,
point: &<<P as RTreeObject>::Envelope as Envelope>::Point,
max_distance_2: <<<P as RTreeObject>::Envelope as Envelope>::Point as Point>::Scalar
) -> Option<<P as Point>::Scalar>
Returns the squared distance to this object or None
if the distance
is larger than a given maximum value. Read more
Rotate a Geometry around an arbitrary point by an angle, given in degrees Read more