shape_core/elements/points/point_2d/
mod.rs1use super::*;
2mod arthmetic;
3mod constructors;
4mod euclidean;
5mod manhattan;
6
7#[cfg_attr(feature = "serde", repr(C), derive(Serialize, Deserialize))]
9#[derive(Copy, Clone, PartialEq, Eq, Hash)]
10pub struct Point<T> {
11 pub x: T,
13 pub y: T,
15}
16
17impl<T> Point<T> {
18 pub fn ref_inner(&self) -> Point<&T> {
19 Point { x: &self.x, y: &self.y }
20 }
21}
22
23impl<T> Point<T>
24where
25 T: Num + Clone,
26{
27 pub fn norm(&self) -> T
28 where
29 T: Float,
30 {
31 (self.x.clone() * self.x.clone() + self.y.clone() * self.y.clone()).sqrt()
32 }
33
34 pub fn cross_dot(&self, a: &Self, b: &Self) -> T {
38 let p = (b.x.clone() - a.x.clone()) * (self.y.clone() - b.y.clone());
39 let q = (b.y.clone() - a.y.clone()) * (self.x.clone() - b.x.clone());
40 p - q
41 }
42}