jscad / csg.js

DEPRECATED: CSG Library for JSCAD (See the link below)
https://github.com/jscad/OpenJSCAD.org/tree/master/packages/modeling
MIT License
218 stars 56 forks source link

Add validation of input for all basic operations #56

Closed kaosat-dev closed 4 years ago

kaosat-dev commented 7 years ago

Right now it is possible to do for example csg.translate([0,0, undefined]) which will not throw any error but result in an extreme memory consumption

z3dev commented 7 years ago

Here's my take....

Math objects should never check so that performance is maximized. No checks on arguments, order, values, etc. the calling function should be creating these objects 100% correctly.

We can have "check" routines for developers to call, which validate the Math objects for use with the calculations. For example, validatePolygon(), etc.

I think this should also apply to constructor functions of higher level classes as well. Once again, the calling functions should create 100%'valid objects with 100% valid arguments. We can add "check" routines for the complex objects as well.

For the convince routiness, like circle(), these functions should check arguments. These convince routines must create 100% pure objects for further use.

z3dev commented 7 years ago

High level object operations such as translate(), rotate(), etc should check arguments. We expect users (not developers) to call these functions.

z3dev commented 7 years ago

To throw or not throw (return default).... we should decide and be consistent.

z3dev commented 7 years ago

By the way, I want to trash Side, and replace with Line2D. Maybe you can do this while adding color to CAG.

And Line2D / Line3D need properties such as color, width, style, etc.

kaosat-dev commented 7 years ago

ughh too much to do ! but this

High level object operations such as translate(), rotate(), etc should check arguments

YES !!! the fact that it can fail this way in the first place is bad bad bad ! I spent 2 hours debugging some code until I figured this out.

On any invalid input, even a slight error => throw!!! that is the only way to make sure nothing fails silently (which take a ton of time to figure out) : the errors need to be visible to users , and that is the only way to ensure that in a nice way

About Line2D/Line3D : actually it is a bit more complex than that: we need abstractions for paths, bezier etc, sides can be replaced with arrays etc, let's open another issue

z3dev commented 4 years ago

V2 API has been improved to validate parameters and THROW errors.

Closing this issue.