ocraft / ocraft-s2client

StarCraft II Client - Java library supported on Windows, Linux and Mac designed for building scripted bots and research using the SC2API.
MIT License
55 stars 15 forks source link

Validation of Point/Point2d at construction time #62

Closed Supalosa closed 1 year ago

Supalosa commented 2 years ago

At the moment, the validation that a Point(2d) has a coordinate >= 0 and <= 255 happens at toSc2Api time.

This causes a crash that can sometimes be a bit hard to debug, since there is often no link back to the code that constructed the point.

Would it be reasonable to validate this when the Point2d is constructed, instead? https://github.com/ocraft/ocraft-s2client/blob/master/ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/spatial/Point2d.java#L76

ocraft commented 2 years ago

The reason it was done this way is because Point2d can be used for various calculations and intermediate values may be out of scale, only the final result should be validated.