Skip to content

Commit

Permalink
SWIG: Expose the S2Point's underlying 3-vector
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePlayle committed Jun 20, 2022
1 parent 7a40135 commit e8f4ae4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/python/pywraps2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ def testS2EarthMetricRadians(self):
radius_m = s2.S2Earth.RadiansToMeters(angle.radians())
self.assertEqual(radius_m, 12340.0)

def testS2Point_ToFromRaw(self):
p = s2.S2Point_FromRaw(1.0, 1.0, 1.0)
p = p.Normalize()
p_raw = s2.S2Point_ToRaw(p)
self.assertAlmostEqual(p_raw[0], 0.57735027)
self.assertAlmostEqual(p_raw[1], 0.57735027)
self.assertAlmostEqual(p_raw[2], 0.57735027)

class RegionTermIndexerTest(unittest.TestCase):
def _randomCaps(self, query_type, **indexer_options):
Expand Down
4 changes: 4 additions & 0 deletions src/python/s2_common.i
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ std::vector<S2Polyline *> *out(std::vector<S2Polyline *> temp) {
return SWIG_NewPointerObj(new S2Point(x, y, z), SWIGTYPE_p_S2Point,
SWIG_POINTER_OWN);
}

static PyObject *S2Point_ToRaw(const S2Point& p) {
return Py_BuildValue("ddd", p[0], p[1], p[2]);
}
%}

// We provide our own definition of S2Point, because the real one is too
Expand Down

0 comments on commit e8f4ae4

Please sign in to comment.