Skip to main content

geometry/
lib.rs

1//! Ports `mapbox::geometry::point<T>` (mapbox/geometry/point.hpp of
2//! geometry.hpp, the C++ core's vendor/maplibre-native-base/deps/geometry.hpp),
3//! the point of tile geometry and the 2D vector of the renderer.
4//!
5//! GeoJSON and feature geometry is `geo_types`'; [`Point`] converts to and
6//! from its [`Coord`].
7
8use geo_types::{Coord, CoordNum};
9
10/// `mapbox::geometry::point<T>`
11#[derive(Clone, Copy, Debug, Default, PartialEq, mln_wire::Wire)]
12pub struct Point<T> {
13    pub x: T,
14    pub y: T,
15}
16
17impl<T> Point<T> {
18    pub const fn new(x: T, y: T) -> Self {
19        Point { x, y }
20    }
21}
22
23impl<T: CoordNum> From<Coord<T>> for Point<T> {
24    fn from(c: Coord<T>) -> Self {
25        Point { x: c.x, y: c.y }
26    }
27}
28
29impl<T: CoordNum> From<Point<T>> for Coord<T> {
30    fn from(p: Point<T>) -> Self {
31        Coord { x: p.x, y: p.y }
32    }
33}