-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Background
https://www.steptools.com/stds/step/IS_final_p21e3.html#clause-6-4-2 defines the REAL data type as follows:
The encoding shall consist of a decimal mantissa optionally followed by a decimal exponent. The decimal mantissa consists of an optional plus sign "+" or minus sign "-", followed by a sequence of one or more digits, followed by a full stop ".", followed by a sequence of zero or more digits. A decimal exponent consists of the latin capital letter E optionally followed by a plus sign "+" or minus sign "-", followed by one or more digits.
In particular, this is given as an invalid example:
| Invalid real expressions | Problem |
|---|---|
| 1E05 | Decimal point required in mantissa |
Issue/Example
However, this invalid example is exactly the way that steputils formats coordinates. For example:
#1177=CARTESIAN_POINT('Vertex',(1.84999999998,5.70100354408,7.80860104192)) ; becomes #1177=CARTESIAN_POINT('Vertex',(-2E-11,5.70100354408,7.80860104192)); when executing the following code:
for ref, currentEntity in stepfile.data[0].instances.copy().items():
if isinstance(currentEntity, p21.SimpleEntityInstance) == True:
if currentEntity.entity.name == "CARTESIAN_POINT":
newPosX = Decimal('-1.85')
newCartesianParameters = [currentEntity.entity.params[0], [newPosX, currentEntity.entity.params[1][1], currentEntity.entity.params[1][2]]]
stepfile.data[0].add(p21.simple_instance(currentEntity.ref, name=currentEntity.entity.name, params=newCartesianParameters))
Possible mitigations and workarounds
- Using simple float for
newPosXinstead of Decimal does not solve the issue. - Using string formatting like
newPosX = f"{newPosX:f}"does produce valid REAL presentation, but inside a string (which is of course not valid). The output in the example would be as follows:#1177=CARTESIAN_POINT('Vertex',('-0.00000000002',5.70100354408,7.80860104192)); - For now, I will probably post-process the produced file, adding ".0" before every "E" without decimal point before it. However, this doesn't solve the issue, that the library in itself produces invalid STEP files.