i also don't do it inline with triangulation, but compute with tl,pl, nl and next draw the 3Dfaces. Thus avoiding removing (searching) and replacing entities.
To find the first triangle of a constraint is use this method (see code as posted earlier), with larger sets this will be probably much faster then triloc because the triangle search list is reduced to in most cases a few triangles.
I add intersection points to the triangulation and thus only remove triangles and modify tl, pl, el instead of complete rebuilding it.
I build cdtl based on vertices only, vertices + points or points only.
It seems to be very stable, even with 'bad' data sets (duplicate points, constraints etc). However with duplicate 2D constraints but different Z you can get a bad result, but garbage in = garbage out.
But also still need to fix a bug when a vertex of a constraint is colinear within another constraint. But this will probably be solved when verifying for constraint intersections, which is needed in any way.
I'll post complete code when cleaned up and optimized.
(defun addedge_xxl
(a b / pnr tl_r pl_a tl_a el_a el_r ac bc ls v ip z cnt tr)
;;;last point position in pl
(setq pnr (- (length pl) 1)
;;;triangle list that will be removed
tl_r nil
;;;point list that will be added
pl_a nil
;;;triangle list that will be added
tl_a nil
;;;coordinates of point a, first point of constraint
ac (nth a pl)
;;;coordinates of point a, second point of constraint
bc (nth b pl)
)
;;; skip null length constraints both 2D and 3D
(if (> (distance ac bc) 0.001)
(progn
;;; reduce tl to ls that have connection with point a of the constraint
(setq ls (vl-remove-if-not
'vl-consp
(mapcar '(lambda (x)
(if (member a x)
x
)
)
tl
)
)
)
;;;counter for position in ls
(setq cnt 0)
;;;loop ls until intersection with opposed edge of point a is found
(while (not ip)
(setq trr (nth cnt ls))
;;;opposed edge to point a
(if (= (vl-position a trr) 1)
(setq v (reverse (vl-remove a trr)))
(setq v (vl-remove a trr))
)
;;;search for intersection of constraint a-b with the triangle edge opposed to point a
(if (setq ip (inters (list (car ac) (cadr ac))
bc
(nth (car v) pl)
(nth (cadr v) pl)
t
)
)
(progn
;;;add trr to remove list
(setq tl_r (cons trr tl_r))