@@ -16,14 +16,16 @@ the mesh that contains the indices of the planes where each triangle lies.
1616
1717# Example
1818```jldoctest output=false
19- julia> import ColorTypes: RGB
19+ julia> import ColorTypes: RGB;
2020
2121julia> mesh = Rectangle(length = 1.0, width = 1.0);
2222
2323julia> slice!(mesh, Y = collect(-0.25:0.25:0.5), Z = collect(0.25:0.25:1));
2424
2525julia> add_property!(mesh, :colors, rand(RGB));
2626
27+ julia> using PlantViz;
28+
2729julia> render(mesh, wireframe = true);
2830```
2931"""
@@ -126,9 +128,11 @@ A tuple containing:
126128
127129# Example
128130```jldoctest
131+ julia> import PlantGeomPrimitives as PG;
132+
129133julia> m = Rectangle(length = 1.0, width = 1.0);
130134
131- julia> check_intersection(m, 1, 2, 0.5, 1);
135+ julia> PG. check_intersection(m, 1, 2, 0.5, 1);
132136```
133137"""
134138function check_intersection (m:: Mesh , t:: Integer , i:: Integer , h:: Real , j:: Integer )
@@ -207,12 +211,14 @@ The next vertex index in the sequence (1, 2, or 3).
207211
208212# Example
209213```jldoctest
210- julia> next(1);
211- 2
212- julia> next(2);
213- 3
214- julia> next(3);
215- 1
214+ julia> import PlantGeomPrimitives as PG;
215+
216+ julia> PG.next(1);
217+
218+ julia> PG.next(2);
219+
220+ julia> PG.next(3);
221+
216222```
217223"""
218224next (i:: Integer ) = mod (i,3 ) + 1
@@ -238,10 +244,16 @@ A tuple containing the updated slice indices for the two new triangles created f
238244
239245# Example
240246```jldoctest
247+ julia> import PlantGeomPrimitives as PG;
248+
241249julia> mesh = Rectangle(length = 1.0, width = 1.0);
242- julia> update_edges!(mesh);
243- julia> nverts_before = length(vertices(mesh))
244- julia> one_triangle_intersection!(mesh, 1, 2, 0.5, 1, [1,1,1], 2, [1, -1, -1]);
250+
251+ julia> PG.update_edges!(mesh);
252+
253+ julia> nverts_before = length(vertices(mesh));
254+
255+ julia> PG.one_triangle_intersection!(mesh, 1, 2, 0.5, 1, [1,1,1], 2, [1, -1, -1]);
256+
245257julia> nverts_after = length(vertices(mesh));
246258```
247259"""
@@ -288,20 +300,23 @@ Intersect a triangle with a plane, create two new triangles, and add them to the
288300- `s`: The signs of the distances to the plane for each vertex.
289301
290302# Returns
291- A tuple containing the updated slice indices for the three new triangles created
303+ A tuple containing the updated slice indices for the three new triangles created
292304from the intersection.
293305
294306# Example
295307```jldoctest
308+ julia> import PlantGeomPrimitives as PG;
309+
296310julia> mesh = Rectangle(length = 1.0, width = 1.0);
297311
298- julia> update_edges!(mesh);
312+ julia> PG. update_edges!(mesh);
299313
300- julia> nverts_before = length(vertices(mesh))
314+ julia> nverts_before = length(vertices(mesh));
301315
302- julia> two_triangle_intersections!(mesh, 1, 2, 0.5, 1, [1,1,1], 2, [1, -1, -1]);
316+ julia> PG. two_triangle_intersections!(mesh, 1, 2, 0.5, 1, [1,1,1], 2, [1, -1, -1]);
303317
304318julia> nverts_after = length(vertices(mesh));
319+
305320```
306321"""
307322function two_triangle_intersections! (mesh, t, i, h, vi, slindex, j, s)
@@ -356,13 +371,15 @@ The 3D coordinates of the intersection point.
356371
357372# Example
358373```jldoctest
374+ julia> import PlantGeomPrimitives as PG;
375+
359376julia> vs = [Vec(0.0, 0.0, 0.0), Vec(1.0, 0.0, 0.0), Vec(0.0, 1.0, 0.0)];
360377
361378julia> es = [vs[2] - vs[1], vs[3] - vs[2], vs[3] - vs[1]]; # Examples: intersect the triangle with the plane x = 0.5, using vertex 1 as the reference
362379
363- julia> one_intersection_point(1, 0.5, 3, es, vs); # Intersection point between the plane and the edge opposite to vertex 1
380+ julia> PG. one_intersection_point(1, 0.5, 3, es, vs); # Intersection point between the plane and the edge opposite to vertex 1
364381
365- julia> one_intersection_point(1, 0.5, 2, es, vs); # Intersection point between the plane and the edge opposite to vertex 2
382+ julia> PG. one_intersection_point(1, 0.5, 2, es, vs); # Intersection point between the plane and the edge opposite to vertex 2
366383```
367384"""
368385function one_intersection_point (i, h, vi, es, vs)
@@ -398,21 +415,23 @@ A tuple containing the 3D coordinates of the two intersection points.
398415
399416# Example
400417```jldoctest
418+ julia> import PlantGeomPrimitives as PG;
419+
401420julia> vs = [Vec(0.0, 0.0, 0.0), Vec(1.0, 0.0, 0.0), Vec(0.0, 1.0, 0.0)];
402421
403422julia> es = [vs[2] - vs[1], vs[3] - vs[2], vs[1] - vs[3]]; # Examples: intersect the triangle with the plane x = 0.5, using vertex 1 as the reference
404423
405- julia> two_intersection_points(1, 0.5, 3, es, vs); # Intersection points between the plane and the edges opposite to vertex 1
424+ julia> PG. two_intersection_points(1, 0.5, 3, es, vs); # Intersection points between the plane and the edges opposite to vertex 1
406425
407- julia> two_intersection_points(1, 0.5, 2, es, vs); # Intersection points between the plane and the edges opposite to vertex 2
426+ julia> PG. two_intersection_points(1, 0.5, 2, es, vs); # Intersection points between the plane and the edges opposite to vertex 2
408427```
409428"""
410429function two_intersection_points (i, h, vi, es, vs)
411430 @inbounds begin
412431 # Choose barycentric coordinate system
413432 vi == 1 && begin vr, e1, e2 = (vs[1 ], es[1 ], es[2 ]) end
414- vi == 2 && begin vr, e1, e2 = (vs[2 ], .- es[3 ], .- es[1 ]) end
415- vi == 3 && begin vr, e1, e2 = (vs[3 ], .- es[2 ] , es[3 ]) end
433+ vi == 2 && begin vr, e1, e2 = (vs[2 ], .- es[3 ], .- es[1 ]) end
434+ vi == 3 && begin vr, e1, e2 = (vs[3 ], .- es[2 ] , es[3 ]) end
416435 # Calculate the barycentric coordinate on each axis
417436 # and from that the 3D coordinate of intersection point
418437 d = (h - vr[i])/ e1[i]
0 commit comments