예제 #1
0
            public Neighbor(Displacement orig, Displacement disp, NeighborOrientation orientation, Vector2 min, Vector2 max)
            {
                Displacement         = disp;
                _relativeOrientation = orientation;
                _relativeMin         = min;
                _relativeMax         = max;

                if (orientation != NeighborOrientation.Unknown)
                {
                    return;
                }

                // Temp hack until I figure out how to correctly offset orientation
                var testPos = (min + max) * 0.5f;

                if (testPos.X < 0f)
                {
                    testPos.X = 0f;
                }
                else if (testPos.X > 1f)
                {
                    testPos.X = 1f;
                }
                if (testPos.Y < 0f)
                {
                    testPos.Y = 0f;
                }
                else if (testPos.Y > 1f)
                {
                    testPos.Y = 1f;
                }

                var origSample      = orig.GetInnerPosition(testPos);
                var bestDist2       = float.PositiveInfinity;
                var bestOrientation = NeighborOrientation.CounterClockwise0;

                for (var i = 0; i < 4; ++i)
                {
                    _relativeOrientation = (NeighborOrientation)i;
                    var sample = GetPosition(testPos);
                    var dist2  = (sample - origSample).LengthSquared;

                    if (dist2 < bestDist2)
                    {
                        bestDist2       = dist2;
                        bestOrientation = _relativeOrientation;
                    }
                }

                _relativeOrientation = bestOrientation;
            }
예제 #2
0
파일: Cell.cs 프로젝트: n1l/crozzle
        /// <summary>
        /// Get neibot row index
        /// </summary>
        /// <param name="orientation">Orientation of search</param>
        /// <returns>Row index in matrix</returns>
        public int GetNeighborRow(NeighborOrientation orientation)
        {
            var rowIndex = RowIndex;

            switch (orientation)
            {
            case NeighborOrientation.Diagonal:
            case NeighborOrientation.Vertical:
                rowIndex++;
                break;

            case NeighborOrientation.Horizontal:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
            }
            return(rowIndex);
        }