In Feature Script: Zero need ValueWithUnits when sketching somethings?
yvan_bourassa
Member Posts: 2 ✭✭
Hello Everyone,
I try to sketch circle like this:
I try to sketch circle like this:
precondition
{
annotation { "Name" : "Ring Diameter" }
annotation { "Name" : "Ring Diameter" }
isLength(definition.myRingDiameter, { (millimeter) : [0, 120, 500] } as LengthBoundSpec);
}
var D = definition.myRingDiameter;
var D = definition.myRingDiameter;
skCircle(sketchPINS, "circle1", {
"center" : vector(0 , D/2),
"radius" : definition.myPinDiameter/2
});
this code fail! Precondition of skCircle failed (value.center is undefined || is2dPoint(value.center))
var D = definition.myRingDiameter;
Someone have an explanation, why Zero need units?
this code fail! Precondition of skCircle failed (value.center is undefined || is2dPoint(value.center))
var D = definition.myRingDiameter;
skCircle(sketchPINS, "circle1", {
"center" : vector(0 * millimeter, D/2),
"radius" : definition.myPinDiameter/2
});
this code pass!Someone have an explanation, why Zero need units?
Tagged:
0
Best Answers
-
It needs units because it's a coordinate. X, Y, and Z coordinates are generally nonzero, i.e. the nonzero numerical space is a lot larger than the zero space. So it's more straightforward to just expect them to have units. Otherwise you'd have to program an extra "If" into every function just to check if a value is zero and apply a default unit.
Bottom line is featurescript won't let you be lazy. Variables that generally need units (distance, coordinates, angles, mass, etc) should be explicitly declared with units. It'll keep you out of trouble in the long run. It's no different than declaring a double or integer variable type. Zero is zero right? No, not really. An integer zero doesn't function like a double zero.3 -
Thanks,
0
Answers
-
It needs units because it's a coordinate. X, Y, and Z coordinates are generally nonzero, i.e. the nonzero numerical space is a lot larger than the zero space. So it's more straightforward to just expect them to have units. Otherwise you'd have to program an extra "If" into every function just to check if a value is zero and apply a default unit.
Bottom line is featurescript won't let you be lazy. Variables that generally need units (distance, coordinates, angles, mass, etc) should be explicitly declared with units. It'll keep you out of trouble in the long run. It's no different than declaring a double or integer variable type. Zero is zero right? No, not really. An integer zero doesn't function like a double zero.3 -
If you look at the definition of is2dPoint in vector.fs, it checks that every term in the vector is a length - specifically, it's a ValueWithUnits and it has length units.
This is essentially a data correctness check: even though zero of anything seems like it should be just zero, units are meant to signify *what physical quantity* your datum is. I'd expect that passing 0 degrees to something that expects length would fail, because that input can change. Being too smart about converting one type of zero to another might lead to your feature silently succeeding with a zero input of the wrong type but then mysteriously failing when that changes.
Edit: Mahir beat me to it.
0 -
Thanks,
0


