equal
deleted
inserted
replaced
96 } else if iy > intersections_box.bottom() { |
96 } else if iy > intersections_box.bottom() { |
97 iy = intersections_box.bottom(); |
97 iy = intersections_box.bottom(); |
98 } |
98 } |
99 |
99 |
100 let ix = if ray.direction.y.abs() > edge_dir.y.abs() { |
100 let ix = if ray.direction.y.abs() > edge_dir.y.abs() { |
101 (iy - ray.start.y) * ray.direction.cotangent() + ray.start.x |
101 ray.start.x + ray.direction.cotangent_mul(iy - ray.start.y) |
102 } else { |
102 } else { |
103 (iy - edge.start.y) * edge_dir.cotangent() + edge.start.x |
103 edge.start.x + edge_dir.cotangent_mul(iy - edge.start.y) |
104 }; |
104 }; |
105 |
105 |
106 let intersection_point = Point::new(ix, iy).clamp(intersections_box); |
106 let intersection_point = Point::new(ix, iy).clamp(intersections_box); |
107 let diff_point = ray.start - intersection_point; |
107 let diff_point = ray.start - intersection_point; |
108 let t = ray.direction.dot(diff_point); |
108 let t = ray.direction.dot(diff_point); |
138 // find distances to map borders |
138 // find distances to map borders |
139 if normal.x != 0 { |
139 if normal.x != 0 { |
140 // where the normal line intersects the left map border |
140 // where the normal line intersects the left map border |
141 let left_intersection = Point::new( |
141 let left_intersection = Point::new( |
142 map_box.left(), |
142 map_box.left(), |
143 (map_box.left() - mid_point.x) * normal.tangent() + mid_point.y, |
143 mid_point.y + normal.tangent_mul(map_box.left() - mid_point.x), |
144 ); |
144 ); |
145 dist_left = (mid_point - left_intersection).integral_norm(); |
145 dist_left = (mid_point - left_intersection).integral_norm(); |
146 |
146 |
147 // same for the right border |
147 // same for the right border |
148 let right_intersection = Point::new( |
148 let right_intersection = Point::new( |
149 map_box.right(), |
149 map_box.right(), |
150 (map_box.right() - mid_point.x) * normal.tangent() + mid_point.y, |
150 mid_point.y + normal.tangent_mul(map_box.right() - mid_point.x) , |
151 ); |
151 ); |
152 dist_right = (mid_point - right_intersection).integral_norm(); |
152 dist_right = (mid_point - right_intersection).integral_norm(); |
153 |
153 |
154 if normal.x > 0 { |
154 if normal.x > 0 { |
155 std::mem::swap(&mut dist_left, &mut dist_right); |
155 std::mem::swap(&mut dist_left, &mut dist_right); |
157 } |
157 } |
158 |
158 |
159 if normal.y != 0 { |
159 if normal.y != 0 { |
160 // where the normal line intersects the top map border |
160 // where the normal line intersects the top map border |
161 let top_intersection = Point::new( |
161 let top_intersection = Point::new( |
162 (map_box.top() - mid_point.y) * normal.cotangent() + mid_point.x, |
162 mid_point.x + normal.cotangent_mul(map_box.top() - mid_point.y), |
163 map_box.top(), |
163 map_box.top(), |
164 ); |
164 ); |
165 let dl = (mid_point - top_intersection).integral_norm(); |
165 let dl = (mid_point - top_intersection).integral_norm(); |
166 |
166 |
167 // same for the bottom border |
167 // same for the bottom border |
168 let bottom_intersection = Point::new( |
168 let bottom_intersection = Point::new( |
169 (map_box.bottom() - mid_point.y) * normal.cotangent() + mid_point.x, |
169 mid_point.x + normal.cotangent_mul(map_box.bottom() - mid_point.y), |
170 map_box.bottom(), |
170 map_box.bottom(), |
171 ); |
171 ); |
172 let dr = (mid_point - bottom_intersection).integral_norm(); |
172 let dr = (mid_point - bottom_intersection).integral_norm(); |
173 |
173 |
174 if normal.y < 0 { |
174 if normal.y < 0 { |