1 /** 2 Copyright: Copyright (c) 2017-2018 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 7 module voxelman.math.offset4; 8 9 alias margins4 = offset4; 10 alias borders4 = offset4; 11 alias padding4 = offset4; 12 13 /// Used to set size of borders, padding, margins, spacing etc 14 struct offset4 15 { 16 union 17 { 18 struct 19 { 20 int left; 21 int right; 22 int top; 23 int bottom; 24 } 25 int[4] arrayof; 26 } 27 28 void toString()(scope void delegate(const(char)[]) sink) const 29 { 30 import std.string : formattedWrite; 31 return formattedWrite(sink, "offset4(%s, %s, %s, %s)", left, right, top, bottom); 32 } 33 34 this(int off) 35 { 36 arrayof[] = off; 37 } 38 39 this(int[4] array) 40 { 41 arrayof = array; 42 } 43 44 this(int l, int r, int t, int b) 45 { 46 left = l; 47 right = r; 48 top = t; 49 bottom = b; 50 } 51 52 this(int hor, int vert) 53 { 54 left = hor; 55 right = hor; 56 top = vert; 57 bottom = vert; 58 } 59 60 int hori() const @property nothrow @nogc 61 { 62 return left + right; 63 } 64 65 int vert() const @property nothrow @nogc 66 { 67 return top + bottom; 68 } 69 }