public SpriteSheet(string name, Size2d size, Position2d origin, int columns, int rows, int columnPadding, int rowPadding) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException($"{nameof(SpriteSheet)} name is required."); } this.Name = name; var frames = new List <Rect2d>(columns * rows); for (var r = 0; r < rows; r++) { for (var c = 0; c < columns; c++) { float x = origin.X + (c * size.Width) + (c * columnPadding); float y = origin.Y + (r * size.Height) + (r * rowPadding); frames.Add(new Rect2d(x, y, size.Width, size.Height)); } } if (frames.Count == 0) { throw new InvalidOperationException($"Cannot create a {nameof(SpriteSheet)} with no frames."); } this.Frames = frames; }
public void CanCreateFromPositionAndSize() { var pos = new Position2d(1, 2); var size = new Size2d(3, 4); var anchor = Anchor2d.Center; var rect = new Rect2d(pos, size); DolphAssert.EqualF(pos.X, rect.X); DolphAssert.EqualF(pos.Y, rect.Y); DolphAssert.EqualF(size.Width, rect.Width); DolphAssert.EqualF(size.Height, rect.Height); rect = new Rect2d(pos, size, anchor); DolphAssert.EqualF(pos.X, rect.X); DolphAssert.EqualF(pos.Y, rect.Y); DolphAssert.EqualF(size.Width, rect.Width); DolphAssert.EqualF(size.Height, rect.Height); Assert.Equal(anchor, rect.Origin.Anchor); rect = new Rect2d(pos, size, new Origin2d(anchor)); DolphAssert.EqualF(pos.X, rect.X); DolphAssert.EqualF(pos.Y, rect.Y); DolphAssert.EqualF(size.Width, rect.Width); DolphAssert.EqualF(size.Height, rect.Height); Assert.Equal(anchor, rect.Origin.Anchor); }
public void CanConvertToSize() { var size1 = new Size2d(8, 12); var rect = new Rect2d(new Position2d(4, 4), size1); var size2 = rect.GetSize(); Assert.Equal(size1, size2); }
public void CanScaleByMagnitude(float w1, float h1, float mag, float w2, float h2) { var size = new Size2d(w1, h1); size.Scale(mag); DolphAssert.EqualF(w2, size.Width); DolphAssert.EqualF(h2, size.Height); }
public void Size2dCloneWorks() { var v = new Size2d(1, 2); var v2 = v.Clone(); v2.Width = 3; Assert.NotEqual(v, v2); Assert.True(v.Equivalent(new Size2d(1, 2))); }
public void TestHashCode() { var size1 = new Size2d(1, 2); var size2 = new Size2d(1, 2); Assert.Equal(size1.GetHashCode(), size2.GetHashCode()); size2.Scale(1.1f); Assert.NotEqual(size1.GetHashCode(), size2.GetHashCode()); }
public void Size2dApplyWorks() { var v = new Size2d(1.11, 2.22); v.Apply(Math.Round); Assert.True(v.Equivalent(new Size2d(1, 2))); v.Apply(val => { return(val + 1); }); Assert.True(v.Equivalent(new Size2d(2, 3))); }
public void Size2dAddsCorrectly() { var v = new Size2d(2, 3); Assert.False(v == v + 0); Assert.False(v == v.Add(0)); Assert.True(v.Equivalent(v + 0)); Assert.True(v.Equivalent(v.Add(0))); Assert.True((v + v).Equivalent(new Size2d(4, 6))); Assert.True(v.Add(v).Equivalent(new Size2d(4, 6))); Assert.True((v + .1).Equivalent(new Size2d(2.1, 3.1))); Assert.True(v.Add(.1).Equivalent(new Size2d(2.1, 3.1))); }
public void Size2dTriggerWorks() { var v = new Size2d(2, 3); double total = 0; Action <double> sum = (val) => { total += val; }; v.Trigger(sum); Assert.Equal(5, total); }
public void Size2dDividesCorrectly() { var v = new Size2d(2, 4); Assert.False(v == v / 1); Assert.False(v == v.Divide(1)); Assert.True(v.Equivalent(v / 1)); Assert.True(v.Equivalent(v.Divide(1))); Assert.True(new Size2d(.5, .25).Equivalent(1 / v)); Assert.True(new Size2d(.5, .25).Equivalent(v.DivideFrom(1))); Assert.True(new Size2d(20, 40).Equivalent(v / .1)); Assert.True(new Size2d(20, 40).Equivalent(v.Divide(.1))); }
public void Size2dMultipliesCorrectly() { var v = new Size2d(2, 3); Assert.False(Size2d.Zero == v * 0); Assert.False(Size2d.Zero == v.Multiply(0)); Assert.True(Size2d.Zero.Equivalent(v * 0)); Assert.True(Size2d.Zero.Equivalent(v.Multiply(0))); Assert.True((v * v).Equivalent(new Size2d(4, 9))); Assert.True(v.Multiply(v).Equivalent(new Size2d(4, 9))); Assert.True((v * .5).Equivalent(new Size2d(1, 1.5))); Assert.True(v.Multiply(.5).Equivalent(new Size2d(1, 1.5))); }
public Window( string title, Point2d<int> position, Size2d<int> size, SDL.SDL_WindowFlags flags) { window = SDL.SDL_CreateWindow( title, position.X, position.Y, size.Width, size.Height, flags); }
public void CanScaleByVector(float w1, float h1, float x, float y, float w2, float h2) { var size = new Size2d(w1, h1); size.Scale(x, y); DolphAssert.EqualF(w2, size.Width); DolphAssert.EqualF(h2, size.Height); size = new Size2d(w1, h1); size.Scale(new Vector2d(x, y)); DolphAssert.EqualF(w2, size.Width); DolphAssert.EqualF(h2, size.Height); }
public void Size2dSubtractsCorrectly() { var v = new Size2d(2, 3); Assert.False(v == v - 0); Assert.False(v == v.Subtract(0)); Assert.False(-v == v.SubtractFrom(0)); Assert.True(v.Equivalent(v - 0)); Assert.True(v.Equivalent(v.Subtract(0))); Assert.True((-v).Equivalent(0 - v)); Assert.True((-v).Equivalent(v.SubtractFrom(0))); Assert.True((v - v).Equivalent(Size2d.Zero)); Assert.True((v.Subtract(v)).Equivalent(Size2d.Zero)); Assert.True((v - .1).Equivalent(new Size2d(1.9, 2.9))); Assert.True((v.Subtract(.1)).Equivalent(new Size2d(1.9, 2.9))); Assert.True((.1 - v).Equivalent(new Size2d(-1.9, -2.9))); Assert.True((v.SubtractFrom(.1)).Equivalent(new Size2d(-1.9, -2.9))); }
public void TestEquality(float w, float h) { var size1 = new Size2d(w, h); var size2 = new Size2d(w, h); Assert.True(size1 == size2); Assert.True(size1.Equals(size2)); size1.Width += Constants.FloatTolerance / 10; Assert.True(size1 == size2); Assert.True(size1.Equals(size2)); size1.Width += Constants.FloatTolerance * 10; Assert.False(size1 == size2); Assert.False(size1.Equals(size2)); }
/// <summary> /// Creates a new instance of BoundingRectangle. /// </summary> /// <param name="position">Initial Position of the BoundingRectangle.</param> /// <param name="size">Initial Size of the BoundingRectangle.</param> public BoundingRectangle(Vector2d position, Size2d size) : base(position) { Size = size; }
public static extern ExceptionStatus core_FileNode_read_Size2d(IntPtr node, out Size2d returnValue);
public static extern ExceptionStatus core_Mat_push_back_Size2d(IntPtr self, Size2d v);
public SpriteSheet(string name, Size2d size, Position2d origin, int columns, int rows) : this(name, size, origin, columns, rows, 0, 0) { }
public static extern ExceptionStatus core_FileStorage_shift_Size2d(IntPtr fs, Size2d val);
public static Point ToPoint(this Size2d size) { return(new Point((int)size.Width, (int)size.Height)); }