* XatY and YatX functions for a line 4.x-dev

Sun, 11 Jul 2021 10:14:45 +0300

author
cemkalyoncu
date
Sun, 11 Jul 2021 10:14:45 +0300
branch
4.x-dev
changeset 1709
8c097aad12ae
parent 1708
5024ed6400e1
child 1711
847f51ca989f

* XatY and YatX functions for a line

Source/Gorgon/Geometry/Line.h file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Geometry/Line.h	Sat Jul 10 16:12:35 2021 +0300
+++ b/Source/Gorgon/Geometry/Line.h	Sun Jul 11 10:14:45 2021 +0300
@@ -82,7 +82,21 @@
         P_ PointAtMaxX() const {
             return Start.X > End.X ? Start : End;
         }
-        
+
+        ///Returns the X value at a given Y coordinate. This function does
+        ///not check if Y is in range and may give invalid values if it
+        ///doesn't.
+        typename P_::BaseType XatY(typename P_::BaseType y) const {
+            return (y - Start.Y) * SlopeInv() + Start.X;
+        }
+
+        ///Returns the Y value at a given X coordinate. This function does
+        ///not check if X is in range and may give invalid values if it
+        ///doesn't.
+        typename P_::BaseType YatX(typename P_::BaseType x) const {
+            return (x - Start.X) * Slope() + Start.Y;
+        }
+
         ///Returns whether the line is moving up or down. Up movement is -1
         ///down movement is 1 and if line is horizontal this function will
         ///return 0

mercurial