-
Notifications
You must be signed in to change notification settings - Fork 143
Added segment snapping to the ShapeEditor #132
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
Conversation
|
Thanks for the pull request. We will have a look and merge it soon. |
|
That'd be awesome actually, as I'm also preparing a pull request for MapWindow5 to incorporate this. |
| { | ||
| VARIANT_BOOL visible; | ||
| sf->get_ShapeVisible(id, &visible); | ||
| if (!visible) continue; |
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.
It's best not to treat a VARIANT_BOOL as a bool. Since VARIANT_TRUE is a short integer (-1), and bool is an intrinsic type, you may not always get the expected result. It would be better to say something like
if (visible == VARIANT_FALSE) continue;
This may seem a trivial point, but we've had issues in the past when mixing these types.
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.
I'm pretty new to C and C++, most of the changes were made by looking at other code and copying what I need, thanks for the explanation. Can you point me to a good reference for this in particular?
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.
Here's a pretty good explanation, noting particularly to beware of comparing the various 'true' values:
BOOL vs. VARIANT_BOOL vs. BOOLEAN vs. bool
I should add that being a COM interface, our API needs to use VARIANT_BOOL. However, internally, it is often beneficial to use bool since it is more concise and straightforward. Only convert back to VARIANT_BOOL as necessary.
src/ComHelpers/ShapefileHelper.cpp
Outdated
| // ***************************************************************** | ||
| bool ShapefileHelper::GetClosestPointOnSegment(double ax, double ay, double bx, double by, double px, double py, | ||
| double *rx, double *ry) { | ||
|
|
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.
- It would be helpful to document the variables and intent of this method.
- It's not clear why this is a boolean function since it always returns true and your not using the result. If it can actually fail to get the closest point on the segment, then we should trap that case and return false.
|
|
||
| double projX, projY; | ||
| bool snapped = FindSnapPointCore(x, y, &projX, &projY); | ||
| if (!snapped) { |
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.
Similar to earlier, FindSnapPointCore returns a VARIANT_BOOL, and you're setting it into a bool variable. Either 'snapped' should be changed to VARIANT_BOOL, OR perhaps instead, we should change FindSnapPointCore to return a bool, since it is an internal function and is more easily handled with the standard bool data type.
| this->PixelToProjection(x, y, projX, projY); | ||
|
|
||
| // highlighting of vertices | ||
| if (behavior == ebVertexEditor) |
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.
I have to look further into this - 'behavior' was originally defined (within this block of code) as tkEditorBehavior, but you have redefined it (above) as tkLayerSelection, and assigned the result of get_SnapBehavior. It seems that this test (behavior == ebVertexEditor) may not be giving back the expected result.
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.
Hello @mathijs-dumon
First, I should thank you for submitting this. It will be a nice feature. Additionally, we may be able to optimize the search for nearest snap point by using a GEOS library nearest-point method.
I've done an initial code review and added some comments. I have not yet tested any code, and I will do that soon. You do not need to revise anything; I just wanted to let you see my initial review in case you have any replies to my comments. My next step will be to build the code and probably make some of the suggested changes. This is the first Pull Request that I am reviewing, so the process is new to me.
Regards.
Jerry.
|
Hey @jerryfaust, Thanks for the first review. I'm not familiar with GEOS at all. I did check the QGis implementation which also seemed to use a custom method for it. Performance wise this seemed ok, since the features (to be snapped to) are clipped first to reduce their number. But this is based on limited testing. If you want me to help out, just ask! Mathijs |
|
We use GEOS internally (as does GDAL) for various geospatial operations (e.g. intersection, containment, etc). One thing we're working toward is consistency, so that all of our geospatial operations are done using the same GEOS functions, rather than some of them using GEOS and others using our own algorithms. That's the reasoning behind MWGIS-136. In this way, we will always get consistent results, and we can let the GEOS people focus on optimized algorithms. So you did the right thing by narrowing down the number of shapes to check for snapping, but I think we can go another step further, replacing the algorithm for finding the nearest snap point on each shape (GetClosestSnapPosition), using a function within the GEOS library. |
|
@mathijs-dumon |
|
Hey Jerry, cheers & happy new year, |
143ee96 to
06c9ade
Compare
|
@jerryfaust I've made some changes incorporating most of what you suggested and rebased the branch - can you double check I did not forget anything? |
|
Thanks, @mathijs-dumon, I'll hopefully get to it this weekend. |
|
Hello @mathijs-dumon. I've committed some follow-up changes to the Pull request; some related to the use of VARIANT_BOOL, and take note particularly of the change to Thanks again for the contribution. |
This is an addition I had to make I think you might want to merge into the main project