示例#1
0
        public VectorPoint Mod(VectorPoint other)
        {
            var newX = Mathi.Mod(x, other.X);
            var newY = Mathi.Mod(y, other.Y);

            return(new VectorPoint(newX, newY));
        }
示例#2
0
        public IEnumerable <DiamondPoint> GetEdgeFaces()
        {
            var edgeAnchor = GetEdgeFaceAnchor();

            int edgeIndex = Mathi.Mod(X + Y, 2);

            return(from faceDirection in EdgeFaceDirections[edgeIndex]
                   select faceDirection + edgeAnchor);
        }
示例#3
0
        public override FlatTriPoint RawWorldToGrid(Vector2 point)
        {
            float hexSize = cellDimensions.y * 2;

            float y = point.x / hexSize * Mathf.Sqrt(3);
            float x = (point.y - cellDimensions.y / 2) / hexSize;

            int ti = Mathf.FloorToInt(-x + y);
            int tj = Mathf.FloorToInt(x + y) + 1;
            int tk = Mathf.FloorToInt(-2 * x);

            return(new FlatTriPoint(ti, -tk, Mathi.Mod(tj + tk + ti, 2)));
        }
示例#4
0
        public override PointyTriPoint RawWorldToGrid(Vector2 point)
        {
            float hexSize = cellDimensions.x * 2;

            float x = point.y / hexSize * Mathf.Sqrt(3);
            float y = (point.x - cellDimensions.x / 2) / hexSize /*- cellDimensions.y/2*/;

            int ti = Mathf.FloorToInt(x - y);
            int tj = Mathf.FloorToInt(x + y) + 1;
            int tk = Mathf.FloorToInt(-2 * y);

            return(new PointyTriPoint(-tk, ti, Mathi.Mod(tj + tk + ti, 2)));
        }
示例#5
0
        /**
         *      Makes an edge grid for this grid.
         */
        public IGrid <TNewCell, FlatRhombPoint> MakeEdgeGrid <TNewCell>()
        {
            var edges   = this.SelectMany(x => x.GetEdges());
            var storage = FlatRhombGrid <TNewCell> .CalculateStorage(edges);

            var offset = FlatRhombGrid <TNewCell> .GridPointFromArrayPoint(storage.offset);

            var oddPoint = new FlatHexPoint(
                Mathi.Mod(offset.X, 2),
                Mathi.Mod(offset.Y, 2));

            var evenPoint = offset.Subtract(oddPoint);

            return(new FlatRhombGrid <TNewCell>(storage.dimensions.X + 2, storage.dimensions.Y + 2, IsInsideEdgeGrid, evenPoint));
        }
示例#6
0
        //TODO: Fix
        public override FlatRhombPoint RawWorldToGrid(Vector2 point)
        {
            float hexSize = cellDimensions.y;

            //basePoint += new Vector2(cellDimensions.x/2, cellDimensions.y / 4);

            float y = (point.y - cellDimensions.y / 4) / hexSize;
            float x = (point.x - cellDimensions.y / 4 / Mathf.Sqrt(3)) / hexSize * Mathf.Sqrt(3);

            int ti = Mathf.FloorToInt(x - y);
            int tj = Mathf.FloorToInt(x + y);
            int tk = Mathf.FloorToInt(-2 * y);

            float hi0 = Mathf.FloorToInt((+ti + tk + 2.0f) / 3);
            float hj0 = Mathf.FloorToInt((+tj - tk + 1.0f) / 3);
            float hk0 = hi0 + hj0;

            float hi = -hi0;
            float hj = hk0;

            int index;

            if (
                Mathi.Mod(tj, 3) == 0 && Mathi.Mod(tk, 3) == 1 ||
                Mathi.Mod(tj, 3) == 1 && Mathi.Mod(tk, 3) == 2 ||
                Mathi.Mod(tj, 3) == 2 && Mathi.Mod(tk, 3) == 0)
            {
                index = 0;
            }
            else if (
                Mathi.Mod(ti, 3) == 0 && Mathi.Mod(tk, 3) == 1 ||
                Mathi.Mod(ti, 3) == 1 && Mathi.Mod(tk, 3) == 0 ||
                Mathi.Mod(ti, 3) == 2 && Mathi.Mod(tk, 3) == 2
                )
            {
                index = 1;
            }
            else
            {
                index = 2;
            }

            return(new FlatRhombPoint(Mathf.FloorToInt(hj), Mathf.FloorToInt(hi), index));
        }
示例#7
0
        public override PointyHexPoint RawWorldToGrid(Vector2 worldPoint)
        {
            float angleRad = Mathf.Atan2(worldPoint.y - Center.y, worldPoint.x - Center.x);

            if (angleRad < 0)
            {
                angleRad += 2 * Mathf.PI;
            }

            float radius = (new Vector2(worldPoint.x - Center.x, worldPoint.y - Center.y)).magnitude;


            int n = Mathf.FloorToInt((radius - InnerRadius) / (OuterRadius - InnerRadius) * SectorsAndBands.Y);
            int m = Mathf.FloorToInt((angleRad - sectorAngleRad * n / 2) / sectorAngleRad);

            m = Mathi.Mod(m, SectorsAndBands.X);

            return(new PointyHexPoint(m, n));
        }
 protected override Func <LinePoint, int> GetColorFunc(int x0, int x1, int y1)
 {
     return(point => Mathi.Mod(point, x0));
 }
示例#9
0
 public int GetColor4()
 {
     return(Mathi.Mod(X + 3 * Y, 8));
 }
示例#10
0
 public int GetColor1_2()
 {
     return(Mathi.Mod(X + Y, 2));
 }
示例#11
0
 public PointyRhombPoint IncIndex(int n)
 {
     return(new PointyRhombPoint(basePoint, Mathi.Mod(index + n, SpliceCount)));
 }
示例#12
0
 public FlatTriPoint IncIndex(int n)
 {
     return(new FlatTriPoint(basePoint, Mathi.Mod(index + n, SpliceCount)));
 }
示例#13
0
 public CairoPoint IncIndex(int n)
 {
     return(new CairoPoint(basePoint, Mathi.Mod(index + n, SpliceCount)));
 }
示例#14
0
 public int GetColor(int colorCount)
 {
     return(Mathi.Mod(n, colorCount));
 }
示例#15
0
 public LinePoint Mod(LinePoint other)
 {
     return(Mathi.Mod(n, other.n));
 }
示例#16
0
 public static bool IsInsideCheckerBoard(RectPoint point, int width, int height, bool includesOrigin)
 {
     return
         (IsInsideRect(point, width, height) &&
          (Mathi.Mod(point.X + point.Y, 2) == (includesOrigin ? 0 : 1)));
 }