From bbb535a0bfa4c3766b9bd262a28b2e1b0641a705 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 26 Jan 2024 13:09:48 +0100 Subject: [PATCH] Tests for polygon-to-edge and polygon-to-edge-pair processors --- testdata/ruby/dbRegionTest.rb | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/testdata/ruby/dbRegionTest.rb b/testdata/ruby/dbRegionTest.rb index 9eea0ff38..87da79aa1 100644 --- a/testdata/ruby/dbRegionTest.rb +++ b/testdata/ruby/dbRegionTest.rb @@ -59,6 +59,34 @@ class ShrinkToHalfProcessor < RBA::PolygonProcessor end +class SomePolygonToEdgePairProcessor < RBA::PolygonToEdgePairProcessor + + # Constructor + def initialize + self.is_isotropic_and_scale_invariant # scale or orientation do not matter + end + + def process(polygon) + box = polygon.bbox + return [ RBA::EdgePair::new([ box.left, box.bottom, box.left, box.top ], [ box.right, box.bottom, box.right, box.top ]) ] + end + +end + +class SomePolygonToEdgeProcessor < RBA::PolygonToEdgeProcessor + + # Constructor + def initialize + self.is_isotropic_and_scale_invariant # scale or orientation do not matter + end + + def process(polygon) + box = polygon.bbox + return [ RBA::Edge::new(box.p1, box.p2) ] + end + +end + class DBRegion_TestClass < TestBase # Basics @@ -1249,9 +1277,9 @@ class DBRegion_TestClass < TestBase end # Generic processors - def test_generic_processors + def test_generic_processors_pp - # Some basic tests for the filter class + # Some basic tests for the processor class f = ShrinkToHalfProcessor::new assert_equal(f.wants_variants?, true) @@ -1285,6 +1313,36 @@ class DBRegion_TestClass < TestBase end + # Generic processors + def test_generic_processors_pep + + p = SomePolygonToEdgePairProcessor::new + + region = RBA::Region::new + + region.insert(RBA::Polygon::new([[0,0], [100, 100], [100,0]])) + region.insert(RBA::Box::new(200, 0, 300, 100)) + + assert_equal(region.processed(p).to_s, "(0,0;0,100)/(100,0;100,100);(200,0;200,100)/(300,0;300,100)") + assert_equal(region.to_s, "(0,0;100,100;100,0);(200,0;200,100;300,100;300,0)") + + end + + # Generic processors + def test_generic_processors_pe + + p = SomePolygonToEdgeProcessor::new + + region = RBA::Region::new + + region.insert(RBA::Polygon::new([[0,0], [100, 100], [100,0]])) + region.insert(RBA::Box::new(200, 0, 300, 100)) + + assert_equal(region.processed(p).to_s, "(0,0;100,100);(200,0;300,100)") + assert_equal(region.to_s, "(0,0;100,100;100,0);(200,0;200,100;300,100;300,0)") + + end + end load("test_epilogue.rb")