aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/line.rs10
-rw-r--r--src/state.rs14
2 files changed, 13 insertions, 11 deletions
diff --git a/src/line.rs b/src/line.rs
index 07a1f03..17191ce 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -1,12 +1,12 @@
use crate::point::Point;
-pub struct Line {
- p1: Point,
- p2: Point,
+pub struct Line<'a> {
+ p1: &'a Point,
+ p2: &'a Point,
}
-impl Line {
- pub fn new(p1: Point, p2: Point) -> Self {
+impl<'a> Line<'a> {
+ pub fn new(p1: &'a Point, p2: &'a Point) -> Self {
Self { p1, p2 }
}
diff --git a/src/state.rs b/src/state.rs
index 90c8147..02a3a85 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -115,17 +115,19 @@ impl State {
Ok(())
}
- fn find_poly(&self) -> Vec<Point> {
- let mut last_line = Line::new(Point::new(0.0, 0.0), Point::new(1.0, 0.0));
+ fn find_poly(&self) -> Vec<&Point> {
+ let p1 = Point::new(0.0, 0.0);
+ let p2 = Point::new(1.0, 0.0);
+ let mut last_line = Line::new(&p1, &p2);
let mut xxx = 100;
- let mut res = vec![self.points[0].clone()];
+ let mut res = vec![&self.points[0]];
loop {
let last = res.last().expect("something in res");
let mut min_theta = TAU;
let mut min_p = &self.points[0];
for p in &self.points {
if !last.equal_pos(p) {
- let l2 = Line::new(last.clone(), p.clone());
+ let l2 = Line::new(last, p);
let theta = last_line.angle_between(&l2);
if theta < min_theta {
min_theta = theta;
@@ -133,8 +135,8 @@ impl State {
}
}
}
- last_line = Line::new(res.last().expect("something in res").clone(), min_p.clone());
- res.push(min_p.clone());
+ last_line = Line::new(res.last().expect("something in res"), min_p);
+ res.push(min_p);
xxx -= 1;
if xxx == 0 || res[0].equal_pos(res.last().expect("something in res")) {