comparison dynamin/painting/coordinates.d @ 101:1690ebff00a0

Add opIndex and opIndexAssign and tests to Point, Size, etc.
author Jordan Miner <jminer7@gmail.com>
date Tue, 15 May 2012 20:54:39 -0500
parents 4f2d709760eb
children 73060bc3f004
comparison
equal deleted inserted replaced
100:4f2d709760eb 101:1690ebff00a0
13 * License. 13 * License.
14 * 14 *
15 * The Original Code is the Dynamin library. 15 * The Original Code is the Dynamin library.
16 * 16 *
17 * The Initial Developer of the Original Code is Jordan Miner. 17 * The Initial Developer of the Original Code is Jordan Miner.
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009 18 * Portions created by the Initial Developer are Copyright (C) 2006-2012
19 * the Initial Developer. All Rights Reserved. 19 * the Initial Developer. All Rights Reserved.
20 * 20 *
21 * Contributor(s): 21 * Contributor(s):
22 * Jordan Miner <jminer7@gmail.com> 22 * Jordan Miner <jminer7@gmail.com>
23 * 23 *
51 void x(float f) { _values[0] = f; } 51 void x(float f) { _values[0] = f; }
52 /// 52 ///
53 float y() { return _values[1]; } 53 float y() { return _values[1]; }
54 /// 54 ///
55 void y(float f) { _values[1] = f; } 55 void y(float f) { _values[1] = f; }
56 ///
57 float opIndex(int index) { return _values[index]; }
58 ///
59 float opIndexAssign(float f, int index) { return _values[index] = f; }
56 /// 60 ///
57 Point opNeg() { 61 Point opNeg() {
58 Point pt2; 62 Point pt2;
59 pt2.x = -x; 63 pt2.x = -x;
60 pt2.y = -y; 64 pt2.y = -y;
111 void width(float f) { _values[0] = f; } 115 void width(float f) { _values[0] = f; }
112 /// 116 ///
113 float height() { return _values[1]; } 117 float height() { return _values[1]; }
114 /// 118 ///
115 void height(float f) { _values[1] = f; } 119 void height(float f) { _values[1] = f; }
120 ///
121 float opIndex(int index) { return _values[index]; }
122 ///
123 float opIndexAssign(float f, int index) { return _values[index] = f; }
116 /// 124 ///
117 Size opAdd(Size size) { 125 Size opAdd(Size size) {
118 Size size2; 126 Size size2;
119 size2.width = width + size.width; 127 size2.width = width + size.width;
120 size2.height = height + size.height; 128 size2.height = height + size.height;
185 void right(float f) { width = f - x; } 193 void right(float f) { width = f - x; }
186 /// 194 ///
187 float bottom() { return y + height; } 195 float bottom() { return y + height; }
188 /// 196 ///
189 void bottom(float f) { height = f - y; } 197 void bottom(float f) { height = f - y; }
198 ///
199 float opIndex(int index) { return _values[index]; }
200 ///
201 float opIndexAssign(float f, int index) { return _values[index] = f; }
190 /// 202 ///
191 Rect opAdd(Rect rect) { 203 Rect opAdd(Rect rect) {
192 Rect rect2; 204 Rect rect2;
193 rect2.x = x + rect.x; 205 rect2.x = x + rect.x;
194 rect2.y = y + rect.y; 206 rect2.y = y + rect.y;
328 /// 340 ///
329 float bottom() { return _values[3]; } 341 float bottom() { return _values[3]; }
330 /// 342 ///
331 void bottom(float f) { _values[3] = f; } 343 void bottom(float f) { _values[3] = f; }
332 /// 344 ///
345 float opIndex(int index) { return _values[index]; }
346 ///
347 float opIndexAssign(float f, int index) { return _values[index] = f; }
348 ///
333 BorderSize opAdd(BorderSize border) { 349 BorderSize opAdd(BorderSize border) {
334 BorderSize border2; 350 BorderSize border2;
335 border2.left = left + border.left; 351 border2.left = left + border.left;
336 border2.right = right + border.right; 352 border2.right = right + border.right;
337 border2.top = top + border.top; 353 border2.top = top + border.top;
352 left, top, right, bottom); 368 left, top, right, bottom);
353 } 369 }
354 } 370 }
355 371
356 unittest { 372 unittest {
357 Point pt = Point(7, 9); 373 Point pt;
374 Size sz;
375 Rect rect;
376 BorderSize border;
377
378 assert(pt.x == 0 && pt.y == 0);
379
380 pt = Point(7, 9);
358 assert(pt.x == 7); 381 assert(pt.x == 7);
359 assert(pt.y == 9); 382 assert(pt.y == 9);
360 Rect rect = pt + Size(15, 13); 383 rect = pt + Size(15, 13);
361 assert(rect == Rect(7, 9, 15, 13)); 384 assert(rect == Rect(7, 9, 15, 13));
362 assert(Size(15, 10) + BorderSize(3, 5, 1, 7) == Size(19, 22)); 385 assert(Size(15, 10) + BorderSize(3, 5, 1, 7) == Size(19, 22));
363 } 386
364 387 pt = Point(1, 2);
388 assert(pt[0] == 1 && pt[1] == 2);
389 pt[0] = 13;
390 assert(pt[0] == 13);
391
392 sz = Size(20, 30);
393 assert(sz[0] == 20 && sz[1] == 30);
394 sz[1] = 35;
395 assert(sz[0] == 20 && sz[1] == 35);
396
397 rect = Rect(1, 2, 3, 4);
398 assert(rect[0] == 1 && rect[1] == 2 && rect[2] == 3 && rect[3] == 4);
399 rect[2] = 5;
400 assert(rect[2] == 5);
401
402 border = BorderSize(5, 6, 7, 8);
403 assert(border[0] == 5 && border[1] == 6 && border[2] == 7 && border[3] == 8);
404 }
405