Example #1
0
        /// <summary>
        /// Perform a difference between the path of two loops.
        /// </summary>
        /// <remarks>This function assumes the left and right loops have only one
        /// path that's a closed island.</remarks>
        /// <param name="left">The island being subtracted from.</param>
        /// <param name="right">The island being subtracted.</param>
        /// <param name="onIslA">A node that's on the island, or null if no geometry
        /// is left afterwards.</param>
        public static void Difference(
            BLoop left,
            BLoop right,
            out BNode onIslA)
        {
            // we always remove B, which may contain extra stuff from
            // subtraction shapes that didn't find a target to remove.
            PerIslandBoolean(
                left,
                right,
                Difference,
                out onIslA,
                true);

            right.Clear();
            RemoveLoop(right, true);
        }
Example #2
0
        /// <summary>
        /// Perform an intersection operation between two islands using a reflow strategy.
        /// </summary>
        /// <param name="left">The collection of islands for the operation.</param>
        /// <param name="right">The other collection of islands for the operation.</param>
        /// <param name="onIslA">An output node that exists on the remaining path(s).</param>
        /// <param name="removeRight">If true, remove the contents of the right loop parameter after
        /// the operation.</param>
        public static void Intersection(BLoop left, BLoop right, out BNode onIslA, bool removeRight)
        {
            onIslA = null;
            // Sanity check on geometry, try to union each loop with its islands
            // so there's no overlapping regions within them.

            List <BNode> rightIslands = right.GetIslands();

            if (rightIslands.Count >= 2)
            {
                for (int i = 1; i < rightIslands.Count; ++i)
                {
                    List <BNode> RSegsA = new List <BNode>(rightIslands[0].Travel());
                    List <BNode> RSegsB = new List <BNode>(rightIslands[i].Travel());

                    Union(right, RSegsA, RSegsB, out onIslA, true);
                }
            }

            List <BNode> leftIslands = left.GetIslands();

            if (leftIslands.Count >= 2)
            {
                for (int i = 1; i < leftIslands.Count; ++i)
                {
                    List <BNode> LSegsA = new List <BNode>(leftIslands[0].Travel());
                    List <BNode> LSegsB = new List <BNode>(leftIslands[i].Travel());

                    Union(right, LSegsA, LSegsB, out onIslA, true);
                }
            }

            leftIslands  = left.GetIslands();
            rightIslands = right.GetIslands();

            foreach (BNode leftIsl in leftIslands)
            {
                List <BNode> leftIslandSegs = new List <BNode>(leftIsl.Travel());
                foreach (BNode rightIsl in rightIslands)
                {
                    List <BNode> rightIslandSegs = new List <BNode>(rightIsl.Travel());

                    Intersection(
                        left,
                        leftIslandSegs,
                        rightIslandSegs,
                        out onIslA);
                }
            }

            foreach (BNode bn in leftIslands)
            {
                bn.RemoveIsland(false);
            }

            foreach (BNode bn in rightIslands)
            {
                bn.RemoveIsland(false);
            }

            // TODO: For each island left, we need to see if there's
            // any shapes being fully contained by the other side.

            if (removeRight == true)
            {
                right.Clear();
                RemoveLoop(right, true);
            }
        }