-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[traverse] reverse meaning of isolation in difference #887
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,6 @@ struct traversal_switch_detector | |
|
||
enum isolation_type | ||
{ | ||
isolation_unknown = -1, | ||
isolation_no = 0, | ||
isolation_yes = 1, | ||
isolation_multiple = 2 | ||
|
@@ -121,7 +120,7 @@ struct traversal_switch_detector | |
struct region_properties | ||
{ | ||
signed_size_type region_id = -1; | ||
isolation_type isolated = isolation_unknown; | ||
isolation_type isolated = isolation_no; | ||
set_type unique_turn_ids; | ||
connection_map connected_region_counts; | ||
}; | ||
|
@@ -374,7 +373,7 @@ struct traversal_switch_detector | |
{ | ||
region_properties& properties = key_val.second; | ||
|
||
if (properties.isolated == isolation_unknown | ||
if (properties.isolated == isolation_no | ||
&& has_only_isolated_children(properties)) | ||
{ | ||
properties.isolated = isolation_yes; | ||
|
@@ -388,13 +387,36 @@ struct traversal_switch_detector | |
{ | ||
for (turn_type& turn : m_turns) | ||
{ | ||
// For difference, for the input walked through in reverse, | ||
// the meaning is reversed: what is isolated is actually not, | ||
// and vice versa. | ||
bool const reverseMeaningInTurn | ||
= (Reverse1 || Reverse2) | ||
&& ! turn.is_self() | ||
&& ! turn.is_clustered() | ||
&& uu_or_ii(turn) | ||
&& turn.operations[0].enriched.region_id | ||
!= turn.operations[1].enriched.region_id; | ||
|
||
for (auto& op : turn.operations) | ||
{ | ||
auto mit = m_connected_regions.find(op.enriched.region_id); | ||
if (mit != m_connected_regions.end()) | ||
{ | ||
bool const reverseMeaningInOp | ||
= reverseMeaningInTurn | ||
&& ((op.seg_id.source_index == 0 && Reverse1) | ||
|| (op.seg_id.source_index == 1 && Reverse2)); | ||
|
||
// It is assigned to isolated if it's property is "Yes", | ||
// (one connected interior, or chained). | ||
// "Multiple" doesn't count for isolation, | ||
// neither for intersection, neither for difference. | ||
region_properties const& prop = mit->second; | ||
op.enriched.isolated = prop.isolated == isolation_yes; | ||
op.enriched.isolated | ||
= reverseMeaningInOp | ||
? false | ||
: prop.isolated == isolation_yes; | ||
} | ||
} | ||
} | ||
|
@@ -478,8 +500,12 @@ struct traversal_switch_detector | |
// Discarded turns don't connect rings to the same region | ||
// Also xx are not relevant | ||
// (otherwise discarded colocated uu turn could make a connection) | ||
return ! turn.discarded | ||
&& ! turn.both(operation_blocked); | ||
return ! turn.discarded && ! turn.both(operation_blocked); | ||
} | ||
|
||
inline bool uu_or_ii(turn_type const& turn) const | ||
{ | ||
return turn.both(operation_union) || turn.both(operation_intersection); | ||
} | ||
|
||
inline bool connects_same_region(turn_type const& turn) const | ||
|
@@ -492,7 +518,7 @@ struct traversal_switch_detector | |
if (! turn.is_clustered()) | ||
{ | ||
// If it is a uu/ii-turn (non clustered), it is never same region | ||
return ! (turn.both(operation_union) || turn.both(operation_intersection)); | ||
return ! uu_or_ii(turn); | ||
} | ||
|
||
if (BOOST_GEOMETRY_CONDITION(target_operation == operation_union)) | ||
|
@@ -565,10 +591,83 @@ struct traversal_switch_detector | |
} | ||
} | ||
|
||
#if defined(BOOST_GEOMETRY_DEBUG_TRAVERSAL_SWITCH_DETECTOR) | ||
void debug_show_results() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shows quite a neat list of results and I would like to keep it. For example
|
||
{ | ||
auto isolation_to_string = [](isolation_type const& iso) -> std::string | ||
{ | ||
switch(iso) | ||
{ | ||
case isolation_no : return "no"; | ||
case isolation_yes : return "yes"; | ||
case isolation_multiple : return "multiple"; | ||
} | ||
return "error"; | ||
}; | ||
auto set_to_string = [](auto const& s) -> std::string | ||
{ | ||
std::ostringstream result; | ||
for (auto item : s) { result << " " << item; } | ||
return result.str(); | ||
}; | ||
|
||
for (auto const& kv : m_connected_regions) | ||
{ | ||
auto const& prop = kv.second; | ||
|
||
std::ostringstream sub; | ||
sub << "[turns" << set_to_string(prop.unique_turn_ids) | ||
<< "] regions"; | ||
for (auto const& kvs : prop.connected_region_counts) | ||
{ | ||
sub << " { " << kvs.first | ||
<< " : via [" << set_to_string(kvs.second.unique_turn_ids) | ||
<< " ] }"; | ||
} | ||
|
||
std::cout << "REGION " << prop.region_id | ||
<< " " << isolation_to_string(prop.isolated) | ||
<< " " << sub.str() | ||
<< std::endl; | ||
} | ||
|
||
for (std::size_t turn_index = 0; turn_index < m_turns.size(); ++turn_index) | ||
{ | ||
turn_type const& turn = m_turns[turn_index]; | ||
|
||
if (uu_or_ii(turn) && ! turn.is_clustered()) | ||
{ | ||
std::cout << (turn.both(operation_union) ? "UU" : "II") | ||
<< " " << turn_index | ||
<< " (" << geometry::get<0>(turn.point) | ||
<< ", " << geometry::get<1>(turn.point) << ")" | ||
<< " -> " << std::boolalpha | ||
<< " [" << turn.operations[0].seg_id.source_index | ||
<< "/" << turn.operations[1].seg_id.source_index << "] " | ||
<< "(" << turn.operations[0].enriched.region_id | ||
<< " " << turn.operations[0].enriched.isolated | ||
<< ") / (" << turn.operations[1].enriched.region_id | ||
<< " " << turn.operations[1].enriched.isolated << ")" | ||
<< std::endl; | ||
} | ||
} | ||
|
||
for (auto const& key_val : m_clusters) | ||
{ | ||
cluster_info const& cinfo = key_val.second; | ||
std::cout << "CL RESULT " << key_val.first | ||
<< " -> " << cinfo.open_count << std::endl; | ||
} | ||
} | ||
#endif | ||
|
||
void iterate() | ||
{ | ||
#if defined(BOOST_GEOMETRY_DEBUG_TRAVERSAL_SWITCH_DETECTOR) | ||
std::cout << "BEGIN SWITCH DETECTOR (region_ids and isolation)" << std::endl; | ||
std::cout << "BEGIN SWITCH DETECTOR (region_ids and isolation)" | ||
<< (Reverse1 ? " REVERSE_1" : "") | ||
<< (Reverse2 ? " REVERSE_2" : "") | ||
<< std::endl; | ||
#endif | ||
|
||
// Collect turns per ring | ||
|
@@ -608,33 +707,7 @@ struct traversal_switch_detector | |
|
||
#if defined(BOOST_GEOMETRY_DEBUG_TRAVERSAL_SWITCH_DETECTOR) | ||
std::cout << "END SWITCH DETECTOR" << std::endl; | ||
|
||
for (std::size_t turn_index = 0; turn_index < m_turns.size(); ++turn_index) | ||
{ | ||
turn_type const& turn = m_turns[turn_index]; | ||
|
||
if ((turn.both(operation_union) || turn.both(operation_intersection)) | ||
&& ! turn.is_clustered()) | ||
{ | ||
std::cout << (turn.both(operation_union) ? "UU" : "II") | ||
<< " " << turn_index | ||
<< " (" << geometry::get<0>(turn.point) | ||
<< ", " << geometry::get<1>(turn.point) << ")" | ||
<< " -> " << std::boolalpha | ||
<< "(" << turn.operations[0].enriched.region_id | ||
<< " " << turn.operations[0].enriched.isolated | ||
<< ") / (" << turn.operations[1].enriched.region_id | ||
<< " " << turn.operations[1].enriched.isolated << ")" | ||
<< std::endl; | ||
} | ||
} | ||
|
||
for (auto const& key_val : m_clusters) | ||
{ | ||
cluster_info const& cinfo = key_val.second; | ||
std::cout << "CL RESULT " << key_val.first | ||
<< " -> " << cinfo.open_count << std::endl; | ||
} | ||
debug_show_results(); | ||
#endif | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first version did have
prop.isolated == isolation_no
but that is the default, we should not revert all of them into yes.But it now does not look symmetrical, theoretically there should be cases where reversal should be necessary - but we don't have them currently in our test set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reverse one of the test cases? To make sure the other option also gets triggered by test suite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We test all our difference operations in two ways, so both
a - b
andb - a
. If that is what you mean.Or you probably mean (what I call) inverse them, so make a large polygon around a polygon and make the polygon itself an interior of that. Yes, I could do that, I will try to construct a case where this should happen. I now know where I’m looking for. I will do that, but not today.
Thanks.