Unit Test for Primitives
2020-11-09, 16:31 (This post was last modified: 2020-11-09, 17:18 by Lasse Deleuran.)
2020-11-09, 16:31 (This post was last modified: 2020-11-09, 17:18 by Lasse Deleuran.)
I have made automated tests for generated primitives. These are the ones described in LDraw Primitives Reference page. The purpose is primarily to find errors and inconsistencies which we can discuss in this thread.
Methodology
The regular primitives are generated using JS functions. The generated primitives are compared to the official files and any inconsistencies are reported.
Source
My code for testing this can also be used to generate new primitives. The code can be found in this open source JS file with the unit tests being performed by this HTM page. If you don't want to try it locally, then you can see the results hosted here on my website.
Results
Right now the code covers 973 primitives (in /p and /p/48 as well as logo.dat from the unofficial parts). I divide my results into categories as in the Primitive References. There are still a lot of primitives to be tested. See all the "TODO" comments in the JS file and please create pull requests if you want to submit some primitives to be tested. The results are numbered for ease of reference in the comments.
1) Rectilinear primitives
Given that this section also contains non-rectilinear primitives, such as the triangular prisms and boxjcylr.dat, is the name still fitting?
1.1) Two dimensional
All 7 rectangles are tested. No inconsistencies found.
1.2) Three dimensional
1.2.1) Boxes
Most of the inconsistencies found among these primitives should be ignored, as the descriptions make sense when you see the primitives. However. I still wanted to list all that I found:
box.dat: This is the box with all edges and sides. The name is, however, not consistent with the others. A more consistent name would be "Box with 6 faces and All edges".
box3u12.dat: The naming is incorrect. It says "Box with 3 Parallel Faces without Any Edges" but the faces are not parallel.
box4-5a.dat and box4-12.dat are missing from the Primitive Reference.
box4t.dat: This is the only "box4" which says "Adjacent" in the description, which is inconsistent with box4-1.dat, box4-2p.dat, etc.
box2-5.dat, box3u5p.dat and box4-5a.dat are all described "without 5 Edges". However. The missing edges are different in each file.
box2-7.dat and box4-7a.dat are missing the same 7 adjacent edges, but the description of box2-7.dat is not mentioning that they are adjacent.
box2-9.dat and box3-9a are missing the same 9 adjacent edges, but the description of box2-9.dat is not mentioning that they are adjacent.
box3-3.dat is the only box where missing edges are described as "Missing". The others say "without ..."
box3-7a.dat, box3u7a.dat and box4-7a.dat are all described "without 7 Adjacent Edges". However. The missing edges are different in each file.
box3u2p.dat, box4-2p.dat and box5-2p.dat [color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]are all described "without 2 Parallel Edges[/size][/font][/size][/color][color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]". However. The missing edges are different in each file.
[/size][/font][/size][/color]
box4-4a.dat is missing 4 adjacent edges. These are, however, not the same as missing from box3u4a.dat and box5-4a.dat (which are consistent with one another)
1.2.2) Triangular Prisms
tri3-1.dat, tri3-3.dat and tri4.dat are missing from the Primitive Reference.
tri3u1.dat: The missing edge is different than in tri3a1.dat and tri3-1.dat (which as consistent with one another)
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]2) Curved Primitives[/size][/font][/size][/color]
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif][color=#333333][size=small][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]2.1) Two dimensional[/size][/size][/font][/size][/size][/font][/size][/color][/color]
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif][color=#333333][size=small][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]2.1.1) n-fedge.dat[/size][/size][/font][/size][/size][/font][/size][/color][/color]
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif][color=#333333][size=small][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]These are all consistent. Please ignore the comments in the code.[/size][/size][/font][/size][/size][/font][/size][/color][/color]
2.1.2) n-fdisc.dat
No inconsistencies found.
2.1.3) n-fndis.dat
No inconsistencies found.
2.1.4) n-fchrd.dat
The chrd primitives are fairly inconsistent and will require composed polygon comparisons since some of them are constructed using only triangles, while others use quads.
2.1.5) Circular ring segments
1-8ring5.dat: Error found in description. Found 'Ring 5 x 0.25'. Expected 'Ring 5 x 0.125'. Chris is fast-tracking the fix of the official file.
2.2) Three dimensional
2.2.1) Circular cylinders
1-4cyli.dat and 4-4cyli.dat: The control points for the conditional lines are at y=0 rather than y=1, which is the case for any of the other n-fcyli.dat primitives.
7-8cyli.dat and 7-16cyli.dat: The distance to the outer-most control points in these two primitives differ from all the other primitives.
2.2.2) Circular cylinders with Open Ends
No inconsistencies found.
2.2.3) Circular cylinders with Closed Ends
1-4cylc2.dat: There is an additional space before "0.25" in the description: "Cylinder Closed 0.25 without Edges and Conditional Lines".
n-fcylc3.dat files are not mentioned in the Primitive Reference.
2.2.4) Circular cylinders truncated by an angled planes
TODO: These still have to be tested.
2.2.5) Circular cones
TODO Only the 4-4cone primitives are currently tested. No inconsistencies found among them so far.
2.2.6) Circular toruses
TODO Still to be tested
3) Stud group primitives
TODO: The Duplo primitives are not yet tested.
These primitives are sometimes referring directly to studs, such as stug-12x1.dat, while others, such as stug-4x4.dat, are constructed by other stud groups, even though they consist of fewer lines.
Methodology
The regular primitives are generated using JS functions. The generated primitives are compared to the official files and any inconsistencies are reported.
Source
My code for testing this can also be used to generate new primitives. The code can be found in this open source JS file with the unit tests being performed by this HTM page. If you don't want to try it locally, then you can see the results hosted here on my website.
Results
Right now the code covers 973 primitives (in /p and /p/48 as well as logo.dat from the unofficial parts). I divide my results into categories as in the Primitive References. There are still a lot of primitives to be tested. See all the "TODO" comments in the JS file and please create pull requests if you want to submit some primitives to be tested. The results are numbered for ease of reference in the comments.
1) Rectilinear primitives
Given that this section also contains non-rectilinear primitives, such as the triangular prisms and boxjcylr.dat, is the name still fitting?
1.1) Two dimensional
All 7 rectangles are tested. No inconsistencies found.
1.2) Three dimensional
1.2.1) Boxes
Most of the inconsistencies found among these primitives should be ignored, as the descriptions make sense when you see the primitives. However. I still wanted to list all that I found:
box.dat: This is the box with all edges and sides. The name is, however, not consistent with the others. A more consistent name would be "Box with 6 faces and All edges".
box3u12.dat: The naming is incorrect. It says "Box with 3 Parallel Faces without Any Edges" but the faces are not parallel.
box4-5a.dat and box4-12.dat are missing from the Primitive Reference.
box4t.dat: This is the only "box4" which says "Adjacent" in the description, which is inconsistent with box4-1.dat, box4-2p.dat, etc.
box2-5.dat, box3u5p.dat and box4-5a.dat are all described "without 5 Edges". However. The missing edges are different in each file.
box2-7.dat and box4-7a.dat are missing the same 7 adjacent edges, but the description of box2-7.dat is not mentioning that they are adjacent.
box2-9.dat and box3-9a are missing the same 9 adjacent edges, but the description of box2-9.dat is not mentioning that they are adjacent.
box3-3.dat is the only box where missing edges are described as "Missing". The others say "without ..."
box3-7a.dat, box3u7a.dat and box4-7a.dat are all described "without 7 Adjacent Edges". However. The missing edges are different in each file.
box3u2p.dat, box4-2p.dat and box5-2p.dat [color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]are all described "without 2 Parallel Edges[/size][/font][/size][/color][color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]". However. The missing edges are different in each file.
[/size][/font][/size][/color]
box4-4a.dat is missing 4 adjacent edges. These are, however, not the same as missing from box3u4a.dat and box5-4a.dat (which are consistent with one another)
1.2.2) Triangular Prisms
tri3-1.dat, tri3-3.dat and tri4.dat are missing from the Primitive Reference.
tri3u1.dat: The missing edge is different than in tri3a1.dat and tri3-1.dat (which as consistent with one another)
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]2) Curved Primitives[/size][/font][/size][/color]
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif][color=#333333][size=small][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]2.1) Two dimensional[/size][/size][/font][/size][/size][/font][/size][/color][/color]
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif][color=#333333][size=small][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]2.1.1) n-fedge.dat[/size][/size][/font][/size][/size][/font][/size][/color][/color]
[color=#333333][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif][color=#333333][size=small][size=small][size=small][font=Tahoma, Verdana, Arial, sans-serif]These are all consistent. Please ignore the comments in the code.[/size][/size][/font][/size][/size][/font][/size][/color][/color]
2.1.2) n-fdisc.dat
No inconsistencies found.
2.1.3) n-fndis.dat
No inconsistencies found.
2.1.4) n-fchrd.dat
The chrd primitives are fairly inconsistent and will require composed polygon comparisons since some of them are constructed using only triangles, while others use quads.
2.1.5) Circular ring segments
1-8ring5.dat: Error found in description. Found 'Ring 5 x 0.25'. Expected 'Ring 5 x 0.125'. Chris is fast-tracking the fix of the official file.
2.2) Three dimensional
2.2.1) Circular cylinders
1-4cyli.dat and 4-4cyli.dat: The control points for the conditional lines are at y=0 rather than y=1, which is the case for any of the other n-fcyli.dat primitives.
7-8cyli.dat and 7-16cyli.dat: The distance to the outer-most control points in these two primitives differ from all the other primitives.
2.2.2) Circular cylinders with Open Ends
No inconsistencies found.
2.2.3) Circular cylinders with Closed Ends
1-4cylc2.dat: There is an additional space before "0.25" in the description: "Cylinder Closed 0.25 without Edges and Conditional Lines".
n-fcylc3.dat files are not mentioned in the Primitive Reference.
2.2.4) Circular cylinders truncated by an angled planes
TODO: These still have to be tested.
2.2.5) Circular cones
TODO Only the 4-4cone primitives are currently tested. No inconsistencies found among them so far.
2.2.6) Circular toruses
TODO Still to be tested
3) Stud group primitives
TODO: The Duplo primitives are not yet tested.
These primitives are sometimes referring directly to studs, such as stug-12x1.dat, while others, such as stug-4x4.dat, are constructed by other stud groups, even though they consist of fewer lines.