Fixed #152 (shape count wrong)

This commit is contained in:
Matthias Koefferlein 2018-08-13 09:30:28 +02:00
parent 1a7bcfc31c
commit bcd6c466fb
3 changed files with 33 additions and 1 deletions

View File

@ -50,6 +50,21 @@ static void dump_mem_statistics (const db::Shapes *shapes, bool detailed)
ms.print (); ms.print ();
} }
static size_t shapes_size (const db::Shapes *shapes)
{
// we may have shape arrays - expand their count to match the shape count with the shapes delivered
size_t n = 0;
for (db::Shapes::shape_iterator i = shapes->begin (db::ShapeIterator::All); ! i.at_end (); ++i) {
if (i.in_array ()) {
n += i.array ().array_size ();
i.finish_array ();
} else {
++n;
}
}
return n;
}
template<class Sh> template<class Sh>
static db::Shape insert (db::Shapes *s, const Sh &p) static db::Shape insert (db::Shapes *s, const Sh &p)
{ {
@ -1088,7 +1103,7 @@ Class<db::Shapes> decl_Shapes ("Shapes",
"@brief Clears the shape container\n" "@brief Clears the shape container\n"
"This method has been introduced in version 0.16. It can only be used in editable mode." "This method has been introduced in version 0.16. It can only be used in editable mode."
) + ) +
gsi::method ("size", (size_t (db::Shapes::*)() const) &db::Shapes::size, gsi::method_ext ("size", &shapes_size,
"@brief Gets the number of shapes in this container\n" "@brief Gets the number of shapes in this container\n"
"This method was introduced in version 0.16\n" "This method was introduced in version 0.16\n"
"@return The number of shapes in this container\n" "@return The number of shapes in this container\n"

BIN
testdata/oasis/issue_152.oas vendored Normal file

Binary file not shown.

View File

@ -1377,6 +1377,23 @@ class DBShapes_TestClass < TestBase
end end
# issue 152 (number of shapes count wrong in viewer mode)
def test_10
ly = RBA::Layout::new(true)
ly.read(File.join($ut_testsrc, "testdata", "oasis", "issue_152.oas"))
assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 200)
ly.top_cell.shapes(ly.layer(1, 0)).insert(RBA::Polygon::new(RBA::Box::new(0, 0, 100, 100)))
assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 201)
ly = RBA::Layout::new(false)
ly.read(File.join($ut_testsrc, "testdata", "oasis", "issue_152.oas"))
assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 200)
ly.top_cell.shapes(ly.layer(1, 0)).insert(RBA::Polygon::new(RBA::Box::new(0, 0, 100, 100)))
assert_equal(ly.top_cell.shapes(ly.layer(1, 0)).size, 201)
end
end end
load("test_epilogue.rb") load("test_epilogue.rb")