Skip to content

Commit

Permalink
Add simple "point inside polygon" tests for POS
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed May 9, 2024
1 parent 9c8df10 commit ef5ec27
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/test_ivoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import unittest

from lsst.sphgeom import Region
from lsst.sphgeom import Box, Circle, ConvexPolygon, LonLat, Region, UnitVector3d


class IvoaTestCase(unittest.TestCase):
Expand Down Expand Up @@ -62,6 +62,31 @@ def test_construction(self):
with self.assertRaises(ValueError):
Region.from_ivoa_pos(pos)

def test_circle(self):
"""Test circle construction."""
circle = Region.from_ivoa_pos("CIRCLE 12.0 34.0 5")
self.assertIsInstance(circle, Circle)
self.assertTrue(circle.contains(UnitVector3d(LonLat.fromDegrees(13.0, 33.0))))
self.assertFalse(circle.contains(UnitVector3d(LonLat.fromDegrees(12.0, 40.0))))

def test_range(self):
"""Test range construction."""
box = Region.from_ivoa_pos("RANGE 1 2 5 6")
self.assertIsInstance(box, Box)
self.assertTrue(box.contains(UnitVector3d(LonLat.fromDegrees(1.5, 5.4))))
self.assertFalse(box.contains(UnitVector3d(LonLat.fromDegrees(4, 10))))

box = Region.from_ivoa_pos("RANGE 1 2 20 +Inf")
self.assertTrue(box.contains(UnitVector3d(LonLat.fromDegrees(1.7, 80))))
self.assertFalse(box.contains(UnitVector3d(LonLat.fromDegrees(1.7, 10))))

def test_polygon(self):
"""Test polygon construction."""
poly = Region.from_ivoa_pos("POLYGON 12.0 34.0 14.0 35.0 14. 36.0 12.0 35.0")
self.assertIsInstance(poly, ConvexPolygon)
self.assertTrue(poly.contains(UnitVector3d(LonLat.fromDegrees(13, 35))))
self.assertFalse(poly.contains(UnitVector3d(LonLat.fromDegrees(14, 34))))


if __name__ == "__main__":
unittest.main()

0 comments on commit ef5ec27

Please sign in to comment.