-
Notifications
You must be signed in to change notification settings - Fork 186
Port S2LegacyValidQuery and use in polygon validation #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This does appear to be a bug or, at least, an implementation inconsistent with the C++ implementation. Below is an equivalent C++ program. The provided loops work fine when calling S2Polygon::InitNested(), but produce an error when calling S2Polygon::InitOriented(). #include <iostream>
#include <memory>
#include <vector>
#include <s2/s2latlng.h>
#include <s2/s2loop.h>
#include <s2/s2point.h>
#include <s2/s2polygon.h>
using std::cout;
using std::endl;
using std::vector;
int main() {
vector<S2Point> s{
S2LatLng::FromDegrees(35.841751, 50.991497).ToPoint(),
S2LatLng::FromDegrees(35.836811, 50.991626).ToPoint(),
S2LatLng::FromDegrees(35.83695, 51.002612).ToPoint(),
S2LatLng::FromDegrees(35.842065, 51.00081).ToPoint(),
};
vector<S2Point> h{
S2LatLng::FromDegrees(35.841056, 50.996089).ToPoint(),
S2LatLng::FromDegrees(35.837785, 50.993557).ToPoint(),
S2LatLng::FromDegrees(35.83789, 51.000381).ToPoint(),
};
vector<std::unique_ptr<S2Loop>> loops;
loops.push_back(std::make_unique<S2Loop>(s));
loops.push_back(std::make_unique<S2Loop>(h));
cout << loops[0]->GetArea() - loops[1]->GetArea() << endl;
S2Polygon polyN;
polyN.InitNested(std::move(loops));
cout << polyN.GetArea() << endl;
cout << polyN.IsValid() << endl;
loops.clear();
loops.push_back(std::make_unique<S2Loop>(s));
loops.push_back(std::make_unique<S2Loop>(h));
S2Polygon polyO;
polyO.InitOriented(std::move(loops));
cout << polyO.GetArea() << endl;
cout << polyO.IsValid() << endl;
return 0;
} Output:
|
Looks like the implementation is incomplete. The TODO comment in s2/polygon.go indicates that the validation is currently not implementing the orientation check. As you can see, the planned error message, Lines 462 to 473 in e86565b
|
In C++, |
s2LegacyValidQuery needs s2ValidQuery which needs internal/s2index_cell_data and internal/s2incident_edge_tracker |
These are ports of the C++ s2/internal/ types that are needed for ValidationQuery for Loops and Polygons. Work for issues golang#72, golang#108.
In the documentation of
PolygonFromOrientedLoops
, it's said that:and:
But in this example, I'm giving two nested counter-clockwise loops to
PolygonFromOrientedLoops
and it automatically makes the inner loop a hole like how it does inPolygonFromLoops
. So shouldn'tValidate
returns an error in this situation or I'm missing something here?This is the visualization of loops:

Code:
Output:
The text was updated successfully, but these errors were encountered: