mirror of
https://github.com/KLayout/klayout.git
synced 2026-08-30 09:49:21 +02:00
EdgePairs generic processor
This commit is contained in:
Vendored
+95
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user