Here's my pseudocode for all three parts of P24. This is not tested and may not be the best way, but I think the approach is solid.
x
1""" Return zero, one, or two triangles that result from clipping
2triangle abc with the x=1 plane."""
3function clip_positive_x(a::Vec3, b::Vec3, c::Vec3)
4 function in(v) = v[1] > 1 # helper - is v inside the x<1 half-space?
5 n_in = length([in(v) for v in (a, b, c)])
6
7 if n_in == 3
8 return a, b, c # case 1 - all in
9 elseif n_in == 0
10 return nothing # case 2 - all out
11 elseif n_in == 1
12 # case 3 - one in, two out; one triangle results
13
14 # yuck, need to handle different cases of which vertex is in; let's simplfiy:
15 # roll until the "in" vertex is a
16 while !in(a)
17 # if we were doing this for real, we might want to also keep track of
18 # how many times we rolled so we could return new vertices where the one
19 # inside is in the same position (i.e., "a" remains "a" if that one was
20 # inside); I'll gloss over this bookkeeping here
21 a, b, c = b, c, a # keep them in ccw order
22 end
23 bprime = int_x1(a, b)
24 cprime = int_x1(a, c)
25 return a, bprime, cprime
26 elseif n_in == 2
27 # similar procedure as above to get a and b to be the "in" vertices
28 while in(c)
29 a, b, c = b, c, a
30 end
31 ac = int_x1(a, c)
32 bc = int_x1(b, c)
33 return [(a, b, ac), (b, bc, ac)]
34 end
35end
36
37""" return where the line from p to q intersects the x = 1 plane """
38function int_x1(p, q)
39 qp = q-p
40 # phrase this as a ray: q + t (q-p)
41 # derive the t value:
42 #p.x + t * qp.x = 1
43 #t = (1 - p.x) / qp.x
44 t = (1 - p[1]) / qp[1]
45 return p + t * qp
46end