@@ -20,6 +20,8 @@ namespace viewshed
2020
2121// / Normalize a masking angle. Change from clockwise with 0 north (up) to counterclockwise
2222// / with 0 to the east (right) and change to radians.
23+ // /
24+ // @param maskAngle Masking angle in degrees.
2325double normalizeAngle (double maskAngle)
2426{
2527 maskAngle = 90 - maskAngle;
@@ -30,7 +32,12 @@ double normalizeAngle(double maskAngle)
3032
3133// / Compute the X intersect position on the line Y = y with a ray extending
3234// / from (nX, nY) along `angle`.
33- // /ABELL doc args
35+ // /
36+ // / @param angle Angle in radians, standard arrangement.
37+ // / @param nX X coordinate of ray endpoint.
38+ // / @param nY Y coordinte of ray endpoint.
39+ // / @param y Horizontal line where Y = y.
40+ // / @return X intersect or NaN
3441double horizontalIntersect (double angle, int nX, int nY, int y)
3542{
3643 double x = std::numeric_limits<double >::quiet_NaN ();
@@ -54,6 +61,14 @@ double horizontalIntersect(double angle, int nX, int nY, int y)
5461 return x;
5562}
5663
64+ // / Compute the X intersect position on the line Y = y with a ray extending
65+ // / from (nX, nY) along `angle`.
66+ // /
67+ // / @param angle Angle in radians, standard arrangement.
68+ // / @param nX X coordinate of ray endpoint.
69+ // / @param nY Y coordinte of ray endpoint.
70+ // / @param y Horizontal line where Y = y.
71+ // / @return Rounded X intersection of the sentinel INVALID_ISECT
5772int hIntersect (double angle, int nX, int nY, int y)
5873{
5974 double x = horizontalIntersect (angle, nX, nY, y);
@@ -62,6 +77,14 @@ int hIntersect(double angle, int nX, int nY, int y)
6277 return static_cast <int >(std::round (x));
6378}
6479
80+ // / Compute the X intersect on one of the horizontal edges of a window
81+ // / with a ray extending from (nX, nY) along `angle`, clamped the the extent of a window.
82+ // /
83+ // / @param angle Angle in radians, standard arrangement.
84+ // / @param nX X coordinate of ray endpoint.
85+ // / @param nY Y coordinte of ray endpoint.
86+ // / @param win Window to intersect.
87+ // / @return X intersect, clamped to the window extent.
6588int hIntersect (double angle, int nX, int nY, const Window &win)
6689{
6790 if (ARE_REAL_EQUAL (angle, M_PI))
@@ -74,9 +97,14 @@ int hIntersect(double angle, int nX, int nY, const Window &win)
7497 return std::clamp (static_cast <int >(std::round (x)), win.xStart , win.xStop );
7598}
7699
77- // / Compute the Y intersect position on the line X = x with a ray extending
100+ // / Compute the X intersect position on the line Y = y with a ray extending
78101// / from (nX, nY) along `angle`.
79- // /ABELL doc args
102+ // /
103+ // / @param angle Angle in radians, standard arrangement.
104+ // / @param nX X coordinate of ray endpoint.
105+ // / @param nY Y coordinte of ray endpoint.
106+ // / @param y Vertical line where X = x.
107+ // / @return Y intersect or NaN
80108double verticalIntersect (double angle, int nX, int nY, int x)
81109{
82110 double y = std::numeric_limits<double >::quiet_NaN ();
@@ -100,6 +128,14 @@ double verticalIntersect(double angle, int nX, int nY, int x)
100128 return y;
101129}
102130
131+ // / Compute the X intersect position on the line Y = y with a ray extending
132+ // / from (nX, nY) along `angle`.
133+ // /
134+ // / @param angle Angle in radians, standard arrangement.
135+ // / @param nX X coordinate of ray endpoint.
136+ // / @param nY Y coordinte of ray endpoint.
137+ // / @param y Horizontal line where X = x.
138+ // / @return Rounded Y intersection of the sentinel INVALID_ISECT
103139int vIntersect (double angle, int nX, int nY, int x)
104140{
105141 double y = verticalIntersect (angle, nX, nY, x);
@@ -108,6 +144,15 @@ int vIntersect(double angle, int nX, int nY, int x)
108144 return static_cast <int >(std::round (y));
109145}
110146
147+ // / Compute the Y intersect on one of the vertical edges of a window
148+ // / with a ray extending from (nX, nY) along `angle`, clamped the the extent
149+ // / of the window.
150+ // /
151+ // / @param angle Angle in radians, standard arrangement.
152+ // / @param nX X coordinate of ray endpoint.
153+ // / @param nY Y coordinte of ray endpoint.
154+ // / @param win Window to intersect.
155+ // / @return y intersect, clamped to the window extent.
111156int vIntersect (double angle, int nX, int nY, const Window &win)
112157{
113158 if (ARE_REAL_EQUAL (angle, M_PI / 2 ))
@@ -120,8 +165,12 @@ int vIntersect(double angle, int nX, int nY, const Window &win)
120165 return std::clamp (static_cast <int >(std::round (y)), win.yStart , win.yStop );
121166}
122167
123- // Determine if ray is in the slice between two rays starting at `start` and
124- // going clockwise to `end` (inclusive). [start, end]
168+ // / Determine if ray is in the slice between two rays starting at `start` and
169+ // / going clockwise to `end` (inclusive). [start, end]
170+ // / @param start Start angle.
171+ // / @param end End angle.
172+ // / @param test Test angle.
173+ // / @return Whether `test` lies in the slice [start, end]
125174bool rayBetween (double start, double end, double test)
126175{
127176 // Our angles go counterclockwise, so swap start and end
0 commit comments