Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -71,12 +71,12 @@ double dist(vec x, vec y0, vec y1, double tol)
|
|||
int inside(vec v, polygon p, double tol)
|
||||
{
|
||||
/* should assert p->n > 1 */
|
||||
int i, k, crosses;
|
||||
int i, k, crosses, intersectResult;
|
||||
vec *pv;
|
||||
double min_x, max_x, min_y, max_y;
|
||||
|
||||
for (i = 0; i < p->n; i++) {
|
||||
k = i + 1 % p->n;
|
||||
k = (i + 1) % p->n;
|
||||
min_x = dist(v, p->v[i], p->v[k], tol);
|
||||
if (min_x < tol) return 0;
|
||||
}
|
||||
|
|
@ -107,13 +107,13 @@ int inside(vec v, polygon p, double tol)
|
|||
|
||||
for (i = 0; i < p->n; i++) {
|
||||
k = (i + 1) % p->n;
|
||||
k = intersect(v, e, p->v[i], p->v[k], tol, 0);
|
||||
intersectResult = intersect(v, e, p->v[i], p->v[k], tol, 0);
|
||||
|
||||
/* picked a bad point, ray got too close to vertex.
|
||||
re-pick */
|
||||
if (!k) break;
|
||||
if (!intersectResult) break;
|
||||
|
||||
if (k == 1) crosses++;
|
||||
if (intersectResult == 1) crosses++;
|
||||
}
|
||||
if (i == p->n) break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ immutable struct Figure {
|
|||
Edge[] edges;
|
||||
}
|
||||
|
||||
bool contains(in Figure poly, in Point p) pure nothrow {
|
||||
static bool raySegI(in Point p, in Edge edge) pure nothrow {
|
||||
bool contains(in Figure poly, in Point p) pure nothrow @safe @nogc {
|
||||
static bool raySegI(in Point p, in Edge edge)
|
||||
pure nothrow @safe @nogc {
|
||||
enum double epsilon = 0.00001;
|
||||
with (edge) {
|
||||
if (a.y > b.y)
|
||||
|
|
@ -31,7 +32,7 @@ bool contains(in Figure poly, in Point p) pure nothrow {
|
|||
}
|
||||
}
|
||||
|
||||
return poly.edges.count!(e => raySegI(p, e))() % 2;
|
||||
return poly.edges.count!(e => raySegI(p, e)) % 2;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
|
@ -54,6 +55,7 @@ void main() {
|
|||
{{10.0, 5.0}, { 7.0, 10.0}}, {{ 7.0, 10.0}, { 3.0, 10.0}},
|
||||
{{ 3.0, 10.0}, { 0.0, 5.0}}, {{ 0.0, 5.0}, { 3.0, 0.0}}]}
|
||||
];
|
||||
|
||||
immutable Point[] testPoints = [{ 5, 5}, {5, 8}, {-10, 5}, {0, 5},
|
||||
{10, 5}, {8, 5}, { 10, 10}];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue