Skip to content

Commit 1230200

Browse files
committed
Checkpoint.
1 parent 7cd865f commit 1230200

File tree

3 files changed

+51
-36
lines changed

3 files changed

+51
-36
lines changed

alg/viewshed/util.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ double horizontalIntersect(double angle, int nX, int nY, int y)
5252
return x;
5353
}
5454

55+
int hIntersect(double angle, int nX, int nY, int y)
56+
{
57+
double x = horizontalIntersect(angle, nX, nY, y);
58+
if (std::isnan(x))
59+
return (std::numeric_limits<int>::max)();
60+
return static_cast<int>(std::round(x));
61+
}
62+
5563
/// Compute the Y intersect position on the line X = x with a ray extending
5664
/// from (nX, nY) along `angle`.
5765
///ABELL doc args
@@ -78,6 +86,14 @@ double verticalIntersect(double angle, int nX, int nY, int x)
7886
return y;
7987
}
8088

89+
int vIntersect(double angle, int nX, int nY, int x)
90+
{
91+
double y = verticalIntersect(angle, nX, nY, x);
92+
if (std::isnan(y))
93+
return (std::numeric_limits<int>::max)();
94+
return static_cast<int>(std::round(y));
95+
}
96+
8197
// Determine if ray is in the slice between two rays starting at `start` and
8298
// going clockwise to `end`.
8399
bool rayBetween(double start, double end, double test)

alg/viewshed/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ namespace viewshed
1616

1717
double normalizeAngle(double maskAngle);
1818
double horizontalIntersect(double angle, int nX, int nY, int y);
19+
int hIntersect(double angle, int nX, int nY, int y);
1920
double verticalIntersect(double angle, int nX, int nY, int x);
21+
int vIntersect(double angle, int nX, int nY, int x);
2022
bool rayBetween(double start, double end, double test);
2123
size_t bandSize(GDALRasterBand &band);
2224

alg/viewshed/viewshed.cpp

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -229,64 +229,61 @@ void shrinkWindowForAngles(Window &oOutExtent, int nX, int nY,
229229

230230
// Set the X boundaries for the angles
231231
//ABELL - Verify for out-of-raster.
232-
double xStart = horizontalIntersect(startAngle, nX, nY, win.yStart);
233-
if (isnan(xStart))
234-
xStart = horizontalIntersect(startAngle, nX, nY, win.yStop);
232+
int xStart = hIntersect(startAngle, nX, nY, win.yStart);
233+
if (xStart == std::numeric_limits<int>::max())
234+
xStart = hIntersect(startAngle, nX, nY, win.yStop);
235235

236-
double xStop = horizontalIntersect(endAngle, nX, nY, win.yStart);
237-
if (isnan(xStop))
238-
xStop = horizontalIntersect(endAngle, nX, nY, win.yStop);
236+
int xStop = hIntersect(endAngle, nX, nY, win.yStart);
237+
if (xStop == std::numeric_limits<int>::max())
238+
xStop = hIntersect(endAngle, nX, nY, win.yStop);
239239

240-
double xmax = nX;
240+
int xmax = nX;
241241
if (!rayBetween(startAngle, endAngle, 0))
242242
{
243-
if (!isnan(xStart))
244-
xmax = std::max(xmax, static_cast<double>(xStart));
245-
if (!isnan(xStop))
246-
xmax = std::max(xmax, static_cast<double>(xStop));
247-
oOutExtent.xStop =
248-
std::min(oOutExtent.xStop, static_cast<int>(std::round(xmax)));
243+
if (xStart != (std::numeric_limits<int>::max)())
244+
xmax = std::max(xmax, xStart);
245+
if (xStop != (std::numeric_limits<int>::max)())
246+
xmax = std::max(xmax, xStop);
247+
oOutExtent.xStop = std::min(oOutExtent.xStop, xmax);
249248
}
250-
double xmin = nX;
249+
250+
int xmin = nX;
251251
if (!rayBetween(startAngle, endAngle, M_PI))
252252
{
253253
if (!isnan(xStart))
254254
xmin = std::min(xmin, xStart);
255255
if (!isnan(xStop))
256256
xmin = std::min(xmin, xStop);
257-
oOutExtent.xStart =
258-
std::max(oOutExtent.xStart, static_cast<int>(std::round(xmin)));
257+
oOutExtent.xStart = std::max(oOutExtent.xStart, xmin);
259258
}
260259

261260
// Set the Y boundaries for the angles
262261
//ABELL - Verify for out-of-raster.
263-
double yStart = verticalIntersect(startAngle, nX, nY, win.xStart);
264-
if (isnan(yStart))
265-
yStart = verticalIntersect(startAngle, nX, nY, win.xStop);
262+
int yStart = vIntersect(startAngle, nX, nY, win.xStart);
263+
if (yStart == std::numeric_limits<int>::max())
264+
yStart = vIntersect(startAngle, nX, nY, win.xStop);
266265

267-
double yStop = verticalIntersect(endAngle, nX, nY, win.xStart);
268-
if (isnan(yStop))
269-
yStop = verticalIntersect(endAngle, nX, nY, win.xStop);
266+
int yStop = vIntersect(endAngle, nX, nY, win.xStart);
267+
if (yStop == std::numeric_limits<int>::max())
268+
yStop = vIntersect(endAngle, nX, nY, win.xStop);
270269

271-
double ymin = nY;
270+
int ymin = nY;
272271
if (!rayBetween(startAngle, endAngle, M_PI / 2))
273272
{
274-
if (!isnan(yStart))
275-
ymin = std::min(ymin, static_cast<double>(yStart));
276-
if (!isnan(yStop))
277-
ymin = std::min(ymin, static_cast<double>(yStop));
278-
oOutExtent.yStart =
279-
std::max(oOutExtent.yStart, static_cast<int>(std::round(ymin)));
273+
if (yStart != std::numeric_limits<int>::max())
274+
ymin = std::min(ymin, yStart);
275+
if (yStop != std::numeric_limits<int>::max())
276+
ymin = std::min(ymin, yStop);
277+
oOutExtent.yStart = std::max(oOutExtent.yStart, ymin);
280278
}
281-
double ymax = nY;
279+
int ymax = nY;
282280
if (!rayBetween(startAngle, endAngle, 3 * M_PI / 2))
283281
{
284-
if (!isnan(yStart))
285-
ymax = std::max(ymax, static_cast<double>(yStart));
286-
if (!isnan(yStop))
287-
ymax = std::max(ymax, static_cast<double>(yStop));
288-
oOutExtent.yStop =
289-
std::min(oOutExtent.yStop, static_cast<int>(std::round(ymax)));
282+
if (yStart != std::numeric_limits<int>::max())
283+
ymax = std::max(ymax, yStart);
284+
if (yStop != std::numeric_limits<int>::max())
285+
ymax = std::max(ymax, yStop);
286+
oOutExtent.yStop = std::min(oOutExtent.yStop, ymax);
290287
}
291288
}
292289

0 commit comments

Comments
 (0)