-
Notifications
You must be signed in to change notification settings - Fork 44
fix(Model): remove valid check from add method #292
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
base: master
Are you sure you want to change the base?
fix(Model): remove valid check from add method #292
Conversation
Add(GeoObjectList... & Add(IEnumerable<IGeoObject>... both dont check for this, and a model can contain invalid geometries anyway.
|
Thanks for opening this and explaining the motivation behind removing the HasValidData check on Add(IGeoObject…). I agree that something about this should be addressed, especially since the other overloads (Add(GeoObjectList…), Add(IEnumerable…)) don’t behave the same way. That said, I’m not really in favor of removing the check entirely. It was likely added for a reason, and removing it outright might reintroduce subtle issues unless we’re sure it’s safe. Consistency between overloads is important, but so is maintaining the intended safeguards. I think a better approach could be to align the behavior between the different Add methods while still trying to keep the model clear of invalid data. That way we can make the behavior predictable without losing the integrity checks that are there for a reason. |
|
@dsn27 That would still allow invalid geometries in the If you would still like to keep the check, could we add a |
|
This "HasValidData()" has been introduced to avoid interactive construction of "invalid" GeoObjects. You can for example draw a line with identical start- and endpoint. And this line will not be added to the Model because of this HasValidData() check. It should be the responsibility of the interactive ConstructActions (and there are many) not to call Model.Add when the constructed object is kind of invalid (circle with radius 0, path where the segments are not connected). And I don't know, whether such an object could cause an exception somewhere else. Of course using the Model.Add from your code, it is your responsibility to add well behaving objects only. I tested this by drawing such a line and it would have been added if it had not been rejected by HasValidData(). Not all GeoObjects implement HasValidData, so this is not consistent anyhow. |
Hello. While i get this, silently dropping the .Add operation is probably the most fragile way of dealing with invalid data. I would be fine with keeping the check but at least throw an exception. The application should NOT call .Add if the geo is invalid (because it has to know currently that the geo is not ending up in the List because its invalid in the first place). |
|
@dsn27 @SOFAgh I can see that a construction shouldn't add invalid geometries, but that doesn't prevent the model from containing invalid geometries, since the user can always make a line invalid by editing the data in the property editor. The check in the |
|
In my view, this is a minor problem. you would have to check in |
|
I agree, it is a minor problem. We just think it is strange internal / blackbox behavior that users of the library don't expect. If I call .Add(...), I either expect the add to happen or an exception if the library has any complaints about the item about to be added. In no case I expect a silent drop of the .Add(...) operation. If this PR doesn't go thru, we will simply use |

I would like to remove the
HasValidDatacheck from theAdd(IGeoObject...method on the model.Add(GeoObjectList...&Add(IEnumerable<IGeoObject>...both don't check for this. The Model can contain invalid geometries anyway, so this check just leads to unexpected behavior.