Exemplo n.º 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));
        }
Exemplo n.º 2
0
        override public FlatHexPoint RawWorldToGrid(Vector2 point)
        {
            int x = Mathi.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x);
            int y = Mathi.FloorToInt((point.y - x * cellDimensions.y / 2 + cellDimensions.y / 2) / cellDimensions.y);

            return(new FlatHexPoint(x, y));
        }
Exemplo n.º 3
0
        public override LinePoint RawWorldToGrid(Vector2 worldPoint)
        {
            var point = (worldPoint + cellDimensions / 2);

            var m = Mathi.FloorToInt(point.x / cellDimensions.x);

            return(m);
        }
Exemplo n.º 4
0
        public IEnumerable <DiamondPoint> GetEdgeFaces()
        {
            var edgeAnchor = GetEdgeFaceAnchor();

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

            return(from faceDirection in EdgeFaceDirections[edgeIndex]
                   select faceDirection + edgeAnchor);
        }
Exemplo n.º 5
0
 private DiamondPoint GetEdgeFaceAnchor()
 {
     /*
      * 0 0 -> 0 0
      * 0 1 -> 0 0
      * 1 0 -> 0 -1
      * 1 1 -> 1 0
      */
     return(new DiamondPoint(
                Mathi.Div(X + Y, 2),
                Mathi.Div(Y - X, 2)));
 }
Exemplo n.º 6
0
        public override DiamondPoint RawWorldToGrid(Vector2 point)
        {
            int x =
                Mathi.FloorToInt((point.x + 0 * cellDimensions.x / 2) / cellDimensions.x +
                                 /*Mathi.FloorToInt(*/ (point.y + cellDimensions.y / 2) / cellDimensions.y);

            int y =
                Mathi.FloorToInt((point.y + cellDimensions.y / 2) / cellDimensions.y -
                                 (point.x + 0 * cellDimensions.x / 2) / cellDimensions.x);

            return(new DiamondPoint(x, y));
        }
Exemplo n.º 7
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)));
        }
Exemplo n.º 8
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)));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
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));
        }
Exemplo n.º 12
0
 public VectorPoint ScaleDown(int r)
 {
     return(new VectorPoint(
                Mathi.Div(x, r),
                Mathi.Div(y, r)));
 }
Exemplo n.º 13
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)));
 }
Exemplo n.º 14
0
 public int GetColor(int colorCount)
 {
     return(Mathi.Mod(n, colorCount));
 }
Exemplo n.º 15
0
 public int GetColor4()
 {
     return(Mathi.Mod(X + 3 * Y, 8));
 }
Exemplo n.º 16
0
 public PointyRhombPoint IncIndex(int n)
 {
     return(new PointyRhombPoint(basePoint, Mathi.Mod(index + n, SpliceCount)));
 }
Exemplo n.º 17
0
 public CairoPoint IncIndex(int n)
 {
     return(new CairoPoint(basePoint, Mathi.Mod(index + n, SpliceCount)));
 }
Exemplo n.º 18
0
 public override RectPoint RawWorldToGrid(Vector2 point)
 {
     return(new RectPoint(
                Mathi.FloorToInt((point.x + cellDimensions.x / 2) / cellDimensions.x),
                Mathi.FloorToInt((point.y + cellDimensions.y / 2) / cellDimensions.y)));
 }
Exemplo n.º 19
0
 public FlatTriPoint IncIndex(int n)
 {
     return(new FlatTriPoint(basePoint, Mathi.Mod(index + n, SpliceCount)));
 }
Exemplo n.º 20
0
 public LinePoint ScaleDown(int r)
 {
     return(Mathi.Div(n, r));
 }
Exemplo n.º 21
0
 public int GetColor1_2()
 {
     return(Mathi.Mod(X + Y, 2));
 }
Exemplo n.º 22
0
 public LinePoint Div(LinePoint other)
 {
     return(Mathi.Div(n, other.n));
 }
Exemplo n.º 23
0
 protected override Func <LinePoint, int> GetColorFunc(int x0, int x1, int y1)
 {
     return(point => Mathi.Mod(point, x0));
 }
Exemplo n.º 24
0
 public LinePoint Mod(LinePoint other)
 {
     return(Mathi.Mod(n, other.n));
 }