This is a continuation of this thread. The thread pointed out rounding errors in existing primitives. I have briefly discussed the issue with Chris, and what has to be done in order to fix the issue. He proposed that not only are fixed parts submitted, but also all official parts which have to be updated due to the changes.
Primitives are used very often in the LDraw library, so each change to a primitive will be associated with a large amount of affected files.
I encourage separate posts in this thread for each fixed primitive. Each post should contain:
- What the fix of the primitive is.
- An overview of all parts that use the primitive.
- Proposed fix of all parts that use the primitive and are affected.
This is my workflow. If you want to contribute to this, then I recommend using it as a starting point (and please find ways to optimize it, since this is taking a lot of time)
1) Use a primitive generator and tester like this to find a primitive with rounding errors.
2) Manually verify and document the error.
3) Fix the file (and the 8/ and 48/ version as well if affected)
4) Find files that use the primitive (I use "grep -ir primitive.dat ." since I use Linux tools, such as cygwin)
5) Go through each file and check all the points from lines of type 2, 3, 4 and 5. If any point lies next to a fixed point, then that point has to be updated. I have made a tool to find these points. If you are interested, I can share the tool with you. Right now it is a bit too technical to be released.
2021-10-15, 17:54 (This post was last modified: 2021-10-16, 16:31 by Lasse Deleuran.
Edit Reason: Redid the changes to the related files, and fixed point of 1-4ring5.dat files.
)
This post is for fixing 1-4ring5.dat.
The problem with the file was stated in the original thread, and I repost it here for completeness:
1-4ring5.dat consists of quads based on the points from 1-4edge.dat.
The points in 1-4edge.dat are those of the quarter circle with diameter 1:
1 0 0
0.9239 0 0.3827
0.7071 0 0.7071
0.3827 0 0.9239
0 0 1
1-4ring5.dat spans from the quarter circle of diameter 5 to the quarter circle of diameter 6. It consists of the following points:
5 0 0
4.6195 0 1.9135
3.5355 0 3.5355
1.9135 0 4.6195
0 0 5
6 0 0
5.5433 0 2.2961
4.2426 0 4.2426
2.2961 0 5.5433
0 0 6
By scaling the points from 1-4edge.dat with 5 and 6, respectively, we get:
5 0 0
4.6195 0 1.9135
3.5355 0 3.5355
1.9135 0 4.6195
0 0 5
6 0 0
5.5434 0 2.2962
4.2426 0 4.2426
2.2962 0 5.5434
0 0 6
Which differ from the points in the official file where highlighted.
The numbers in 1-4ring5.dat have to be updated as follows:
2.2961 to 2.2962
5.5433 to 5.5434
The file 48/1-4ring5.dat has been updated with the same changes to the points.
The files below all use 1-4ring5.dat or the 48/-version. They are handled as follows:
- Check out where 1-4ring5.dat is used.
- Find any geometries that match up to 1-4ring5.dat.
- Since the corrected points of 1-4ring5.dat are those between the ends, only points that intersect the points between the two ends are relevant for corrections.
The files that have overlaps with 1-4ring5.dat are typically safe, since the overlap hides any corrections made to the points. However. Overlaps should be avoided, as they cause issues for rendering engines. Overlaps are easily detected using Harlequin mode.
Hits s/61904s01.dat on the outside and 3-4cyli.dat on the inside. Since s/61904s01.dat is used twice, and hits a 2-4ring5.dat instead of a 1-4ring5.dat on the second usage, the points therein should not be corrected.
Overlaps 48/1-4rin18.dat on the outside and 1-4rin65.dat on the inside. The overlap in this part should most likely be fixed, but it is not affected by changes to 1-4ring5.dat as is.
Mirrored usages. They hit 1-4ring4.dat on the inside and 1-4cyli.dat on the outside. 1-4ring4.dat has correct points, while 1-4cyli.dat has the correct points, although the control points are unusual with y=0 instead of y=1, which is unconvensional.
File contains overlapping geometries, which should be fixed. 1-4ring5.dat is used in the eyes. However. None of the 26 point misalignments are involving 1-4ring5.dat, so all is OK.
Hits 2359p01.dat on the inside and 48/1-4rin45.dat on the outside of the first usage.
Hits 48/1-4rin65.dat on the inside and 48/1-4rin18.dat on the outside of the second usage. While the usages of 1-4ring5.dat is fine in the file, it does contain overlaps, which should be fixed.
Overlaps several other geometries on the outside, which should be fixed. The file also has BFC errors, which should be fixed. Correcting 48\1-4ring5.dat for now should not be an issue.
Use in upper black collar clip on the right side. Hits 1-4ring6.dat on the outside and 1-4disc.dat on the inside. All OK for 1-4ring5.dat, but the 1-4disc.dat has a T-section on the left, which should be avoided.
Used as the big upper flat area between the studs. Hits 48/1-4cylo.dat on the outside and 48/1-4cylo.dat on the inside as well. That primitive has no incorrect points.
The first usage hits 2-4disc.dat on the inside and quads on the outside. The quads need realignment after fixing 1-4ring5.dat. The other usages hit 2-4disc.dat on the inside and other ring primitives on the outside, which is OK.
The file has 33 misaligned points in the triangles and quads. 3 of these involve 1-4ring5.dat.
The points "4.2426 10.5003 -31.0006" have been changed to "4.2426 10.5003 -31.0006" in the file.
A 4-4ring5.dat should have been used instead. The four prinmitives hit a single 4-4ring4.dat on the inside and four 1-4ring6.dat's on the outside. Here a single 4-4ring6.dat should also have been used instead. All OK from the perspective of 1-4ring5.dat.
Used as the bottom. Hit by quads. Although there are 117 point misalignments in this file, none of them are against the 1-4ring5.dat after correction. That is, the points of the quads are differing less than 0.00005 from those of 1-4ring5.dat.
First usage hits 1-4cyli.dat on the inside and Overlaps with 1-4ring9.dat on the outside. The 1-4ring9.dat also overlaps with yet another geometry on its outside. The owerlaps should be fixed.
Second usage overlaps with 1-4ring9.dat on the outside and 1-4con7.dat on the inside. All OK for 1-4ring5.dat.
All three are symmetrically used. They hit standard primitives on the inside and overlap with standard primitives on the outside. The overlaps should be fixed. Otherwise OK.
First usage hits standard primitives only.
Second usage also hits standard primitives. However, on the outside, it hits and overlaps several standard geometries at the misaligned point. There are no gaps due to the overlaps, but the overlaps should really be removed.
First usage hits only high-res primitived, so all OK.
Second usage hits high-res primitive on the outside and quads and conditional lines on the inside.
There were originally 8 point misalignments in the file due to 48/1-4ring5.dat. However. After the issue by Travis was pointed out, these were found to be false positives. The file remains unchanged.
Used as sleeve ends as pairs, where 2-4ring5.dat should have been used instead.
Hits triangles, quads and lines on both the inside and outside. There are 64 point misalignments due to this, but they all seem to be caused by differing decimal precisions.
The following points have been corrected:
-15.38 8 -10 -> -15.379 8 -10 (4 instances. Going from 2 to 3 decimals)
-15.38 8 -12 -> -15.379 8 -12 (2 instances. Going from 2 to 3 decimals)
The other points are not changed, as they are misaligned on the fourth decimal, where only 3 significant digits are generally used in the file.
Both usages hit standard primitives on the outside and triangles on the inside. There are 12 point misalignments due to differences in significant digits.
The following points are corrected:
-17.619 6.086 -10 -> -17.620 6.087 -10 (2 instances. Fixed rounding on 3rd digit)
-16.535 4.465 -10 -> -16.536 4.465 -10 (2 instances. Fixed rounding on 3rd digit)
17.619 6.086 -10 -> 17.620 6.087 -10 (2 instances. Fixed rounding on 3rd digit)
16.535 4.465 -10 -> 16.536 4.465 -10 (2 instances. Fixed rounding on 3rd digit)
(List of updated points changes after Travis' input)
Notice: Error on buildinginstructions.js display of part title has to be fixed.
The two usages should be replace by a 2-4ring5.dat. They hit standard primitives only. All OK.
Quads are hit. There were 4 point misalignments due to this. These were no longer an issue after the update pointed out by Travis, and the file has been reverted.
The attached file contains at least one set of incorrect rounding.
0.9239 * 6 = 5.5434. Both the current version of the primitive and your proposed fix use 5.5433. I have not checked every single point in the new file to see if it is correct, but the presence of one error means that every single point in the file needs to be re-checked. I don't know how you generated the new file, but if you plan to do this with other primitives, whatever is being done needs to be fixed.
(2021-10-15, 18:20)Travis Cobbs Wrote: The attached file contains at least one set of incorrect rounding.
0.9239 * 6 = 5.5434. Both the current version of the primitive and your proposed fix use 5.5433. I have not checked every single point in the new file to see if it is correct, but the presence of one error means that every single point in the file needs to be re-checked. I don't know how you generated the new file, but if you plan to do this with other primitives, whatever is being done needs to be fixed.
Thanks. The file and related files have been updated accordingly. It took much less time this time around, since I knew where to look. Another positive change: Not as many of the related files have to be updated, compared to what I initially though.
By changing:
2.6788 to 2.6789 (rounding error)
6.4672 to 6.4673 (rounding error)
3.0614 to 3.0616 (rounding error)
7.391 to 7.3912 (missing fourth decimal)
5.6569 to 5.6568 (rounding error)
Notice: Unlike for 1-4ring5.dat, the file 48/1-4ring7.dat already has the correct points!
See analysis of usages of 1-4ring7.dat below:
----------------------------------------------------------------------------
12818.dat currently on the parts tracker. The two usages of 1-4ring7.dat only hit other large primitives (top side of curved section). All OK.
Four usages for the corners of the shell. They only hit other primitives.
Remaining 12 usaages for sound openings. They also only hit other primitives.
All OK.
Two Usages near first cross-axle driver only hit other primitives.
The other two usages are near the second cross-axle driver and similarly only hit other primitives.
All OK.
Usages not only hit primitives. 3 of the 195 point misalignments involve the 1-4ring7.dat instanes. However. The quads involved are nicely aligned to no decimals, and should stay this way. All OK.
The usages only hit other primitives. However. Smaller primitives should have been considered, as there is a lot of unused geometry within the hull of the part.
(2021-10-15, 17:49)Lasse Deleuran Wrote: This is a continuation of this thread. The thread pointed out rounding errors in existing primitives.
Please note that it is generally a bad idea to use floating point arithmetic to get consistent results on different platforms.
Any approach, which do not rely on strict floating point math will result in a different result somewhere else.
JavaScript is a weakly typed language, from the design thought, there are no strict for floating point data types, so the precision error problem is especially prominent.
The Java 17 JDK changed its behaviour and is now using always strict floating point semantics.
For the C#/.net-Framework the problem exists, too.