1 module evael.utils.Size; 2 3 struct Size(T) 4 { 5 public T[2] values; 6 public T halfWidth, halfHeight; 7 8 @nogc 9 public this(in T width, in T height) nothrow 10 { 11 this.values[0] = width; 12 this.values[1] = height; 13 this.halfWidth = width / 2; 14 this.halfHeight = height / 2; 15 } 16 17 /** 18 * == and != 19 */ 20 @nogc 21 public bool opEquals(Size!T b) const nothrow 22 { 23 return this.values[0] == b.values[0] && this.values[1] == b.values[1]; 24 } 25 26 /** 27 * += and -= 28 */ 29 @nogc 30 public void opOpAssign(string op)(in auto ref Size s) nothrow 31 { 32 mixin(q{ 33 this.values[0] " ~ op ~ "= s.width; 34 this.values[1] " ~ op ~ "= v.height; 35 }); 36 } 37 38 @nogc 39 @property 40 { 41 public T width() const 42 { 43 return this.values[0]; 44 } 45 46 public T height() const 47 { 48 return this.values[1]; 49 } 50 51 public void width(in T value) 52 { 53 this.values[0] = value; 54 this.halfWidth = value / 2; 55 } 56 57 public void height(in T value) 58 { 59 this.values[1] = value; 60 this.halfHeight = value / 2; 61 } 62 } 63 } 64