package com.exh.bevel.algo; import com.exh.bevel.support.QuadEntry; import com.exh.bevel.support.QuadList; import com.exh.bevel.support.Spotlight; import com.exh.math.primitive.Quad; /* The main loop for cutting each quad at its point of intersection. */ public final class QuadClipper { private final QuadList mPool = new QuadList(); private final QuadClipList mSlices = new QuadClipList(); // Find all intersections, chop them at the dividing line. public void on( final QuadList cmp, final double z, final Spotlight spot, final QuadList quadOut) { // Step over each element of src, duplicating and // running against the src list. Duplicated results // are pushed into the output. QuadEntry src = cmp.head(); while (src != null) { mSlices.start(src.mQ); QuadEntry dst = cmp.head(); while (dst != null) { if (src != dst && src.overlaps(dst)) { // Subtract the dst quad from the src mSlices.slice(dst.mQ, spot); } dst = dst.mNext; } // Create new quads out of the subtraction results. mSlices.results(quadOut, mPool); src = src.mNext; } // Once all quads are generated, set the interior z, 'cause // that's sorta the point. QuadEntry dst = quadOut.head(); while (dst != null) { final Quad a = dst.mQ; a.mPt[1].z = z; a.mPt[2].z = z; dst = dst.mNext; } } }