/// <summary>
        ///  Compares two <see cref="Coordinate" />s for their relative position along a segment
        /// lying in the specified <see cref="Octant" />.
        /// </summary>
        /// <param name="octant"></param>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        /// <returns>
        /// -1 if node0 occurs first, or
        ///  0 if the two nodes are equal, or
        ///  1 if node1 occurs first.
        /// </returns>
        public static int Compare(OctantDirection octant, Coordinate p0, Coordinate p1)
        {
            // nodes can only be equal if their coordinates are equal
            if (p0.Equals2D(p1))
                return 0;

            int xSign = RelativeSign(p0.X, p1.X);
            int ySign = RelativeSign(p0.Y, p1.Y);

            switch (octant)
            {
                case OctantDirection.Zero:
                    return CompareValue(xSign, ySign);
                case OctantDirection.One:
                    return CompareValue(ySign, xSign);
                case OctantDirection.Two:
                    return CompareValue(ySign, -xSign);
                case OctantDirection.Three:
                    return CompareValue(-xSign, ySign);
                case OctantDirection.Four:
                    return CompareValue(-xSign, -ySign);
                case OctantDirection.Five:
                    return CompareValue(-ySign, -xSign);
                case OctantDirection.Six:
                    return CompareValue(-ySign, xSign);
                case OctantDirection.Seven:
                    return CompareValue(xSign, -ySign);
            }
            throw new InvalidOctantException(octant.ToString());
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SegmentNode"/> class.
 /// </summary>
 /// <param name="segString"></param>
 /// <param name="coord"></param>
 /// <param name="segmentIndex"></param>
 /// <param name="segmentOctant"></param>
 public SegmentNode(SegmentString segString, Coordinate coord, int segmentIndex, OctantDirection segmentOctant)
 {
     Coordinate     = new Coordinate(coord);
     SegmentIndex   = segmentIndex;
     _segmentOctant = segmentOctant;
     _isInterior    = !coord.Equals2D(segString.GetCoordinate(segmentIndex));
 }
示例#3
0
        /// <summary>
        /// Converts a OctantDirection value to a normalized Vector2.
        /// </summary>
        /// <param name="direction">OctantDirection value to convert.</param>
        /// <returns>A normalized Vector2 instance.</returns>
        public static Vector2 DirectionToVector(OctantDirection direction)
        {
            switch (direction)
            {
            case OctantDirection.Up:
                return(new Vector2(0.0f, -1.0f));

            case OctantDirection.UpLeft:
                return(new Vector2(-_inverseSqrt2, -_inverseSqrt2));

            case OctantDirection.UpRight:
                return(new Vector2(_inverseSqrt2, -_inverseSqrt2));

            case OctantDirection.Down:
                return(new Vector2(0.0f, 1.0f));

            case OctantDirection.DownLeft:
                return(new Vector2(-_inverseSqrt2, _inverseSqrt2));

            case OctantDirection.DownRight:
                return(new Vector2(_inverseSqrt2, _inverseSqrt2));

            case OctantDirection.Left:
                return(new Vector2(-1.0f, 0.0f));

            case OctantDirection.Right:
                return(new Vector2(1.0f, 0.0f));

            default:
                return(Vector2.Zero);
            }
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SegmentNode"/> class.
 /// </summary>
 /// <param name="segString"></param>
 /// <param name="coord"></param>
 /// <param name="segmentIndex"></param>
 /// <param name="segmentOctant"></param>
 public SegmentNode(SegmentString segString, Coordinate coord, int segmentIndex, OctantDirection segmentOctant)
 {
     Coordinate = new Coordinate(coord);
     SegmentIndex = segmentIndex;
     _segmentOctant = segmentOctant;
     _isInterior = !coord.Equals2D(segString.GetCoordinate(segmentIndex));
 }
        /// <summary>
        /// Direction of right thumbstick position on a particular player's gamepad.
        /// </summary>
        /// <param name="player">Player whose gamepad will be checked.</param>
        /// <returns>OctantDirection indicating right thumbstick direction.</returns>
        public static OctantDirection GetGamePadRightThumbStickOctantDirection(this InputManager inputManager, PlayerIndex player)
        {
            OctantDirection direction = OctantDirection.None;

            if (_currentGamePadStates[player].IsConnected)
            {
                direction = _currentGamePadStates[player].ThumbSticks.Right.ToOctantDirection();
            }

            return(direction);
        }
        /// <summary>
        ///  Compares two <see cref="Coordinate" />s for their relative position along a segment
        /// lying in the specified <see cref="Octant" />.
        /// </summary>
        /// <param name="octant"></param>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        /// <returns>
        /// -1 if node0 occurs first, or
        ///  0 if the two nodes are equal, or
        ///  1 if node1 occurs first.
        /// </returns>
        public static int Compare(OctantDirection octant, Coordinate p0, Coordinate p1)
        {
            // nodes can only be equal if their coordinates are equal
            if (p0.Equals2D(p1))
            {
                return(0);
            }

            int xSign = RelativeSign(p0.X, p1.X);
            int ySign = RelativeSign(p0.Y, p1.Y);

            switch (octant)
            {
            case OctantDirection.Zero:
                return(CompareValue(xSign, ySign));

            case OctantDirection.One:
                return(CompareValue(ySign, xSign));

            case OctantDirection.Two:
                return(CompareValue(ySign, -xSign));

            case OctantDirection.Three:
                return(CompareValue(-xSign, ySign));

            case OctantDirection.Four:
                return(CompareValue(-xSign, -ySign));

            case OctantDirection.Five:
                return(CompareValue(-ySign, -xSign));

            case OctantDirection.Six:
                return(CompareValue(-ySign, xSign));

            case OctantDirection.Seven:
                return(CompareValue(xSign, -ySign));
            }
            throw new InvalidOctantException(octant.ToString());
        }
 /// <summary>
 /// Converts a OctantDirection value to a normalized Vector2.
 /// </summary>
 /// <param name="direction">OctantDirection value to convert.</param>
 /// <returns>A normalized Vector2 instance.</returns>
 public static Vector2 DirectionToVector(OctantDirection direction)
 {
     switch (direction)
     {
         case OctantDirection.Up:
             return new Vector2(0.0f, -1.0f);
         case OctantDirection.UpLeft:
             return new Vector2(-_inverseSqrt2, -_inverseSqrt2);
         case OctantDirection.UpRight:
             return new Vector2(_inverseSqrt2, -_inverseSqrt2);
         case OctantDirection.Down:
             return new Vector2(0.0f, 1.0f);
         case OctantDirection.DownLeft:
             return new Vector2(-_inverseSqrt2, _inverseSqrt2);
         case OctantDirection.DownRight:
             return new Vector2(_inverseSqrt2, _inverseSqrt2);
         case OctantDirection.Left:
             return new Vector2(-1.0f, 0.0f);
         case OctantDirection.Right:
             return new Vector2(1.0f, 0.0f);
         default:
             return Vector2.Zero;
     }
 }