equal
deleted
inserted
replaced
34 + Point::new( |
34 + Point::new( |
35 (rnd_a % rect.width) as i32, |
35 (rnd_a % rect.width) as i32, |
36 (rnd_b % rect.height) as i32, |
36 (rnd_b % rect.height) as i32, |
37 ) |
37 ) |
38 + play_box.top_left() |
38 + play_box.top_left() |
39 }).collect() |
39 }) |
40 }).collect(), |
40 .collect() |
|
41 }) |
|
42 .collect(), |
41 fill_points: outline_template.fill_points.clone(), |
43 fill_points: outline_template.fill_points.clone(), |
42 } |
44 } |
43 } |
45 } |
44 |
46 |
45 pub fn total_len(&self) -> usize { |
47 pub fn total_len(&self) -> usize { |
90 (iy - s.y) * f.x / f.y + s.x |
92 (iy - s.y) * f.x / f.y + s.x |
91 }; |
93 }; |
92 |
94 |
93 let intersection_point = Point::new(ix, iy); |
95 let intersection_point = Point::new(ix, iy); |
94 let diff_point = *m - intersection_point; |
96 let diff_point = *m - intersection_point; |
95 let d = diff_point.integral_norm(); |
|
96 let t = p.dot(diff_point); |
97 let t = p.dot(diff_point); |
97 |
98 if diff_point.max_norm() >= std::i16::MAX as i32 { |
98 Some((t, d)) |
99 Some((t, std::i32::MAX as u32)) |
|
100 } else { |
|
101 let d = diff_point.integral_norm(); |
|
102 |
|
103 Some((t, d)) |
|
104 } |
99 } else { |
105 } else { |
100 None |
106 None |
101 } |
107 } |
102 } |
108 } |
103 |
109 |
119 // find distances to map borders |
125 // find distances to map borders |
120 if p.x != 0 { |
126 if p.x != 0 { |
121 // where the normal line intersects the left map border |
127 // where the normal line intersects the left map border |
122 let left_intersection = Point::new( |
128 let left_intersection = Point::new( |
123 map_box.left(), |
129 map_box.left(), |
124 (map_box.left() - mid_point.x) * p.y / p.x + mid_point.y); |
130 (map_box.left() - mid_point.x) * p.y / p.x + mid_point.y, |
|
131 ); |
125 dist_left = (mid_point - left_intersection).integral_norm(); |
132 dist_left = (mid_point - left_intersection).integral_norm(); |
126 |
133 |
127 // same for the right border |
134 // same for the right border |
128 let right_intersection = Point::new( |
135 let right_intersection = Point::new( |
129 map_box.right(), |
136 map_box.right(), |
130 (map_box.right() - mid_point.x) * p.y / p.x + mid_point.y); |
137 (map_box.right() - mid_point.x) * p.y / p.x + mid_point.y, |
|
138 ); |
131 dist_right = (mid_point - right_intersection).integral_norm(); |
139 dist_right = (mid_point - right_intersection).integral_norm(); |
132 |
140 |
133 if p.x > 0 { |
141 if p.x > 0 { |
134 std::mem::swap(&mut dist_left, &mut dist_right); |
142 std::mem::swap(&mut dist_left, &mut dist_right); |
135 } |
143 } |
137 |
145 |
138 if p.y != 0 { |
146 if p.y != 0 { |
139 // where the normal line intersects the top map border |
147 // where the normal line intersects the top map border |
140 let top_intersection = Point::new( |
148 let top_intersection = Point::new( |
141 (map_box.top() - mid_point.y) * p.x / p.y + mid_point.x, |
149 (map_box.top() - mid_point.y) * p.x / p.y + mid_point.x, |
142 map_box.top()); |
150 map_box.top(), |
|
151 ); |
143 let dl = (mid_point - top_intersection).integral_norm(); |
152 let dl = (mid_point - top_intersection).integral_norm(); |
144 |
153 |
145 // same for the bottom border |
154 // same for the bottom border |
146 let bottom_intersection = Point::new( |
155 let bottom_intersection = Point::new( |
147 (map_box.bottom() - mid_point.y) * p.x / p.y + mid_point.x, |
156 (map_box.bottom() - mid_point.y) * p.x / p.y + mid_point.x, |
148 map_box.bottom()); |
157 map_box.bottom(), |
|
158 ); |
149 let dr = (mid_point - bottom_intersection).integral_norm(); |
159 let dr = (mid_point - bottom_intersection).integral_norm(); |
150 |
160 |
151 if p.y < 0 { |
161 if p.y < 0 { |
152 dist_left = min(dist_left, dl); |
162 dist_left = min(dist_left, dl); |
153 dist_right = min(dist_right, dr); |
163 dist_right = min(dist_right, dr); |