EdgePairs generic processor

This commit is contained in:
Matthias Koefferlein
2024-01-26 16:09:01 +01:00
parent b7277631c3
commit ce88affa67
12 changed files with 325 additions and 18 deletions
+95
View File
@@ -44,6 +44,46 @@ class PerpendicularEdgesFilter < RBA::EdgePairFilter
end
class FlipEdgePair < RBA::EdgePairOperator
# Constructor
def initialize
self.is_isotropic_and_scale_invariant # orientation and scale do not matter
end
# Flips the edge pair
def process(edge_pair)
return [ RBA::EdgePair::new(edge_pair.second, edge_pair.first) ]
end
end
class SomeEdgePairToEdgeOperator < RBA::EdgePairToEdgeOperator
# Constructor
def initialize
self.is_isotropic_and_scale_invariant # scale or orientation do not matter
end
def process(ep)
return [ RBA::Edge::new(ep.first.p1, ep.second.p2) ]
end
end
class SomeEdgePairToPolygonOperator < RBA::EdgePairToPolygonOperator
# Constructor
def initialize
self.is_isotropic_and_scale_invariant # scale or orientation do not matter
end
def process(ep)
return [ RBA::Polygon::new(ep.bbox) ]
end
end
class DBEdgePairs_TestClass < TestBase
# Basics
@@ -374,6 +414,61 @@ class DBEdgePairs_TestClass < TestBase
end
# Generic processors
def test_generic_processors_epep
# Some basic tests for the processor class
f = FlipEdgePair::new
assert_equal(f.wants_variants?, true)
f.wants_variants = false
assert_equal(f.wants_variants?, false)
# Smoke test
f.is_isotropic
f.is_scale_invariant
# Some application
edge_pairs = RBA::EdgePairs::new
edge_pairs.insert(RBA::EdgePair::new(RBA::Edge::new(0, 0, 100, 100), RBA::Edge::new(200, 300, 200, 500)))
assert_equal(edge_pairs.processed(FlipEdgePair::new).to_s, "(200,300;200,500)/(0,0;100,100)")
assert_equal(edge_pairs.to_s, "(0,0;100,100)/(200,300;200,500)")
edge_pairs.process(FlipEdgePair::new)
assert_equal(edge_pairs.to_s, "(200,300;200,500)/(0,0;100,100)")
end
# Generic processors
def test_generic_processors_epe
p = SomeEdgePairToEdgeOperator::new
edge_pairs = RBA::EdgePairs::new
edge_pairs.insert(RBA::EdgePair::new(RBA::Edge::new(0, 0, 100, 100), RBA::Edge::new(200, 300, 200, 500)))
assert_equal(edge_pairs.processed(p).to_s, "(0,0;200,500)")
assert_equal(edge_pairs.to_s, "(0,0;100,100)/(200,300;200,500)")
end
# Generic processors
def test_generic_processors_epp
p = SomeEdgePairToPolygonOperator::new
edge_pairs = RBA::EdgePairs::new
edge_pairs.insert(RBA::EdgePair::new(RBA::Edge::new(0, 0, 100, 100), RBA::Edge::new(200, 300, 200, 500)))
assert_equal(edge_pairs.processed(p).to_s, "(0,0;0,500;200,500;200,0)")
assert_equal(edge_pairs.to_s, "(0,0;100,100)/(200,300;200,500)")
end
end