| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // Written in the D programming language.
- /**
- Copyright: Copyright Felix 'Zoadian' Hufnagel 2014-.
- License: $(WEB http://www.gnu.org/licenses/lgpl.html, LGPLv3).
- Authors: $(WEB zoadian.de, Felix 'Zoadian' Hufnagel)
- */
- module three.primitives.rect;
- import three.primitives.point;
- import std.traits;
- /**
- +--------> x
- |
- |
- |
- |
- v
-
- y
-
- */
- struct Rect2(T) if(isNumeric!T) {
- private:
- T[4] data; //l,t,r,b
- public:
- ///
- T x() const @safe nothrow @property {
- return this.left;
- }
-
- ///
- T y() const @safe nothrow @property {
- return this.top;
- }
-
- public:
- ///
- T left() const @safe nothrow @property {
- return data[0];
- }
-
- ///
- T top() const @safe nothrow @property {
- return data[1];
- }
-
- ///
- T right() const @safe nothrow @property {
- return data[2];
- }
-
- ///
- T bottom() const @safe nothrow @property {
- return data[3];
- }
-
- public:
- ///
- T width() const @safe nothrow @property {
- return this.right - this.left;
- }
-
- ///
- T height() const @safe nothrow @property {
- return this.bottom - this.top;
- }
-
- public:
- ///
- Point!(2,T) center() const @safe nothrow @property {
- return Point!(2,T)(this.x + this.width / 2, this.y + this.height / 2);
- }
-
- ///
- Point!(2,T) leftTop() const @safe nothrow @property {
- return Point!(2,T)(this.left, this.top);
- }
-
- ///
- Point!(2,T) rightTop() const @safe nothrow @property {
- return Point!(2,T)(this.right, this.top);
- }
-
- ///
- Point!(2,T) rightBottom() const @safe nothrow @property {
- return Point!(2,T)(this.right, this.bottom);
- }
-
- ///
- Point!(2,T) leftBottom() const @safe nothrow @property {
- return Point!(2,T)(this.left, this.bottom);
- }
- }
- ///
- struct RectOffset2(T) if(isNumeric!T) {
- private:
- T[4] data; //l,t,r,b
-
- public:
- ///
- T left() const @safe nothrow @property {
- return data[0];
- }
-
- ///
- T top() const @safe nothrow @property {
- return data[1];
- }
-
- ///
- T right() const @safe nothrow @property {
- return data[2];
- }
-
- ///
- T bottom() const @safe nothrow @property {
- return data[3];
- }
-
- public:
- /// equal to left + right
- T horizontal() const @safe nothrow @property {
- return this.left + this.right;
- }
-
- /// equal to top + bottom
- T vertical() const @safe nothrow @property {
- return this.top + this.bottom;
- }
- }
|