public void CanGetPositionWithAnchor(Anchor2d anchor, float expectedX, float expectedY) { var rect = new Rect2d(X, Y, W, H); var pos = rect.GetAnchorPosition(anchor); DolphAssert.EqualF(expectedX, pos.X); DolphAssert.EqualF(expectedY, pos.Y); }
public void CanSetPositionWithAnchor(Anchor2d anchor, float expectedTopLeftX, float expectedTopLeftY) { var rect = new Rect2d(X, Y, W, H, anchor); foreach (var kvp in RpMap) { var getAnchor = kvp.Key; var rp = kvp.Value; var pos = rect.GetAnchorPosition(getAnchor); DolphAssert.EqualF(rp.X(expectedTopLeftX), pos.X); DolphAssert.EqualF(rp.Y(expectedTopLeftY), pos.Y); } }
public void TestEquality(Anchor2d anchor, float x, float y) { var o1 = new Origin2d(anchor, new Vector2d(x, y)); var o2 = new Origin2d(anchor, new Vector2d(x, y)); Assert.True(o1 == o2); Assert.True(o1.Equals(o2)); o1.Offset.X += Constants.FloatTolerance / 10; Assert.True(o1 == o2); Assert.True(o1.Equals(o2)); o1.Offset.X += Constants.FloatTolerance * 10; Assert.False(o1 == o2); Assert.False(o1.Equals(o2)); }
public void TestEquality(float x, float y, float w, float h, Anchor2d anchor) { var rect1 = new Rect2d(x, y, w, h, anchor); var rect2 = new Rect2d(x, y, w, h, anchor); Assert.True(rect1 == rect2); Assert.True(rect1.Equals(rect2)); rect1.X += Constants.FloatTolerance / 10; Assert.True(rect1 == rect2); Assert.True(rect1.Equals(rect2)); rect1.X += Constants.FloatTolerance * 10; Assert.False(rect1 == rect2); Assert.False(rect1.Equals(rect2)); }
public Origin2d(Anchor2d anchor) { this.Anchor = anchor; this.Offset = Vector2d.Zero; }
public Origin2d(Anchor2d anchor, Vector2d offset) { this.Anchor = anchor; this.Offset = offset; }
public RotationAnimation SetOrigin(Anchor2d anchor) { this.Origin = new Origin2d(anchor); return(this); }
public Position2d GetAnchorPosition(Anchor2d anchor) { const float None = 0.000f; const float Half = 0.500f; const float Whole = 1.000f; Anchor2d thisAnchor = this.Origin.Anchor; float widthDiff; float heightDiff; if ((anchor & Anchor2d.Center) == Anchor2d.Center) { if ((thisAnchor & Anchor2d.Center) == Anchor2d.Center) { widthDiff = None; } else if ((thisAnchor & Anchor2d.Right) == Anchor2d.Right) { widthDiff = Half; } else { widthDiff = -Half; } } else if ((anchor & Anchor2d.Right) == Anchor2d.Right) { if ((thisAnchor & Anchor2d.Center) == Anchor2d.Center) { widthDiff = -Half; } else if ((thisAnchor & Anchor2d.Right) == Anchor2d.Right) { widthDiff = None; } else { widthDiff = -Whole; } } else { if ((thisAnchor & Anchor2d.Center) == Anchor2d.Center) { widthDiff = Half; } else if ((thisAnchor & Anchor2d.Right) == Anchor2d.Right) { widthDiff = Whole; } else { widthDiff = None; } } if ((anchor & Anchor2d.Middle) == Anchor2d.Middle) { if ((thisAnchor & Anchor2d.Middle) == Anchor2d.Middle) { heightDiff = None; } else if ((thisAnchor & Anchor2d.Bottom) == Anchor2d.Bottom) { heightDiff = Half; } else { heightDiff = -Half; } } else if ((anchor & Anchor2d.Bottom) == Anchor2d.Bottom) { if ((thisAnchor & Anchor2d.Middle) == Anchor2d.Middle) { heightDiff = -Half; } else if ((thisAnchor & Anchor2d.Bottom) == Anchor2d.Bottom) { heightDiff = None; } else { heightDiff = -Whole; } } else { if ((thisAnchor & Anchor2d.Middle) == Anchor2d.Middle) { heightDiff = Half; } else if ((thisAnchor & Anchor2d.Bottom) == Anchor2d.Bottom) { heightDiff = Whole; } else { heightDiff = None; } } float totalWidthDiff = (this.Width * widthDiff) + this.Origin.Offset.X; float totalHeightDiff = (this.Height * heightDiff) + this.Origin.Offset.Y; float x = this.X - totalWidthDiff; float y = this.Y - totalHeightDiff; return(new Position2d(x, y)); }
public Rect2d(float x, float y, float width, float height, Anchor2d anchor) : this(x, y, width, height, new Origin2d(anchor)) { }
public Rect2d(Position2d position, Size2d size, Anchor2d anchor) : this(position, size, new Origin2d(anchor)) { }