Ejemplo n.º 1
0
        private double SidePerimeter(LeafPair topLeafPair, LeafPair bottomLeafPair)
        {
            if (LeafPairsAreOutsideJaw(topLeafPair, bottomLeafPair))
            {
                return(0.0);
            }

            // _____         ________
            //      |       |
            // _____|___    |________
            //  +-------|------|---+
            // _|_______|      |___|_

            if (JawTopIsBelowTopLeafPair(topLeafPair))
            {
                return(bottomLeafPair.FieldSize());
            }

            // _|___         ______|_
            //  +---|-------|------+
            // _____|___    |________
            //          |      |
            // _________|      |_____

            if (JawBottomIsAboveBottomLeafPair(bottomLeafPair))
            {
                return(topLeafPair.FieldSize());
            }

            // At this point, the edge between the top and bottom leaf pairs
            // should be fully or partially exposed (depending on the jaw)
            // ___    _______________
            //  +-|--|-------+
            // _|_|__|_______|_______
            //  +-------|----+ |
            // _________|      |_____

            if (LeafPairsAreDisjoint(topLeafPair, bottomLeafPair))
            {
                return(topLeafPair.FieldSize() + bottomLeafPair.FieldSize());
            }

            // ___         __________
            //  +-|-------|--+
            // _|_|___    |__|_______
            //  +-----|------+ |
            // _______|        |_____

            double topEdgeLeft     = Math.Max(Jaw.Left, topLeafPair.Left);
            double bottomEdgeLeft  = Math.Max(Jaw.Left, bottomLeafPair.Left);
            double topEdgeRight    = Math.Min(Jaw.Right, topLeafPair.Right);
            double bottomEdgeRight = Math.Min(Jaw.Right, bottomLeafPair.Right);

            return(Math.Abs(topEdgeLeft - bottomEdgeLeft) +
                   Math.Abs(topEdgeRight - bottomEdgeRight));
        }
Ejemplo n.º 2
0
 private static bool LeafPairsAreDisjoint(LeafPair topLeafPair, LeafPair bottomLeafPair)
 {
     return((bottomLeafPair.Left > topLeafPair.Right) ||
            (bottomLeafPair.Right < topLeafPair.Left));
 }
Ejemplo n.º 3
0
 private bool LeafPairsAreOutsideJaw(LeafPair topLeafPair, LeafPair bottomLeafPair)
 {
     return(topLeafPair.IsOutsideJaw() && bottomLeafPair.IsOutsideJaw());
 }
Ejemplo n.º 4
0
 private bool JawTopIsBelowTopLeafPair(LeafPair topLeafPair)
 {
     return(Jaw.Top <= topLeafPair.Bottom);
 }
Ejemplo n.º 5
0
 private bool JawBottomIsAboveBottomLeafPair(LeafPair bottomLeafPair)
 {
     return(Jaw.Bottom >= bottomLeafPair.Top);
 }