Function as

Convert a PixelCoord to a user-defined (x,y) numeric pair.

Prototype

T as(T)(
  PixelCoord pos
)
if (isPixelCoord!T);

Example

Convert dtiled's pixel-space coordinates to your own types:

// your own representation may be a struct
struct MyVector(T) { T x, y; }

assert(PixelCoord(5, 10).as!(MyVector!double) == MyVector!double(5, 10));
assert(PixelCoord(5.5, 10.2).as!(MyVector!int) == MyVector!int(5, 10));

// or it may be a tuple
alias MyPoint(T) = Tuple!(T, "x", T, "y");

assert(PixelCoord(5, 10).as!(MyPoint!double) == MyPoint!double(5, 10));
assert(PixelCoord(5.5, 10.2).as!(MyPoint!int) == MyPoint!int(5, 10));

// std.conv.to is used internally, so it should detect overflow
import std.conv : ConvOverflowException;
import std.exception : assertThrown;
assertThrown!ConvOverflowException(PixelCoord(-1, -1).as!(MyVector!ulong));

Authors

Copyright

License