mirror of
https://github.com/csharpee/Map-Projections.git
synced 2025-12-12 00:00:17 -05:00
try and fail
I made an attempt to fix the error messages you get with Elastic II. it didn't work. I'm leaving this change in because I think it will probably be better in some situations regardless of the current errors.
This commit is contained in:
parent
f950e04d54
commit
a1d581e849
@ -328,9 +328,9 @@ public class Elastik {
|
|||||||
* @param λ the longitude of the point
|
* @param λ the longitude of the point
|
||||||
* @return true if the point is contained by the polygon and false otherwise
|
* @return true if the point is contained by the polygon and false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean contains(double ф, double λ) {
|
public boolean contains(double ф, double λ) { // TODO: this fails for a few select longitudes for the mountains one
|
||||||
double nearestSegment = POSITIVE_INFINITY;
|
double nearestSegment = POSITIVE_INFINITY;
|
||||||
boolean contained = false;
|
int crossings = 0;
|
||||||
// for each edge of the polygon
|
// for each edge of the polygon
|
||||||
for (int i = 1; i < ф_vertices.length; i ++) {
|
for (int i = 1; i < ф_vertices.length; i ++) {
|
||||||
if (abs(λ_vertices[i] - λ_vertices[i - 1]) > PI)
|
if (abs(λ_vertices[i] - λ_vertices[i - 1]) > PI)
|
||||||
@ -354,16 +354,18 @@ public class Elastik {
|
|||||||
if (Δф < nearestSegment) {
|
if (Δф < nearestSegment) {
|
||||||
// record it
|
// record it
|
||||||
nearestSegment = Δф;
|
nearestSegment = Δф;
|
||||||
// and save the polarity
|
if (Δф == 0)
|
||||||
if (Δф != 0)
|
return true; // if it's on the line, count it as in
|
||||||
contained = (ф_intersect < ф) == (λ_vertices[i - 1] < λ_vertices[i]);
|
// otherwise, count this crossing
|
||||||
|
if ((ф_intersect < ф) == (λ_vertices[i - 1] < λ_vertices[i]))
|
||||||
|
crossings += 1;
|
||||||
else
|
else
|
||||||
contained = true; // if it's on the line, count it as in
|
crossings -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return contained;
|
return crossings > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user