Tests for polygon-to-edge and polygon-to-edge-pair processors

This commit is contained in:
Matthias Koefferlein 2024-01-26 13:09:48 +01:00
parent 1a126ede45
commit bbb535a0bf
1 changed files with 60 additions and 2 deletions

View File

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