IWindow2D

Namespace: Digi21.Math
Assembly: Digi21.DigiNG

Window (axis-aligned rectangle) in the X, Y plane: minimum and maximum coordinates, dimensions, center and cardinal points.

public interface IWindow2D

Types implementing the interface: Window2D.

An uninitialized window has Xmin set to null. Window2D throws InvalidOperationException when reading Width, Height, Center or one of the eight cardinal points of an uninitialized window. Check Valid before reading Width, Height, Center or one of the eight cardinal points.

Properties

Property Description
double? Xmin Minimum X coordinate, or null if the window is uninitialized.
double Ymin Minimum Y coordinate.
double Xmax Maximum X coordinate.
double Ymax Maximum Y coordinate.
bool Valid true if Xmin is not null, Xmin <= Xmax and Ymin <= Ymax.
double Width Xmax - Xmin.
double Height Ymax - Ymin.
Point2D Center Window center.
Point2D NW Northwest corner: (Xmin, Ymax).
Point2D N Midpoint of the north side.
Point2D NE Northeast corner: (Xmax, Ymax).
Point2D E Midpoint of the east side.
Point2D SE Southeast corner: (Xmax, Ymin).
Point2D S Midpoint of the south side.
Point2D SW Southwest corner: (Xmin, Ymin).
Point2D W Midpoint of the west side.

Example

The Muestra method takes any IWindow2D and reads dimensions only if the window is valid:

using Digi21.Math;

Point2D[] puntos =
{
    new Point2D(440000, 4470000),
    new Point2D(440250, 4470100),
    new Point2D(440120, 4469900),
};

// A Window2D created with new Window2D() is uninitialized: Xmin is null.
var envolvente = new Window2D();
Console.WriteLine(envolvente.Valid);        // False

foreach (var punto in puntos)
    envolvente.Union(punto);

Muestra(envolvente);

var hoja = new Window2D(440100, 4469950, 440500, 4470300);
Console.WriteLine(hoja.Contains(puntos[1]));          // True
Console.WriteLine(envolvente.Intersects(hoja));       // True

var comun = envolvente.Intersection(hoja);
Muestra(comun);

var lejana = new Window2D(500000, 4400000, 500100, 4400100);
var vacia = envolvente.Intersection(lejana);
Console.WriteLine(vacia.Valid);             // False: the windows do not overlap

// Expand by 10 units on each side.
envolvente.Inflate(10, 10);
Muestra(envolvente);

static void Muestra(IWindow2D ventana)
{
    if (!ventana.Valid)
    {
        Console.WriteLine("Ventana no válida");
        return;
    }

    Console.WriteLine($"X: {ventana.Xmin} a {ventana.Xmax}, Y: {ventana.Ymin} a {ventana.Ymax}");
    Console.WriteLine($"Ancho {ventana.Width}, alto {ventana.Height}, centro {ventana.Center}");
}