Example #1
0
        public DiamondShapeInfo <TCell> FatRectangle(int width, int height)
        {
            int diamondSize       = width + Mathi.Div(height, 2);
            var storageBottomLeft = new DiamondPoint(0, 1 - width);

            return(Shape(diamondSize, diamondSize, p => IsInsideFatRectangle(p, width, height), storageBottomLeft));
        }
Example #2
0
        /**
         *      Gives a new point that represents the
         *      reminder when the first point is divided
         *      by the second point	component-wise. The
         *      division is integer division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public DiamondPoint Mod(DiamondPoint otherPoint)
        {
            var x = GLMathf.Mod(X, otherPoint.X);
            var y = GLMathf.Mod(Y, otherPoint.Y);

            return(new DiamondPoint(x, y));
        }
Example #3
0
        /**
         *      Gives a new point that represents the
         *      first point divided by the second point
         *      component-wise. The division is integer
         *      division.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public DiamondPoint Div(DiamondPoint otherPoint)
        {
            var x = Mathi.Div(X, otherPoint.X);
            var y = Mathi.Div(Y, otherPoint.Y);

            return(new DiamondPoint(x, y));
        }
Example #4
0
        /**
         *      Gives a new point that represents the
         *      first point multiplied by the second point
         *      component-wise.
         *
         *      @since 1.6 (Rect)
         *      @since 1.7 (other)
         */
        public DiamondPoint Mul(DiamondPoint otherPoint)
        {
            var x = X * otherPoint.X;
            var y = Y * otherPoint.Y;

            return(new DiamondPoint(x, y));
        }
Example #5
0
 private static bool IsInsideParallelogram(DiamondPoint point, int width, int height)
 {
     return
         (point.X >= 0 &&
          point.X < width &&
          point.Y >= 0 &&
          point.Y < height);
 }
Example #6
0
        public DiamondShapeInfo <TCell> Rectangle(int width, int height)
        {
            //Note: this fit is not the tightest possible.
            int diamondSize = width + Mathi.Div(height, 2);

            var storageBottomLeft = new DiamondPoint(0, 1 - width);

            return(Shape(diamondSize, diamondSize, p => IsInsideRaggedRectangle(p, width, height), storageBottomLeft));
        }
Example #7
0
        private static bool IsInsideThinRectangle(DiamondPoint point, int width, int height)
        {
            int x = Mathi.Div(point.X - point.Y, 2);
            int y = point.X + point.Y;

            return
                (x >= 0 &&
                 x < width - Mathi.Mod(y, 2) &&
                 y >= 0 &&
                 y < height);
        }
Example #8
0
        private static bool IsInsideRaggedRectangle(DiamondPoint point, int width, int height)
        {
            int x = GLMathf.Div(point.X - point.Y, 2);
            int y = point.X + point.Y;

            return
                (x >= 0 &&
                 x < width &&
                 y >= 0 &&
                 y < height);
        }
Example #9
0
 protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
 {
     base.OnMouseLeftButtonUp(e);
     draggingStarted      = false;
     mouseDraggedLocation = centerPoint;
     DiamondPoint         = DiamondToolbox.CartesianToDiamond(new DoublePoint(0, 0), 100);
     if (JoystickMovedListeners != null)
     {
         JoystickMovedListeners(DiamondPoint);
     }
     e.Handled = true;
 }
Example #10
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);

            DiamondPoint rectPoint = map[worldPosition];

            if (grid.Contains(rectPoint))
            {
                grid[rectPoint].OnClick();
            }
        }
    }
Example #11
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector2 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);

                DiamondPoint point = map[worldPosition];

                if (grid.Contains(point))
                {
                    //Toggle the highlight
                    grid[point].HighlightOn = !grid[point].HighlightOn;
                }
            }
        }
Example #12
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (draggingStarted)
            {
                mouseDraggedLocation = e.GetPosition(this);
                var p = new DoublePoint(
                    map((int)mouseDraggedLocation.X, 0, (int)ActualWidth, 100, -100),
                    map((int)mouseDraggedLocation.Y, 0, (int)ActualHeight, 100, -100)
                    );
                DiamondPoint = DiamondToolbox.CartesianToDiamond(p, 100);

                if (JoystickMovedListeners != null)
                {
                    JoystickMovedListeners(DiamondPoint);
                }

                e.Handled = true;
            }
        }
Example #13
0
        /**
         *      Gives a coloring of the grid such that
         *      if a point p has color k, then all points
         *      p + m[ux, 0] + n[vx, vy] have the same color
         *      for any integers a and b.
         *
         *      More information anout grid colorings:
         *      http://gamelogic.co.za/2013/12/18/what-are-grid-colorings/
         *
         *      @since 1.7
         */
        public int __GetColor__ReferenceImplementation(int ux, int vx, int vy)
        {
            var u = new DiamondPoint(ux, 0);
            var v = new DiamondPoint(vx, vy);

            int colorCount = u.PerpDot(v);

            float a = PerpDot(v) / (float)colorCount;
            float b = -PerpDot(u) / (float)colorCount;

            int m = Mathi.FloorToInt(a);
            int n = Mathi.FloorToInt(b);

            int baseVectorX = m * u.X + n * v.X;
            int baseVectorY = n * u.Y + n * v.Y;

            int offsetX = Mathi.Mod(X - baseVectorX, ux);
            int offsetY = Y - baseVectorY;

            int colorIndex = Mathi.FloorToInt(offsetX + offsetY * ux);

            return(colorIndex);
        }
        /**
         *      @version1_11
         */

        public InspectableVectorPoint(DiamondPoint point)
        {
            x = point.X;
            y = point.Y;
        }
Example #15
0
 public static ArrayPoint ArrayPointFromGridPoint(DiamondPoint point)
 {
     return(new ArrayPoint(point.X, point.Y));
 }
Example #16
0
 override protected ArrayPoint ArrayPointFromPoint(DiamondPoint point)
 {
     return(ArrayPointFromGridPoint(point));
 }
Example #17
0
 /**
  *      @since 1.7
  */
 public int Dot(DiamondPoint other)
 {
     return(x * other.X + y * other.Y);
 }
Example #18
0
 /**
  *      @since 1.7
  */
 public int PerpDot(DiamondPoint other)
 {
     return(x * other.Y - y * other.x);
 }
Example #19
0
 public DiamondPoint MoveBy(DiamondPoint translation)
 {
     return(Translate(translation));
 }
Example #20
0
 public DiamondPoint MoveBackBy(DiamondPoint translation)
 {
     return(Translate(translation.Negate()));
 }
Example #21
0
 /**
  *      Subtracts the other point from this point, and returns the result.
  */
 public DiamondPoint Subtract(DiamondPoint other)
 {
     return(new DiamondPoint(x - other.X, y - other.Y));
 }
Example #22
0
 /**
  *      This is a norm defined on the point, such that `p1.Difference(p2).Abs()` is equal to
  *      `p1.DistanceFrom(p2)`.
  */
 public DiamondPoint Translate(DiamondPoint translation)
 {
     return(new DiamondPoint(x + translation.X, y + translation.Y));
 }
Example #23
0
        public bool Equals(DiamondPoint other)
        {
            bool areEqual = (x == other.X) && (y == other.Y);

            return(areEqual);
        }
Example #24
0
 /**
  *      The lattice distance from this point to the other.
  */
 public int DistanceFrom(DiamondPoint other)
 {
     return(Subtract(other).Magnitude());
 }
		/**
			@version1_11
		*/

		public InspectableVectorPoint(DiamondPoint point)
		{
			x = point.X;
			y = point.Y;
		}