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 45bb84e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 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,27 @@ 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))))

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))))

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

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))))


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

0 comments on commit 45bb84e

Please sign in to comment.