1 module anchovy.utils.rectoffset; 2 3 import std.conv; 4 5 /++ 6 + Offset for different things like borders 7 +/ 8 struct RectOffset 9 { 10 union 11 { 12 struct 13 { 14 int left; 15 int right; 16 int top; 17 int bottom; 18 } 19 int[4] arrayof; 20 } 21 22 string toString() const 23 { 24 return to!string(arrayof); 25 } 26 27 this(int a) 28 { 29 left = a; 30 right = a; 31 top = a; 32 bottom = a; 33 } 34 35 this(int[4] array) 36 { 37 arrayof = array; 38 } 39 40 this(int a, int b, int c, int d) 41 { 42 left = a; 43 right = b; 44 top = c; 45 bottom = d; 46 } 47 48 int horizontal() @property @safe nothrow 49 { 50 return left + right; 51 } 52 53 int vertical() @property @safe nothrow 54 { 55 return top + bottom; 56 } 57 } 58 59 unittest 60 { 61 RectOffset ro = RectOffset(10, 15, 20, 25); 62 63 assert(ro.horizontal == ro.left + ro.right); 64 assert(ro.vertical == ro.top + ro.bottom); 65 }