Skip to content

Commit db5dfbc

Browse files
committed
finish using-solid-node documentation
1 parent db54a71 commit db5dfbc

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

docs/using-solid-node.rst

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ it to the base classes of the root node at `root/__init__.py`:
229229
class SimpleClock(AssemblyNode, TestCaseMixin):
230230
231231
TestCaseMixin
232-
.............
232+
-------------
233233

234234
Now we'll add tests to our root node. Our SimpleClock
235235
class will extend `solid_node.test.TestCaseMixin` and
@@ -263,27 +263,29 @@ run `solid root test`.
263263

264264
You should see two tests failing, as in practice there is a very
265265
small intersection between rendered meshes even though matematically
266-
they should not. Let's reduce the radius of our pin to 2.9, at
266+
they should not. Let's reduce the radius of our pin to 2.99, at
267267
`root/pin.py`:
268268

269269
.. code-block:: python
270270
271271
class Pin(Solid2Node):
272272
273273
def render(self):
274-
return cylinder(r=2.9, h=20)
274+
return cylinder(r=2.99, h=20)
275275
276276
Run the tests again. This time, the two tests will pass.
277-
If you look closely, the cylinder of the pins are not really round.
278-
They are an approximation. This is because internally STLs are generated
279-
for the models.
280277

281278
@testing_steps
282-
..............
283-
The tests are passing, the pieces are not intersecting. But would they still
284-
not intersect during the rotation of the pointer? The test we made just
285-
tested the situation for the initial setup. We can improve the test
286-
by using the decorator `solid_node.test.testing_steps`:
279+
--------------
280+
281+
Even though the test has passed, if you look closely, the hole in pointer
282+
and the pin are not really round, they are approximated by hexagons.
283+
This is because internally STLs are generated for the models, and STLs
284+
work with triangles. We have tested that in the initial setup the pieces
285+
do not overlap, but our test can't tell yet if the parts can freely move.
286+
287+
By using the decorator `@testing_steps`, we can test the intersection of
288+
pieces in several moments of the animation:
287289

288290
.. code-block:: python
289291
@@ -293,13 +295,45 @@ by using the decorator `solid_node.test.testing_steps`:
293295
class SimpleClock(AssemblyNode, TestCaseMixin):
294296
...
295297
296-
@testing_steps(3, end=0.1)
298+
@testing_steps(16)
297299
def test_pin_runs_free_in_base(self):
298300
self.assertNotIntersecting(self.base, self.pin)
299301
300-
@testing_steps(3, end=0.1)
302+
@testing_steps(16)
301303
def test_pin_runs_free_in_pointer(self):
302304
self.assertNotIntersecting(self.pointer, self.pin)
303305
304-
The tests above will run three times, at three different instants,
305-
from time 0 to 0.1.
306+
The tests above will each test run 32 times, at 32 different instants.
307+
Run the tests again, and you'll see that the tests will pass and fail
308+
in a pattern.
309+
310+
Running tests on the full animation cycle can be very time consuming.
311+
We can keep test performance by applying the test to a slice of time
312+
313+
.. code-block:: python
314+
315+
@testing_steps(4, end=0.125)
316+
def test_pin_runs_free_in_base(self):
317+
self.assertNotIntersecting(self.base, self.pin)
318+
319+
fn property
320+
===========
321+
322+
You see that our tests are passing on the base, but not in the pointer,
323+
as base is very roundly rendered. That's because CadQuery exports STL
324+
files with more precision.
325+
326+
We can achieve that in `Soli2Node` nodes by setting the property `fn`
327+
in the nodes `pin.py` and `pointer.py`, as the example below:
328+
329+
.. code-block:: python
330+
331+
class Pointer(Solid2Node):
332+
333+
fn = 256
334+
335+
Now you see the pin and hole seem more round, and the 0.01 margin
336+
we put is enough to make the tests pass.
337+
338+
You should take in consideration the approximation error on holes
339+
when using Openscad derived nodes, like `Solid2Node` and `OpenScadNode`

0 commit comments

Comments
 (0)