diff --git a/src/drc/drc/built-in-macros/_drc_layer.rb b/src/drc/drc/built-in-macros/_drc_layer.rb index 646dc91cc..0411cbec9 100644 --- a/src/drc/drc/built-in-macros/_drc_layer.rb +++ b/src/drc/drc/built-in-macros/_drc_layer.rb @@ -276,16 +276,37 @@ module DRC end # %DRC% - # @name size + # @name count # @brief Returns the number of objects on the layer - # @synopsis layer.size + # @synopsis layer.count # - # The number of objects is the number of raw objects, not merged - # regions or edges. It is more efficent to call this method on output layers than - # on input layers. + # The count is the number of raw objects, not merged + # regions or edges. This is the flat count - the number of polygons, + # edges or edge pairs seen from the top cell. + # "count" can be computationally expensive for original layers with + # clip regions or cell tree filters. + # + # See \hier_count for a hierarchical (each cell counts once) count. - def size - self.data.size + def count + self.data.count + end + + # %DRC% + # @name hier_count + # @brief Returns the hierarchical number of objects on the layer + # @synopsis layer.hier_count + # + # The hier_count is the number of raw objects, not merged + # regions or edges, with each cell counting once. + # A high \count to hier_count (flat to hierarchical) ratio is an indication + # of a good hierarchical compression. + # "hier_count" applies only to original layers without clip regions or + # cell filters and to layers in \deep mode. Otherwise, hier_count gives + # the same value than \count. + + def hier_count + self.data.hier_count end # %DRC% diff --git a/src/lay/lay/doc/about/drc_ref_layer.xml b/src/lay/lay/doc/about/drc_ref_layer.xml index e7d077cd2..587180996 100644 --- a/src/lay/lay/doc/about/drc_ref_layer.xml +++ b/src/lay/lay/doc/about/drc_ref_layer.xml @@ -275,6 +275,21 @@ The following images show the effect of this method:

+

"count" - Returns the number of objects on the layer

+ +

Usage:

+ +

+The count is the number of raw objects, not merged +regions or edges. This is the flat count - the number of polygons, +edges or edge pairs seen from the top cell. +"count" can be computationally expensive for original layers with +clip regions or cell tree filters. +

+See hier_count for a hierarchical (each cell counts once) count. +

"covering" - Selects shapes or regions of self which completely cover (enclose) one or more shapes from the other region

Usage:

@@ -1187,6 +1202,21 @@ l = nil

By setting the layer to nil, it is ensured that it can no longer be accessed.

+

"hier_count" - Returns the hierarchical number of objects on the layer

+ +

Usage:

+ +

+The hier_count is the number of raw objects, not merged +regions or edges, with each cell counting once. +A high count to hier_count (flat to hierarchical) ratio is an indication +of a good hierarchical compression. +"hier_count" applies only to original layers without clip regions or +cell filters and to layers in deep mode. Otherwise, hier_count gives +the same value than count. +

"holes" - Selects all polygon holes from the input

Usage:

diff --git a/testdata/drc/drcSimpleTests_1.drc b/testdata/drc/drcSimpleTests_1.drc index 28f5bd3a5..35e022c1d 100644 --- a/testdata/drc/drcSimpleTests_1.drc +++ b/testdata/drc/drcSimpleTests_1.drc @@ -3,7 +3,17 @@ dbu 0.001 target($drc_test_target, "TOP") +def self.expect_count(layer, c, hc, where) + if layer.count != c + raise(where + ": Layer count #{layer.count} does not equal #{c}") + end + if layer.hier_count != hc + raise(where + ": Layer hier count #{layer.hier_count} does not equal #{c}") + end +end + x = polygon_layer +expect_count(x, 0, 0, "empty layer") x.is_empty? == true || raise("unexpected value") x.is_box? == false || raise("unexpected value") x.insert(box(4.0, 0, 4.7, 0.7)) @@ -12,6 +22,7 @@ x.is_box? == true || raise("unexpected value") x.insert(polygon([ p(0, 0), p(2.0, 0), p(1.0, 1.0) ])) x.insert(polygon([ p(0, -5.0), p(2.0, -5.0), p(1.0, -6.0) ])) x.insert(path([ p(0, -2), p(2.0, -2) ], 0.2)) +expect_count(x, 4, 4, "after 3x insert") x.is_box? == false || raise("unexpected value") x.output(10, 0) diff --git a/testdata/drc/drcSimpleTests_2.drc b/testdata/drc/drcSimpleTests_2.drc index 66faa4c55..d2055c458 100644 --- a/testdata/drc/drcSimpleTests_2.drc +++ b/testdata/drc/drcSimpleTests_2.drc @@ -2,6 +2,15 @@ target($drc_test_target, "TOP") source($drc_test_source, "TOP") +def self.expect_count(layer, c, hc, where) + if layer.count != c + raise(where + ": Layer count #{layer.count} does not equal #{c}") + end + if layer.hier_count != hc + raise(where + ": Layer hier count #{layer.hier_count} does not equal #{c}") + end +end + a1 = input(1) b1 = input(2) c1 = input(3) @@ -89,3 +98,6 @@ a1.edges.collect_to_region { |p| p.length < 0.8 && p.bbox.transformed(RBA::VCplx a1.width(1.5).collect { |p| p.transformed(RBA::VCplxTrans::new(1000.0)) }.output(1120, 0) a1.width(1.5).collect_to_edge_pairs { |p| p.transformed(RBA::VCplxTrans::new(1000.0)) }.output(1121, 0) +expect_count(a1.edges, 9, 9, "a1.edges") +expect_count(a1.width(1.5), 5, 5, "a1.width(1.5)") + diff --git a/testdata/drc/drcSimpleTests_4.drc b/testdata/drc/drcSimpleTests_4.drc index b729ee968..b05ecdcdc 100644 --- a/testdata/drc/drcSimpleTests_4.drc +++ b/testdata/drc/drcSimpleTests_4.drc @@ -4,6 +4,15 @@ source($drc_test_source, "TOPTOP_SMALL") target($drc_test_target) +def self.expect_count(layer, c, hc, where) + if layer.count != c + raise(where + ": Layer count #{layer.count} does not equal #{c}") + end + if layer.hier_count != hc + raise(where + ": Layer hier count #{layer.hier_count} does not equal #{c}") + end +end + cell("TOPTOP_SMALL") l1_flat = input(1) @@ -66,12 +75,16 @@ r.output(1023, 0) r.extents.output(1123, 0) r = l1.space(0.5) +expect_count(r, 3, 1, "r on l1") r.output(1010, 0) r.extents.output(1110, 0) +expect_count(l1, 15, 5, "l1 before flatten") l1.flatten +expect_count(l1, 15, 15, "l1 after flatten") r = l1.space(0.5) r.output(1011, 0) r.extents.output(1111, 0) +expect_count(r, 3, 1, "r on l1.flatten")