ScreenSpace FromPixelSpace Method (Rectangle)Delta Engine Documentation

Namespace: DeltaEngine.ScreenSpaces
Assembly: DeltaEngine (in DeltaEngine.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public Rectangle FromPixelSpace(
	Rectangle quadraticRect
)

Return Value

Type: Rectangle
Remarks

Tests: DeltaEngine.Tests.ScreenSpaces.QuadraticScreenSpaceTests
Remarks

Tests: DeltaEngine.Tests.ScreenSpaces.Camera2DScreenSpaceTests
Remarks

Tests: DeltaEngine.Tests.ScreenSpaces.PixelScreenSpaceTests
Remarks

Tests: DeltaEngine.Tests.ScreenSpaces.RelativeScreenSpaceTests
Examples

5 unit tests call DeltaEngine.ScreenSpaces.ScreenSpace.FromPixelSpace(DeltaEngine.Datatypes.Rectangle)
[Test]
public void SquareWindowWithQuadraticSpace()
{
    ScreenSpace.Current = new QuadraticScreenSpace(window);
    window.ViewportPixelSize = new Size(100, 100);
    Assert.AreEqual(Vector2D.Zero, ScreenSpace.Current.TopLeft);
    Assert.AreEqual(Vector2D.One, ScreenSpace.Current.BottomRight);
    Assert.AreEqual(Rectangle.One, ScreenSpace.Current.Viewport);
    Assert.AreEqual(Vector2D.One, ScreenSpace.Current.FromPixelSpace(new Vector2D(100, 100)));
    Assert.AreEqual(Vector2D.Half, ScreenSpace.Current.FromPixelSpace(new Vector2D(50, 50)));
    Assert.IsTrue(
        ScreenSpace.Current.FromPixelSpace(new Rectangle(10, 10, 80, 80)).IsNearlyEqual(
            new Rectangle(0.1f, 0.1f, 0.8f, 0.8f)));
}
[Test]
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)));
}
[Test]
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)));
}
Examples

3 unit tests call DeltaEngine.ScreenSpaces.ScreenSpace.FromPixelSpace(DeltaEngine.Datatypes.Rectangle)
[Test]
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))));
}
[Test]
public void LoopingToAndFromPixelSpaceLeavesAPointUnchanged()
{
    var camera = new Camera2DScreenSpace(window)
    {
        LookAt = new Vector2D(-0.5f, 0.6f),
        Zoom = 3.0f
    };
    Assert.IsTrue(
        camera.ToPixelSpace(camera.FromPixelSpace(new Vector2D(1.2f, 3.4f))).IsNearlyEqual(
            new Vector2D(1.2f, 3.4f)));
    Assert.IsTrue(
        camera.FromPixelSpace(camera.ToPixelSpace(new Vector2D(1.2f, 3.4f))).IsNearlyEqual(
            new Vector2D(1.2f, 3.4f)));
}
[Test]
public void FromPixelSpace()
{
    var camera = new Camera2DScreenSpace(window)
    {
        LookAt = new Vector2D(-0.5f, 0.6f),
        Zoom = 2.0f
    };
    Assert.IsTrue(
        camera.FromPixelSpace(Vector2D.Zero).IsNearlyEqual(new Vector2D(-0.75f, 0.459375f)));
    Assert.IsTrue(
        camera.FromPixelSpace((Vector2D)window.ViewportPixelSize).IsNearlyEqual(new Vector2D(
            -0.25f, 0.740625f)));
    Assert.AreEqual(camera.LookAt, camera.FromPixelSpace((Vector2D)window.ViewportPixelSize / 2));
}
Examples

3 unit tests call DeltaEngine.ScreenSpaces.ScreenSpace.FromPixelSpace(DeltaEngine.Datatypes.Rectangle)
[Test]
public void SquareWindowWithPixelSpace()
{
    var screen = new PixelScreenSpace(window);
    Assert.AreEqual(Vector2D.Zero, screen.TopLeft);
    Assert.AreEqual(window.ViewportPixelSize, (Size)screen.BottomRight);
    Assert.AreEqual(new Rectangle(Vector2D.Zero, window.TotalPixelSize), screen.Viewport);
    Assert.AreEqual(new Vector2D(100, 100), screen.FromPixelSpace(new Vector2D(100, 100)));
    Assert.AreEqual(new Rectangle(10, 10, 80, 80),
        screen.FromPixelSpace(new Rectangle(10, 10, 80, 80)));
    window.CloseAfterFrame();
}
[Test]
public void ToPixelSpaceAndFromPixelSpace()
{
    var pixelScreen = new PixelScreenSpace(window);
    Assert.AreEqual(pixelScreen.TopLeft, pixelScreen.ToPixelSpace(pixelScreen.TopLeft));
    Assert.AreEqual(pixelScreen.BottomRight, pixelScreen.ToPixelSpace(pixelScreen.BottomRight));
    Assert.AreEqual(Size.Zero, pixelScreen.ToPixelSpace(Size.Zero));
    Assert.AreEqual(Size.One, pixelScreen.ToPixelSpace(Size.One));
    window.CloseAfterFrame();
}
[Test]
public void SquareWindow()
{
    var pixelScreen = new PixelScreenSpace(window);
    window.ViewportPixelSize = new Size(100, 100);
    Assert.AreEqual(Vector2D.Zero, pixelScreen.TopLeft);
    Assert.AreEqual(new Vector2D(100, 100), pixelScreen.BottomRight);
    Assert.AreEqual(new Rectangle(0, 0, 100, 100), pixelScreen.Viewport);
    Assert.AreEqual(new Vector2D(100, 100), pixelScreen.FromPixelSpace(new Vector2D(100, 100)));
    Assert.AreEqual(new Vector2D(50, 50), pixelScreen.FromPixelSpace(new Vector2D(50, 50)));
}
Examples

1 unit tests call DeltaEngine.ScreenSpaces.ScreenSpace.FromPixelSpace(DeltaEngine.Datatypes.Rectangle)
[Test]
public void ToRelativeWithUnevenSize()
{
    window.ViewportPixelSize = new Size(99, 199);
    var screen = new RelativeScreenSpace(window);
    Assert.AreEqual(Vector2D.Zero, screen.TopLeft);
    Assert.AreEqual(Vector2D.One, screen.BottomRight);
    Assert.AreEqual(screen.BottomRight, screen.FromPixelSpace(new Vector2D(99, 199)));
}
See Also