Numworks Epsilon  1.4.1
Graphing Calculator Operating System
rect.cpp
Go to the documentation of this file.
1 #include <quiz.h>
2 #include <kandinsky.h>
3 #include <assert.h>
4 
5 QUIZ_CASE(kandinsky_rect_intersect) {
6  KDRect a(-5,-5, 10, 10);
7  KDRect b(0, 0, 10, 10);
8  assert(a.intersects(b));
9  assert(b.intersects(a));
10  KDRect c = a.intersectedWith(b);
11  assert(c.x() == 0);
12  assert(c.y() == 0);
13  assert(c.width() == 5);
14  assert(c.height() == 5);
15  c = b.intersectedWith(a);
16  assert(c.x() == 0);
17  assert(c.y() == 0);
18  assert(c.width() == 5);
19  assert(c.height() == 5);
20 }
21 
22 QUIZ_CASE(kandinsky_rect_union) {
23  KDRect a(-5, -5, 10, 10);
24  KDRect b(0, 0, 10, 10);
25  KDRect c = a.unionedWith(b);
26  assert(c.x() == -5);
27  assert(c.y() == -5);
28  assert(c.width() == 15);
29  assert(c.height() == 15);
30 
31  c = a.unionedWith(b);
32  assert(c.x() == -5);
33  assert(c.y() == -5);
34  assert(c.width() == 15);
35  assert(c.height() == 15);
36 }
37 
38 QUIZ_CASE(kandinsky_rect_empty_union) {
39  KDRect a(1, 2, 3, 4);
40  KDRect b(5, 6, 0, 0);
41  KDRect c(-2, -1, 0, 1);
42 
43  KDRect t = a.unionedWith(b);
44  assert(t.x() == a.x());
45  assert(t.y() == a.y());
46  assert(t.width() == a.width());
47  assert(t.height() == a.height());
48 
49  t = b.unionedWith(a);
50  assert(t.x() == a.x());
51  assert(t.y() == a.y());
52  assert(t.width() == a.width());
53  assert(t.height() == a.height());
54 
55  t = a.unionedWith(c);
56  assert(t.x() == a.x());
57  assert(t.y() == a.y());
58  assert(t.width() == a.width());
59  assert(t.height() == a.height());
60 }
#define assert(e)
Definition: assert.h:9
KDCoordinate x() const
Definition: rect.h:36
KDRect unionedWith(const KDRect &other) const
Definition: rect.cpp:71
c(generic_all_nodes)
KDCoordinate y() const
Definition: rect.h:37
Definition: rect.h:26
KDCoordinate width() const
Definition: rect.h:39
QUIZ_CASE(kandinsky_rect_intersect)
Definition: rect.cpp:5
KDRect intersectedWith(const KDRect &other) const
Definition: rect.cpp:33
KDCoordinate height() const
Definition: rect.h:40
bool intersects(const KDRect &other) const
Definition: rect.cpp:24