Git Product home page Git Product logo

Comments (2)

msiner avatar msiner commented on September 25, 2024 1

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:

9.93132e-09
9.93132e-09
1
/home/mark/s2geometry/src/s2/s2polygon.cc:180 ERROR Inconsistent loop orientations detected
/home/mark/s2geometry/src/s2/s2polygon.cc:447 FATAL Check failed: IsValid() Aborted

from geo.

msiner avatar msiner commented on September 25, 2024 1

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, "inconsistent loop orientations detected" matches the error reported by the C++ implementation.

geo/s2/polygon.go

Lines 462 to 473 in e86565b

// TODO(roberts): Uncomment the remaining checks when they are completed.
// Check for loop self-intersections and loop pairs that cross
// (including duplicate edges and vertices).
// if findSelfIntersection(p.index) {
// return fmt.Errorf("polygon has loop pairs that cross")
// }
// Check whether initOriented detected inconsistent loop orientations.
// if p.hasInconsistentLoopOrientations {
// return fmt.Errorf("inconsistent loop orientations detected")
// }

from geo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.