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 clipping2triangle 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 == 38 return a, b, c # case 1 - all in9 elseif n_in == 010 return nothing # case 2 - all out11 elseif n_in == 112 # case 3 - one in, two out; one triangle results13 14 # yuck, need to handle different cases of which vertex is in; let's simplfiy:15 # roll until the "in" vertex is a16 while !in(a)17 # if we were doing this for real, we might want to also keep track of18 # how many times we rolled so we could return new vertices where the one19 # inside is in the same position (i.e., "a" remains "a" if that one was20 # inside); I'll gloss over this bookkeeping here21 a, b, c = b, c, a # keep them in ccw order22 end23 bprime = int_x1(a, b)24 cprime = int_x1(a, c)25 return a, bprime, cprime26 elseif n_in == 227 # similar procedure as above to get a and b to be the "in" vertices28 while in(c)29 a, b, c = b, c, a30 end31 ac = int_x1(a, c) 32 bc = int_x1(b, c)33 return [(a, b, ac), (b, bc, ac)]34 end35end3637""" return where the line from p to q intersects the x = 1 plane """38function int_x1(p, q)39 qp = q-p40 # phrase this as a ray: q + t (q-p)41 # derive the t value:42 #p.x + t * qp.x = 143 #t = (1 - p.x) / qp.x44 t = (1 - p[1]) / qp[1]45 return p + t * qp46end