private static void SplitLargest()
        {
            var largestIndex = 0;
            var largestArea  = 0;

            for (var i = 0; i < quadCount; i++)
            {
                var quad = quads[i];

                if (quad.Area > largestArea)
                {
                    largestIndex = i;
                    largestArea  = quad.Area;
                }
            }

            var first  = new D2dQuad();
            var second = new D2dQuad();

            quads[largestIndex].Split(ref first, ref second);

            quads[largestIndex] = first;

            if (quads.Count > quadCount)
            {
                quads[quadCount] = second;
            }
            else
            {
                quads.Add(second);
            }

            quadCount += 1;
        }
        public static void Fracture(D2dDestructible destructible, int count, float irregularity)
        {
            if (destructible != null && count > 0)
            {
                D2dSplitGroup.ClearAll();
                {
                    var width    = destructible.AlphaWidth;
                    var height   = destructible.AlphaHeight;
                    var mainQuad = new D2dQuad();

                    quadCount  = 1;
                    pointCount = 0;
                    xMin       = 0;
                    xMax       = width - 1;
                    yMin       = 0;
                    yMax       = height - 1;

                    mainQuad.BL = new D2dVector2(xMin, yMin);
                    mainQuad.BR = new D2dVector2(xMax, yMin);
                    mainQuad.TL = new D2dVector2(xMin, yMax);
                    mainQuad.TR = new D2dVector2(xMax, yMax);
                    mainQuad.Calculate();

                    if (quads.Count > 0)
                    {
                        quads[0] = mainQuad;
                    }
                    else
                    {
                        quads.Add(mainQuad);
                    }

                    for (var i = 0; i < count; i++)
                    {
                        SplitLargest();
                    }

                    if (irregularity > 0.0f)
                    {
                        FindPoints();
                        ShiftPoints(irregularity);
                    }

                    for (var i = 0; i < quadCount; i++)
                    {
                        var quad  = quads[i];
                        var group = D2dSplitGroup.GetSplitGroup();

                        group.AddTriangle(quad.BL, quad.BR, quad.TL);
                        group.AddTriangle(quad.TR, quad.TL, quad.BR);
                    }

                    destructible.SplitWhole(D2dSplitGroup.SplitGroups);
                }
                D2dSplitGroup.ClearAll();
            }
        }
        public void Split(ref D2dQuad first, ref D2dQuad second)
        {
            // Vertical split
            if (Size.X > Size.Y)
            {
                var TS = TL + (TR - TL) / 2;
                var BS = BL + (BR - BL) / 2;

                first.BL = BL;
                first.BR = BS;
                first.TL = TL;
                first.TR = TS;

                second.BL = BS;
                second.BR = BR;
                second.TL = TS;
                second.TR = TR;
            }
            // Horizontal split
            else
            {
                var LS = BL + (TL - BL) / 2;
                var RS = BR + (TR - BR) / 2;

                first.BL = LS;
                first.BR = RS;
                first.TL = TL;
                first.TR = TR;

                second.BL = BL;
                second.BR = BR;
                second.TL = LS;
                second.TR = RS;
            }

            first.Calculate();

            second.Calculate();
        }