mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
Migrate Kandinsky to C++
Change-Id: I2752a8db84ad0bb817119cf6c2993c1622621150
This commit is contained in:
@@ -3,15 +3,17 @@
|
||||
#include <assert.h>
|
||||
|
||||
QUIZ_CASE(kandinsky_color_rgb) {
|
||||
assert(KDColorRGB(0xFF, 0, 0) == 0xF800);
|
||||
assert(KDColorRGB(0, 0xFF, 0) == 0x07E0);
|
||||
assert(KDColorRGB(0, 0, 0xFF) == 0x1F);
|
||||
assert(sizeof(KDColor) == 2); // We really want KDColor to be packed
|
||||
|
||||
assert(KDColor(0xFF0000) == 0xF800);
|
||||
assert(KDColor(0x00FF00) == 0x07E0);
|
||||
assert(KDColor(0x0000FF) == 0x1F);
|
||||
/* R = 0x12 = 0b 0001 0010. 5 most important bits are 00010.
|
||||
* G = 0x34 = 0b 0011 0100. 6 most important bits are 001101.
|
||||
* B = 0x56 = 0b 0101 0110. 5 most important bits are 01010.
|
||||
* KDColor = 0b 00010 001101 01010
|
||||
* = 0b 0001 0001 1010 1010
|
||||
* = 0x 1 1 A A */
|
||||
assert(KDColorRGB(0x12, 0x34, 0x56) == 0x11AA);
|
||||
assert(KDColor(0x123456) == 0x11AA);
|
||||
}
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
#include <quiz.h>
|
||||
#include <kandinsky.h>
|
||||
#include <assert.h>
|
||||
|
||||
QUIZ_CASE(kandinsky_rect_intersect) {
|
||||
KDRect a = {
|
||||
.x = -5, .y = -5,
|
||||
.width = 10, .height = 10
|
||||
};
|
||||
KDRect b = {
|
||||
.x = 0, .y = 0,
|
||||
.width = 10, .height = 10
|
||||
};
|
||||
assert(KDRectIntersect(a,b));
|
||||
assert(KDRectIntersect(b,a));
|
||||
KDRect c = KDRectIntersection(a,b);
|
||||
assert(c.x == 0);
|
||||
assert(c.y == 0);
|
||||
assert(c.width == 5);
|
||||
assert(c.height == 5);
|
||||
c = KDRectIntersection(b,a);
|
||||
assert(c.x == 0);
|
||||
assert(c.y == 0);
|
||||
assert(c.width == 5);
|
||||
assert(c.height == 5);
|
||||
}
|
||||
|
||||
QUIZ_CASE(kandinsky_rect_union) {
|
||||
KDRect a = {
|
||||
.x = -5, .y = -5,
|
||||
.width = 10, .height = 10
|
||||
};
|
||||
KDRect b = {
|
||||
.x = 0, .y = 0,
|
||||
.width = 10, .height = 10
|
||||
};
|
||||
|
||||
KDRect c = KDRectUnion(a,b);
|
||||
assert(c.x == -5);
|
||||
assert(c.y == -5);
|
||||
assert(c.width == 15);
|
||||
assert(c.height == 15);
|
||||
|
||||
c = KDRectUnion(a,b);
|
||||
assert(c.x == -5);
|
||||
assert(c.y == -5);
|
||||
assert(c.width == 15);
|
||||
assert(c.height == 15);
|
||||
}
|
||||
|
||||
QUIZ_CASE(kandinsky_rect_empty_union) {
|
||||
KDRect a = {
|
||||
.x = 1, .y = 2,
|
||||
.width = 3, .height = 4
|
||||
};
|
||||
KDRect b = {
|
||||
.x = 5, .y = 6,
|
||||
.width = 0, .height = 0
|
||||
};
|
||||
KDRect c = {
|
||||
.x = -2, .y = -1,
|
||||
.width = 0, .height = 1
|
||||
};
|
||||
|
||||
KDRect t = KDRectUnion(a,b);
|
||||
assert(t.x == a.x);
|
||||
assert(t.y == a.y);
|
||||
assert(t.width == a.width);
|
||||
assert(t.height == a.height);
|
||||
|
||||
t = KDRectUnion(b,a);
|
||||
assert(t.x == a.x);
|
||||
assert(t.y == a.y);
|
||||
assert(t.width == a.width);
|
||||
assert(t.height == a.height);
|
||||
|
||||
t = KDRectUnion(a,c);
|
||||
assert(t.x == a.x);
|
||||
assert(t.y == c.y);
|
||||
assert(t.width == a.width);
|
||||
assert(t.height == 7);
|
||||
}
|
||||
60
kandinsky/test/rect.cpp
Normal file
60
kandinsky/test/rect.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <quiz.h>
|
||||
#include <kandinsky.h>
|
||||
#include <assert.h>
|
||||
|
||||
QUIZ_CASE(kandinsky_rect_intersect) {
|
||||
KDRect a(-5,-5, 10, 10);
|
||||
KDRect b(0, 0, 10, 10);
|
||||
assert(a.intersects(b));
|
||||
assert(b.intersects(a));
|
||||
KDRect c = a.intersectedWith(b);
|
||||
assert(c.x() == 0);
|
||||
assert(c.y() == 0);
|
||||
assert(c.width() == 5);
|
||||
assert(c.height() == 5);
|
||||
c = b.intersectedWith(a);
|
||||
assert(c.x() == 0);
|
||||
assert(c.y() == 0);
|
||||
assert(c.width() == 5);
|
||||
assert(c.height() == 5);
|
||||
}
|
||||
|
||||
QUIZ_CASE(kandinsky_rect_union) {
|
||||
KDRect a(-5, -5, 10, 10);
|
||||
KDRect b(0, 0, 10, 10);
|
||||
KDRect c = a.unionedWith(b);
|
||||
assert(c.x() == -5);
|
||||
assert(c.y() == -5);
|
||||
assert(c.width() == 15);
|
||||
assert(c.height() == 15);
|
||||
|
||||
c = a.unionedWith(b);
|
||||
assert(c.x() == -5);
|
||||
assert(c.y() == -5);
|
||||
assert(c.width() == 15);
|
||||
assert(c.height() == 15);
|
||||
}
|
||||
|
||||
QUIZ_CASE(kandinsky_rect_empty_union) {
|
||||
KDRect a(1, 2, 3, 4);
|
||||
KDRect b(5, 6, 0, 0);
|
||||
KDRect c(-2, -1, 0, 1);
|
||||
|
||||
KDRect t = a.unionedWith(b);
|
||||
assert(t.x() == a.x());
|
||||
assert(t.y() == a.y());
|
||||
assert(t.width() == a.width());
|
||||
assert(t.height() == a.height());
|
||||
|
||||
t = b.unionedWith(a);
|
||||
assert(t.x() == a.x());
|
||||
assert(t.y() == a.y());
|
||||
assert(t.width() == a.width());
|
||||
assert(t.height() == a.height());
|
||||
|
||||
t = a.unionedWith(c);
|
||||
assert(t.x() == a.x());
|
||||
assert(t.y() == c.y());
|
||||
assert(t.width() == a.width());
|
||||
assert(t.height() == 7);
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <quiz.h>
|
||||
#include <kandinsky.h>
|
||||
|
||||
QUIZ_CASE(setpixel) {
|
||||
}
|
||||
Reference in New Issue
Block a user