-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.cpp
More file actions
23 lines (21 loc) · 730 Bytes
/
Copy pathUtility.cpp
File metadata and controls
23 lines (21 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Utility.h"
#include "Geometry.h"
#include <cmath>
using std::floor;
bool get_subscripts(int size, double scale, Point origin,
int &ix, int &iy, Point location)
{
// adjust with origin and scale
Cartesian_vector subscripts = (location - origin) / scale;
// truncate coordinates to integer after taking the floor
// floor function will return the largest integer smaller than the supplied value
// even for negative values, so -0.05 => -1., which will be outside the array.
ix = int(floor(subscripts.delta_x));
iy = int(floor(subscripts.delta_y));
// if out of range, return false
if ((ix < 0) || (ix >= size) || (iy < 0) || (iy >= size)) {
return false;
} else {
return true;
}
}