1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// use std::fmt;
// /// A 2D point or vector.
// #[derive(Default, Clone, Debug)]
// pub struct Point {
// pub x: f32,
// pub y: f32,
// }
// impl Point {
// pub fn new(x: f32, y: f32) -> Self {
// Self { x, y }
// }
// /// Re-assign the coordinates of this point.
// pub fn set(&mut self, x: f32, y: f32) {
// self.x = x;
// self.y = y;
// }
// /// Normalize this vector, so that its new magnitude is 1.
// pub fn normalize(&mut self) {
// let m = self.magnitude();
// self.x /= m;
// self.y /= m;
// }
// /// The dot product of two vectors.
// pub fn dot(&self, x: f32, y: f32) -> f32 {
// self.x * x + self.y * y
// }
// /// Scales a vector's magnitude by a given value.
// pub fn multiply(&mut self, n: f32) {
// self.x *= n;
// self.y *= n;
// }
// /// The magnitude (length) of this vector.
// pub fn magnitude(&self) -> f32 {
// (self.x * self.x + self.y * self.y).sqrt()
// }
// /// The distance between this point and another point.
// pub fn distance_to(&self, x: f32, y: f32) -> f32 {
// self.distance_to_squared(x, y).sqrt()
// }
// /// The squared distance between this point and another point. This is a faster operation than
// /// distanceTo.
// pub fn distance_to_squared(&self, x: f32, y: f32) -> f32 {
// let dx = self.x - x;
// let dy = self.y - y;
// dx * dx + dy * dy
// }
// pub fn equals(&self, other: Point) -> bool {
// self.x == other.x && self.y == other.y
// }
// // static
// pub fn pointMake(x: f32, y: f32) -> Point2<f32> {
// Point2::new(x, y)
// }
// // static
// pub fn p(x: f32, y: f32) -> Point2<f32> {
// Point2::new(x, y)
// }
// // static
// pub fn pointZero() -> Point2<f32> {
// Point2::new(0, 0)
// }
// // static
// pub fn pointEqualToPoint(p1: Point2<f32>, p2: Point2<f32>) -> bool {
// if p1 == None || p2 == None {
// return false;
// }
// (p1.x == p2.x) && (p1.y == p2.y)
// }
// }
// impl fmt::Display for Point {
// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// write!(f, "({},{})", self.x, self.y)
// }
// }