fix tangents
authoralfadur
Tue, 06 Nov 2018 16:40:54 +0300
changeset 14142 11202097584f
parent 14141 477faa7b8a48
child 14143 745c73e0e644
fix tangents
rust/integral-geometry/src/lib.rs
rust/landgen/src/outline.rs
--- a/rust/integral-geometry/src/lib.rs	Tue Nov 06 16:23:43 2018 +0300
+++ b/rust/integral-geometry/src/lib.rs	Tue Nov 06 16:40:54 2018 +0300
@@ -88,13 +88,13 @@
     }
 
     #[inline]
-    pub fn tangent(self) -> i32 {
-        self.y / self.x
+    pub fn tangent_mul(self, x: i32) -> i32 {
+        x * self.y / self.x
     }
 
     #[inline]
-    pub fn cotangent(self) -> i32 {
-        self.x / self.y
+    pub fn cotangent_mul(self, y: i32) -> i32 {
+        y * self.x / self.y
     }
 
     #[inline]
@@ -595,13 +595,13 @@
     }
 
     #[inline]
-    pub fn tangent(&self) -> i32 {
-        self.direction.tangent()
+    pub fn tangent_mul(&self, x: i32) -> i32 {
+        self.direction.tangent_mul(x)
     }
 
     #[inline]
-    pub fn cotangent(&self) -> i32 {
-        self.direction.cotangent()
+    pub fn cotangent_mul(&self, y: i32) -> i32 {
+        self.direction.cotangent_mul(y)
     }
 
     #[inline]
--- a/rust/landgen/src/outline.rs	Tue Nov 06 16:23:43 2018 +0300
+++ b/rust/landgen/src/outline.rs	Tue Nov 06 16:40:54 2018 +0300
@@ -98,9 +98,9 @@
                 }
 
                 let ix = if ray.direction.y.abs() > edge_dir.y.abs() {
-                    (iy - ray.start.y) * ray.direction.cotangent() + ray.start.x
+                    ray.start.x + ray.direction.cotangent_mul(iy - ray.start.y)
                 } else {
-                    (iy - edge.start.y) * edge_dir.cotangent() + edge.start.x
+                    edge.start.x + edge_dir.cotangent_mul(iy - edge.start.y)
                 };
 
                 let intersection_point = Point::new(ix, iy).clamp(intersections_box);
@@ -140,14 +140,14 @@
             // where the normal line intersects the left map border
             let left_intersection = Point::new(
                 map_box.left(),
-                (map_box.left() - mid_point.x) * normal.tangent() + mid_point.y,
+                mid_point.y + normal.tangent_mul(map_box.left() - mid_point.x),
             );
             dist_left = (mid_point - left_intersection).integral_norm();
 
             // same for the right border
             let right_intersection = Point::new(
                 map_box.right(),
-                (map_box.right() - mid_point.x) * normal.tangent() + mid_point.y,
+                mid_point.y + normal.tangent_mul(map_box.right() - mid_point.x)  ,
             );
             dist_right = (mid_point - right_intersection).integral_norm();
 
@@ -159,14 +159,14 @@
         if normal.y != 0 {
             // where the normal line intersects the top map border
             let top_intersection = Point::new(
-                (map_box.top() - mid_point.y) * normal.cotangent() + mid_point.x,
+                mid_point.x + normal.cotangent_mul(map_box.top() - mid_point.y),
                 map_box.top(),
             );
             let dl = (mid_point - top_intersection).integral_norm();
 
             // same for the bottom border
             let bottom_intersection = Point::new(
-                (map_box.bottom() - mid_point.y) * normal.cotangent() + mid_point.x,
+                mid_point.x + normal.cotangent_mul(map_box.bottom() - mid_point.y),
                 map_box.bottom(),
             );
             let dr = (mid_point - bottom_intersection).integral_norm();