Exemplo n.º 1
0
        /// <summary>
        /// Returns the right-hand quadrant of the halfplane defined by the two quadrants,
        /// or -1 if the quadrants are opposite, or the quadrant if they are identical.
        /// </summary>
        /// <param name="quad1"></param>
        /// <param name="quad2"></param>
        public static Quadrant CommonHalfPlane(Quadrant quad1, Quadrant quad2)
        {
            // if quadrants are the same they do not determine a unique common halfplane.
            // Simply return one of the two possibilities
            if (quad1 == quad2)
            {
                return(quad1);
            }
            int diff = (quad1.Value - quad2.Value + 4) % 4;

            // if quadrants are not adjacent, they do not share a common halfplane
            if (diff == 2)
            {
                return(Quadrant.Undefined);
            }

            var min = (quad1 < quad2) ? quad1 : quad2;
            var max = (quad1 > quad2) ? quad1 : quad2;

            // for this one case, the righthand plane is NOT the minimum index;
            if (min == NW && max == Quadrant.SW)
            {
                return(Quadrant.SW);
            }
            // in general, the halfplane index is the minimum of the two adjacent quadrants
            return(min);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Returns whether this quadrant lies within the given halfplane (specified
 /// by its right-hand quadrant).
 /// </summary>
 /// <param name="halfPlane"></param>
 public bool IsInHalfPlane(Quadrant halfPlane)
 {
     if (halfPlane == SE)
     {
         return(this == SE || this == SW);
     }
     return(this == halfPlane || Value == halfPlane.Value + 1);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Returns true if the quadrants are 1 and 3, or 2 and 4.
        /// </summary>
        /// <param name="quad">A quadrant</param>
        public bool IsOpposite(Quadrant quad)
        {
            if (this == quad)
            {
                return(false);
            }
            int diff = (Value - quad.Value + 4) % 4;

            // if quadrants are not adjacent, they are opposite
            if (diff == 2)
            {
                return(true);
            }
            return(false);
        }