From 756fde10a1e15f1efc1a289df19f49e7b340b126 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 25 Dec 2024 19:09:16 +0100 Subject: [PATCH] Bugfix: bool and/not with flat region and property constraint wasn't working properly Property IDs were not translated properly, so that a property match was more or less random if the inputs came from different property ID spaces. --- src/db/db/dbAsIfFlatRegion.cc | 18 ++++++++++-------- src/db/unit_tests/dbAsIfFlatRegionTests.cc | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/db/db/dbAsIfFlatRegion.cc b/src/db/db/dbAsIfFlatRegion.cc index a62894e47..4990c699a 100644 --- a/src/db/db/dbAsIfFlatRegion.cc +++ b/src/db/db/dbAsIfFlatRegion.cc @@ -1494,19 +1494,20 @@ AsIfFlatRegion::and_with (const Region &other, PropertyConstraint property_const } else if (is_box () && ! other.strict_handling ()) { - db::properties_id_type self_prop_id = pc_skip (property_constraint) ? 0 : begin ()->prop_id (); - // map AND with box to clip .. db::Box b = bbox (); std::unique_ptr new_region (new FlatRegion (false)); db::PropertyMapper pm (new_region->properties_repository (), properties_repository ()); - db::properties_id_type prop_id_out = pm (pc_norm (property_constraint, self_prop_id)); + db::PropertyMapper pm2 (new_region->properties_repository (), &other.properties_repository ()); + + db::properties_id_type self_prop_id = pm (pc_skip (property_constraint) ? 0 : begin ()->prop_id ()); + db::properties_id_type prop_id_out = pc_norm (property_constraint, self_prop_id); std::vector clipped; for (RegionIterator p (other.begin ()); ! p.at_end (); ++p) { - db::properties_id_type prop_id = p.prop_id (); + db::properties_id_type prop_id = pm2 (p.prop_id ()); if (pc_match (property_constraint, self_prop_id, prop_id)) { clipped.clear (); @@ -1528,23 +1529,24 @@ AsIfFlatRegion::and_with (const Region &other, PropertyConstraint property_const } else if (other.is_box () && ! strict_handling ()) { - db::properties_id_type other_prop_id = pc_skip (property_constraint) ? 0 : other.begin ().prop_id (); - // map AND with box to clip .. db::Box b = other.bbox (); std::unique_ptr new_region (new FlatRegion (false)); db::PropertyMapper pm (new_region->properties_repository (), properties_repository ()); + db::PropertyMapper pm2 (new_region->properties_repository (), &other.properties_repository ()); + db::properties_id_type other_prop_id = pc_skip (property_constraint) ? 0 : pm2 (other.begin ().prop_id ()); + std::vector clipped; for (RegionIterator p (begin ()); ! p.at_end (); ++p) { - db::properties_id_type prop_id = p.prop_id (); + db::properties_id_type prop_id = pm (p.prop_id ()); if (pc_match (property_constraint, prop_id, other_prop_id)) { clipped.clear (); clip_poly (*p, b, clipped); - db::properties_id_type prop_id_out = pm (pc_norm (property_constraint, prop_id)); + db::properties_id_type prop_id_out = pc_norm (property_constraint, prop_id); if (prop_id_out == 0) { new_region->raw_polygons ().insert (clipped.begin (), clipped.end ()); } else { diff --git a/src/db/unit_tests/dbAsIfFlatRegionTests.cc b/src/db/unit_tests/dbAsIfFlatRegionTests.cc index 55d459000..7a5be9a1d 100644 --- a/src/db/unit_tests/dbAsIfFlatRegionTests.cc +++ b/src/db/unit_tests/dbAsIfFlatRegionTests.cc @@ -1745,7 +1745,7 @@ TEST(40_BoolWithProperties) db::Region clip_region_wp (new db::FlatRegion ()); db::property_names_id_type pn = clip_region_wp.properties_repository ().prop_name_id (1); db::PropertiesRepository::properties_set ps; - ps.insert (std::make_pair (pn, 42)); + ps.insert (std::make_pair (pn, "42")); db::properties_id_type pid42 = clip_region_wp.properties_repository ().properties_id (ps); clip_region_wp.insert (db::BoxWithProperties (clip, pid42));