Skip to content

Instantly share code, notes, and snippets.

@brianv0
Last active May 14, 2018 07:36
Show Gist options
  • Save brianv0/85a96df2236d49927b7de6fde87ccfd4 to your computer and use it in GitHub Desktop.
Save brianv0/85a96df2236d49927b7de6fde87ccfd4 to your computer and use it in GitHub Desktop.
s2 tests
latlng = pywraps2.S2LatLng_FromDegrees(24,42)
latlng2 = pywraps2.S2LatLng_FromDegrees(40,60)
latlng3 = pywraps2.S2LatLng_FromDegrees(26,46)
distance = latlng.GetDistance(latlng2)
# contains
Circle = pywraps2.S2Cap
circ_center = pywraps2.S2LatLng_FromDegrees(26,46).ToPoint()
circ_angle = pywraps2.S1Angle.Degrees(10)
circle = Circle(circ_center, circ_angle)
circle.Contains(latlng.ToPoint())
circle.Contains(latlng2.ToPoint())
Box = pywraps2.S2LatLngRect
box = Box(latlng, latlng2)
box_center = box.GetCenter()
size = pywraps2.S2LatLng_FromDegrees(16, 18)
box2 = Box.FromCenterSize(box_center, size)
box.Contains(box2)
box2.Contains(box)
box.GetSize().ToStringInDegrees()
box2.GetSize().ToStringInDegrees()
box2.GetCenter() == box.GetCenter()
box2.GetSize() == box.GetSize()
@brianv0
Copy link
Author

brianv0 commented May 14, 2018

>>> latlng = pywraps2.S2LatLng_FromDegrees(24,42)
>>> latlng2 = pywraps2.S2LatLng_FromDegrees(40,60)
>>> 
>>> latlng3 = pywraps2.S2LatLng_FromDegrees(26,46)
>>> distance = latlng.GetDistance(latlng2)
>>> 
>>> # contains
... Circle = pywraps2.S2Cap
>>> circ_center = pywraps2.S2LatLng_FromDegrees(26,46).ToPoint()
>>> circ_angle = pywraps2.S1Angle.Degrees(10)
>>> circle = Circle(circ_center, circ_angle)
>>> circle.Contains(latlng.ToPoint())
True
>>> circle.Contains(latlng2.ToPoint())
False
>>> 
>>> Box = pywraps2.S2LatLngRect
>>> 
>>> box = Box(latlng, latlng2)
>>> 
>>> box_center = box.GetCenter()
>>> size =  pywraps2.S2LatLng_FromDegrees(16, 18)
>>> 
>>> box2 = Box.FromCenterSize(box_center, size)
>>> 
>>> 
>>> box.Contains(box2)
False
>>> box2.Contains(box)
True
>>> 
>>> box.GetSize().ToStringInDegrees()
'16.000000,18.000000'
>>> box2.GetSize().ToStringInDegrees()
'16.000000,18.000000'
>>> 
>>> box2.GetCenter() == box.GetCenter()
True
>>> box2.GetSize() == box.GetSize()
False

@brianv0
Copy link
Author

brianv0 commented May 14, 2018

Notes:

Coverage:

S2RegionCoverer::Options options;
options.set_max_cells(5);
S2RegionCoverer coverer(options);
S2Cap cap(center, radius);
S2CellUnion covering = coverer.GetCovering(cap);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment