public void GetInnerPoint()
 {
     window.ViewportPixelSize = new Size(800, 600);
     ScreenSpace screen = new QuadraticScreenSpace(window);
     Assert.AreEqual(screen.TopLeft, screen.GetInnerPosition(Vector2D.Zero));
     Assert.AreEqual(screen.BottomRight, screen.GetInnerPosition(Vector2D.One));
 }
		public void ToPixelWithSquareWindow()
		{
			window.ViewportPixelSize = new Size(100, 100);
			var screen = new QuadraticScreenSpace(window);
			Assert.AreEqual(new Vector2D(100, 100), screen.ToPixelSpace(Vector2D.One));
			Assert.AreEqual(Vector2D.Zero, screen.ToPixelSpace(Vector2D.Zero));
			Assert.AreEqual(new Vector2D(50, 50), screen.ToPixelSpace(Vector2D.Half));
		}
		public void ToQuadraticWithUnevenSize()
		{
			window.ViewportPixelSize = new Size(99, 199);
			var screen = new QuadraticScreenSpace(window);
			Assert.AreEqual(new Vector2D(0.2512563f, 0), screen.TopLeft);
			Assert.AreEqual(new Vector2D(0.7487437f, 1), screen.BottomRight);
			Assert.AreEqual(screen.BottomRight, screen.FromPixelSpace(new Vector2D(99, 199)));
		}
 public void TestViewportSizeChanged()
 {
     window.ViewportPixelSize = new Size(800, 800);
     var screen = new QuadraticScreenSpace(window);
     Action checkSize = delegate { Assert.AreEqual(Rectangle.One, screen.Viewport); };
     screen.ViewportSizeChanged += checkSize;
     window.ViewportPixelSize = new Size(800, 800);
     screen.ViewportSizeChanged -= checkSize;
 }
		public void IfCameraNotAdjustedEdgesAreIdenticalToQuadraticScreenSpace()
		{
			var q = new QuadraticScreenSpace(window);
			var c = new Camera2DScreenSpace(window);
			Assert.AreEqual(q.TopLeft, c.TopLeft);
			Assert.AreEqual(q.BottomRight, c.BottomRight);
			Assert.AreEqual(q.Top, c.Top, 0.0001f);
			Assert.AreEqual(q.Left, c.Left, 0.0001f);
			Assert.AreEqual(q.Bottom, c.Bottom, 0.0001f);
			Assert.AreEqual(q.Right, c.Right, 0.0001f);
		}
		public void ToPixelWithUnevenSizeFromQuadraticSpace()
		{
			window.ViewportPixelSize = new Size(99, 199);
			var screen = new QuadraticScreenSpace(window);
			Assert.AreEqual(new Vector2D(149, 199), screen.ToPixelSpace(Vector2D.One));
			Assert.AreEqual(new Vector2D(-50, 0), screen.ToPixelSpace(Vector2D.Zero));
			Assert.AreEqual(new Vector2D(49.5f, 99.5f), screen.ToPixelSpace(Vector2D.Half));
			Assert.AreEqual(new Vector2D(50, 100), screen.ToPixelSpaceRounded(Vector2D.Half));
			Assert.AreEqual(new Vector2D(199, 199),
				screen.ToPixelSpaceRounded(Vector2D.One) - screen.ToPixelSpaceRounded(Vector2D.Zero));
		}
		public void ToQuadraticWithPortraitWindow()
		{
			window.ViewportPixelSize = new Size(75, 100);
			var screen = new QuadraticScreenSpace(window);
			Assert.AreEqual(new Vector2D(0.125f, 0), screen.TopLeft);
			Assert.AreEqual(new Vector2D(0.875f, 1), screen.BottomRight);
			Assert.AreEqual(new Rectangle(0.125f, 0, 0.75f, 1), screen.Viewport);
			Assert.AreEqual(new Vector2D(0.875f, 1f), screen.FromPixelSpace(new Vector2D(75, 100)));
			Assert.AreEqual(Vector2D.Half, screen.FromPixelSpace(new Vector2D(37.5f, 50)));
			Assert.IsTrue(screen.FromPixelSpace(new Size(10, 10)).IsNearlyEqual(new Size(0.1f, 0.1f)));
		}
 public void ToPixelWithNonSquareWindow()
 {
     window.ViewportPixelSize = new Size(100, 75);
     var screen = new QuadraticScreenSpace(window);
     Assert.AreEqual(new Vector2D(100, 75), screen.ToPixelSpace(new Vector2D(1f, 0.875f)));
     Assert.AreEqual(Vector2D.Zero, screen.ToPixelSpace(new Vector2D(0, 0.125f)));
     Assert.AreEqual(new Vector2D(50, 37.5f), screen.ToPixelSpace(Vector2D.Half));
     Assert.AreEqual(new Size(10, 20), screen.ToPixelSpace(new Size(0.1f, 0.2f)));
     Assert.IsTrue(
         screen.ToPixelSpace(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f)).IsNearlyEqual(new Rectangle(20,
             7.5f, 60, 60)));
 }
 public void ToPixelInFullHdResolution()
 {
     window.ViewportPixelSize = new Size(1920, 1080);
     var screen = new QuadraticScreenSpace(window);
     Assert.AreEqual(new Vector2D(1680, 1500), screen.ToPixelSpace(new Vector2D(0.875f, 1f)));
     var somePoint = screen.FromPixelSpace(new Vector2D(324, 483));
     var somePointPlusOne = screen.FromPixelSpace(new Vector2D(325, 483));
     Assert.IsFalse(somePoint.X.IsNearlyEqual(somePointPlusOne.X),
         somePoint + " should not be nearly equal to " + somePointPlusOne);
     Assert.AreEqual(new Vector2D(324, 483), screen.ToPixelSpaceRounded(somePoint));
     Assert.AreEqual(new Vector2D(325, 483), screen.ToPixelSpaceRounded(somePointPlusOne));
 }
		public void IfCameraNotAdjustedItBehavesIdenticallyToQuadraticScreenSpace()
		{
			var q = new QuadraticScreenSpace(window);
			var c = new Camera2DScreenSpace(window);
			Assert.IsTrue(
				c.FromPixelSpace(new Vector2D(1, 2)).IsNearlyEqual(q.FromPixelSpace(new Vector2D(1, 2))));
			Assert.IsTrue(
				c.FromPixelSpace(new Size(-3, 4)).IsNearlyEqual(q.FromPixelSpace(new Size(-3, 4))));
			Assert.IsTrue(
				c.ToPixelSpace(new Vector2D(2, 6)).IsNearlyEqual(q.ToPixelSpace(new Vector2D(2, 6))));
			Assert.IsTrue(c.ToPixelSpace(new Size(-2, 0)).IsNearlyEqual(q.ToPixelSpace(new Size(-2, 0))));
		}
		public void ToQuadraticWithNonSquareWindow()
		{
			window.ViewportPixelSize = new Size(100, 75);
			var screen = new QuadraticScreenSpace(window);
			Assert.AreEqual(0, screen.Left);
			Assert.AreEqual(0.125f, screen.Top);
			Assert.AreEqual(1, screen.Right);
			Assert.AreEqual(0.875f, screen.Bottom);
			Assert.AreEqual(new Rectangle(0, 0.125f, 1, 0.75f), screen.Viewport);
			Assert.AreEqual(new Vector2D(1f, 0.875f), screen.FromPixelSpace(new Vector2D(100, 75)));
			Assert.AreEqual(Vector2D.Half, screen.FromPixelSpace(new Vector2D(50, 37.5f)));
			Assert.IsTrue(screen.FromPixelSpace(new Size(10, 10)).IsNearlyEqual(new Size(0.1f, 0.1f)));
		}
 public void ToPixelWithPortraitWindow()
 {
     window.ViewportPixelSize = new Size(75, 100);
     var screen = new QuadraticScreenSpace(window);
     Assert.AreEqual(new Vector2D(75, 100), screen.ToPixelSpace(new Vector2D(0.875f, 1f)));
     Assert.AreEqual(Vector2D.Zero, screen.ToPixelSpace(new Vector2D(0.125f, 0)));
     Assert.AreEqual(new Vector2D(37.5f, 50), screen.ToPixelSpace(Vector2D.Half));
     Assert.AreEqual(new Size(10, 20), screen.ToPixelSpace(new Size(0.1f, 0.2f)));
 }
		public void TestAspectRatio()
		{
			var screen = new QuadraticScreenSpace(window);
			window.ViewportPixelSize = new Size(800, 800);
			Assert.AreEqual(1f, screen.AspectRatio);
			window.ViewportPixelSize = new Size(1920, 1080);
			Assert.AreEqual(0.5625f, screen.AspectRatio);
		}