annotate dynamin/painting/coordinates.d @ 103:73060bc3f004

Change license to Boost 1.0 and MPL 2.0.
author Jordan Miner <jminer7@gmail.com>
date Tue, 15 May 2012 22:06:02 -0500
parents 1690ebff00a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
1
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
2 /*
103
73060bc3f004 Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents: 101
diff changeset
3 * Copyright Jordan Miner
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
4 *
103
73060bc3f004 Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents: 101
diff changeset
5 * This Source Code Form is subject to the terms of the Mozilla Public
73060bc3f004 Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents: 101
diff changeset
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
73060bc3f004 Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents: 101
diff changeset
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
8 *
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
9 */
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
10
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
11 module dynamin.painting.coordinates;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
12
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
13 import dynamin.core.string;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
14 import dynamin.core.math;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
15
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
16 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
17 struct Point {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
18 private:
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
19 float[2] _values = [0, 0];
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
20 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
21 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
22 static Point opCall() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
23 Point pt;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
24 return pt;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
25 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
26 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
27 static Point opCall(float x, float y) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
28 Point pt;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
29 pt.x = x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
30 pt.y = y;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
31 return pt;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
32 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
33 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
34 float x() { return _values[0]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
35 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
36 void x(float f) { _values[0] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
37 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
38 float y() { return _values[1]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
39 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
40 void y(float f) { _values[1] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
41 ///
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
42 float opIndex(int index) { return _values[index]; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
43 ///
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
44 float opIndexAssign(float f, int index) { return _values[index] = f; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
45 ///
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
46 Point opNeg() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
47 Point pt2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
48 pt2.x = -x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
49 pt2.y = -y;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
50 return pt2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
51 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
52 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
53 Point opAdd(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
54 Point pt2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
55 pt2.x = x + pt.x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
56 pt2.y = y + pt.y;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
57 return pt2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
58 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
59 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
60 Point opSub(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
61 Point pt2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
62 pt2.x = x - pt.x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
63 pt2.y = y - pt.y;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
64 return pt2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
65 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
66 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
67 Rect opAdd(Size size) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
68 Rect rect;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
69 rect.x = x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
70 rect.y = y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
71 rect.width = size.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
72 rect.height = size.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
73 return rect;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
74 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
75 string toString() {
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
76 return format("Point [x={}, y={}]", x, y);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
77 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
78 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
79
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
80 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
81 struct Size {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
82 private:
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
83 float[2] _values = [0, 0];
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
84 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
85 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
86 static Size opCall() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
87 Size size;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
88 return size;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
89 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
90 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
91 static Size opCall(float width, float height) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
92 Size size;
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
93 size.width = width;
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
94 size.height = height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
95 return size;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
96 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
97 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
98 float width() { return _values[0]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
99 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
100 void width(float f) { _values[0] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
101 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
102 float height() { return _values[1]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
103 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
104 void height(float f) { _values[1] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
105 ///
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
106 float opIndex(int index) { return _values[index]; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
107 ///
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
108 float opIndexAssign(float f, int index) { return _values[index] = f; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
109 ///
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
110 Size opAdd(Size size) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
111 Size size2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
112 size2.width = width + size.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
113 size2.height = height + size.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
114 return size2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
115 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
116 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
117 Size opSub(Size size) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
118 Size size2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
119 size2.width = width - size.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
120 size2.height = height - size.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
121 return size2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
122 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
123 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
124 Size opAdd(BorderSize border) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
125 Size size2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
126 size2.width = width + border.left + border.right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
127 size2.height = height + border.top + border.bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
128 return size2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
129 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
130 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
131 Size opSub(BorderSize border) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
132 Size size2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
133 size2.width = width - border.left - border.right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
134 size2.height = height - border.top - border.bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
135 return size2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
136 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
137 string toString() {
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
138 return format("Size [width={}, height={}]", width, height);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
139 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
140 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
141
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
142 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
143 struct Rect {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
144 private:
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
145 float[4] _values = [0, 0, 0, 0];
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
146 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
147 static Rect opCall() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
148 Rect rect;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
149 return rect;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
150 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
151 static Rect opCall(float x, float y, float width, float height) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
152 Rect rect;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
153 rect.x = x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
154 rect.y = y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
155 rect.width = width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
156 rect.height = height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
157 return rect;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
158 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
159 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
160 float x() { return _values[0]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
161 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
162 void x(float f) { _values[0] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
163 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
164 float y() { return _values[1]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
165 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
166 void y(float f) { _values[1] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
167 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
168 float width() { return _values[2]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
169 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
170 void width(float f) { _values[2] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
171 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
172 float height() { return _values[3]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
173 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
174 void height(float f) { _values[3] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
175 ///
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
176 float right() { return x + width; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
177 ///
98
e7e36dca4768 Add setters for Rect.right and Rect.bottom.
Jordan Miner <jminer7@gmail.com>
parents: 97
diff changeset
178 void right(float f) { width = f - x; }
e7e36dca4768 Add setters for Rect.right and Rect.bottom.
Jordan Miner <jminer7@gmail.com>
parents: 97
diff changeset
179 ///
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
180 float bottom() { return y + height; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
181 ///
98
e7e36dca4768 Add setters for Rect.right and Rect.bottom.
Jordan Miner <jminer7@gmail.com>
parents: 97
diff changeset
182 void bottom(float f) { height = f - y; }
e7e36dca4768 Add setters for Rect.right and Rect.bottom.
Jordan Miner <jminer7@gmail.com>
parents: 97
diff changeset
183 ///
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
184 float opIndex(int index) { return _values[index]; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
185 ///
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
186 float opIndexAssign(float f, int index) { return _values[index] = f; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
187 ///
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
188 Rect opAdd(Rect rect) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
189 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
190 rect2.x = x + rect.x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
191 rect2.y = y + rect.y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
192 rect2.width = width + rect.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
193 rect2.height = height + rect.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
194 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
195 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
196 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
197 Rect opSub(Rect rect) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
198 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
199 rect2.x = x - rect.x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
200 rect2.y = y - rect.y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
201 rect2.width = width - rect.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
202 rect2.height = height - rect.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
203 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
204 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
205 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
206 Rect opAdd(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
207 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
208 rect2.x = x + pt.x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
209 rect2.y = y + pt.y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
210 rect2.width = width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
211 rect2.height = height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
212 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
213 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
214 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
215 Rect opSub(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
216 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
217 rect2.x = x - pt.x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
218 rect2.y = y - pt.y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
219 rect2.width = width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
220 rect2.height = height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
221 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
222 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
223 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
224 Rect opAdd(Size size) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
225 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
226 rect2.x = x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
227 rect2.y = y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
228 rect2.width = width + size.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
229 rect2.height = height + size.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
230 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
231 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
232 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
233 Rect opSub(Size size) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
234 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
235 rect2.x = x;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
236 rect2.y = y;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
237 rect2.width = width - size.width;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
238 rect2.height = height - size.height;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
239 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
240 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
241 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
242 Rect opAdd(BorderSize border) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
243 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
244 rect2.x = x - border.left;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
245 rect2.y = y - border.top;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
246 rect2.width = width + border.left + border.right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
247 rect2.height = height + border.top + border.bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
248 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
249 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
250 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
251 Rect opSub(BorderSize border) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
252 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
253 rect2.x = x + border.left;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
254 rect2.y = y + border.top;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
255 rect2.width = width - border.left - border.right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
256 rect2.height = height - border.top - border.bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
257 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
258 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
259 bool contains(Point pt) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
260 return pt.x >= x && pt.y >= y && pt.x < right && pt.y < bottom;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
261 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
262 Rect getUnion(Rect rect) {
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
263 auto x2 = min(x, rect.x);
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
264 auto y2 = min(y, rect.y);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
265 Rect rect2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
266 rect2.width = max(x + width, rect.x + rect.width ) - x2;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
267 rect2.height = max(y + height, rect.y + rect.height) - y2;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
268 rect2.x = x2;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
269 rect2.y = y2;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
270 return rect2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
271 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
272 string toString() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
273 return format("Rect [x={}, y={}, width={}, height={}]",
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
274 x, y, width, height);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
275 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
276 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
277 unittest {
99
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
278 assert(Rect(2, 3, 5, 9).right == 7);
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
279 assert(Rect(2, 3, 5, 9).bottom == 12);
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
280 // same
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
281 assert(Rect(1, 2, 3, 3).getUnion(Rect(1, 2, 3, 3)) == Rect(1, 2, 3, 3));
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
282 // second inside first
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
283 assert(Rect(1, 2, 5, 7.5).getUnion(Rect(3, 4, 1.5, 2)) == Rect(1, 2, 5, 7.5));
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
284 // second outside first
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
285 assert(Rect(1, 2, 5, 7.5).getUnion(Rect(0.5, 0.7, 10, 11)) == Rect(0.5, 0.7, 10, 11));
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
286 // second up left of first
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
287 assert(Rect(2, 3, 6, 8).getUnion(Rect(1, 2, 5, 6)) == Rect(1, 2, 7, 9));
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
288 // second down right of first
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
289 assert(Rect(2, 3, 6, 8).getUnion(Rect(5, 4, 7, 9)) == Rect(2, 3, 10, 10));
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
290 // not overlapping
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
291 assert(Rect(1, 2, 1, 3).getUnion(Rect(20, 30, 5, 5)) == Rect(1, 2, 24, 33));
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
292 // negative
8daa63a28707 Add more tests for Rect.getUnion().
Jordan Miner <jminer7@gmail.com>
parents: 98
diff changeset
293 assert(Rect(-4, -5, 2, 3).getUnion(Rect(-10, -2, 1, 5)) == Rect(-10, -5, 8, 8));
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
294 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
295
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
296 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
297 struct BorderSize {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
298 private:
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
299 float[4] _values = [0, 0, 0, 0];
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
300 public:
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
301 static BorderSize opCall() {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
302 BorderSize border;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
303 return border;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
304 }
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
305 static BorderSize opCall(float left, float top, float right, float bottom) {
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
306 BorderSize border;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
307 border.left = left;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
308 border.top = top;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
309 border.right = right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
310 border.bottom = bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
311 return border;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
312 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
313 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
314 float left() { return _values[0]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
315 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
316 void left(float f) { _values[0] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
317 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
318 float top() { return _values[1]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
319 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
320 void top(float f) { _values[1] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
321 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
322 float right() { return _values[2]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
323 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
324 void right(float f) { _values[2] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
325 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
326 float bottom() { return _values[3]; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
327 ///
100
4f2d709760eb Change from individual fields to a static array for x, y, width, height, etc.
Jordan Miner <jminer7@gmail.com>
parents: 99
diff changeset
328 void bottom(float f) { _values[3] = f; }
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
329 ///
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
330 float opIndex(int index) { return _values[index]; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
331 ///
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
332 float opIndexAssign(float f, int index) { return _values[index] = f; }
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
333 ///
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
334 BorderSize opAdd(BorderSize border) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
335 BorderSize border2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
336 border2.left = left + border.left;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
337 border2.right = right + border.right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
338 border2.top = top + border.top;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
339 border2.bottom = bottom + border.bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
340 return border2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
341 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
342 ///
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
343 BorderSize opSub(BorderSize border) {
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
344 BorderSize border2;
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
345 border2.left = left - border.left;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
346 border2.right = right - border.right;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
347 border2.top = top - border.top;
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
348 border2.bottom = bottom - border.bottom;
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
349 return border2;
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
350 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
351 string toString() {
97
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
352 return format("BorderSize [left={}, top={}, right={}, bottom={}]",
dccadd297348 Use methods/properties instead of the instance variables directly.
Jordan Miner <jminer7@gmail.com>
parents: 0
diff changeset
353 left, top, right, bottom);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
354 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
355 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
356
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
357 unittest {
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
358 Point pt;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
359 Size sz;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
360 Rect rect;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
361 BorderSize border;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
362
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
363 assert(pt.x == 0 && pt.y == 0);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
364
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
365 pt = Point(7, 9);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
366 assert(pt.x == 7);
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
367 assert(pt.y == 9);
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
368 rect = pt + Size(15, 13);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
369 assert(rect == Rect(7, 9, 15, 13));
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
370 assert(Size(15, 10) + BorderSize(3, 5, 1, 7) == Size(19, 22));
101
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
371
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
372 pt = Point(1, 2);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
373 assert(pt[0] == 1 && pt[1] == 2);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
374 pt[0] = 13;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
375 assert(pt[0] == 13);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
376
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
377 sz = Size(20, 30);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
378 assert(sz[0] == 20 && sz[1] == 30);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
379 sz[1] = 35;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
380 assert(sz[0] == 20 && sz[1] == 35);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
381
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
382 rect = Rect(1, 2, 3, 4);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
383 assert(rect[0] == 1 && rect[1] == 2 && rect[2] == 3 && rect[3] == 4);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
384 rect[2] = 5;
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
385 assert(rect[2] == 5);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
386
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
387 border = BorderSize(5, 6, 7, 8);
1690ebff00a0 Add opIndex and opIndexAssign and tests to Point, Size, etc.
Jordan Miner <jminer7@gmail.com>
parents: 100
diff changeset
388 assert(border[0] == 5 && border[1] == 6 && border[2] == 7 && border[3] == 8);
0
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
389 }
aa4efef0f0b1 Initial commit of code.
Jordan Miner <jminer7@gmail.com>
parents:
diff changeset
390