1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-20 20:19:57 +01:00

Add tests

This commit is contained in:
Miloslav Číž 2018-09-04 13:01:14 +02:00
parent b1146d8f05
commit b59f44048b
2 changed files with 72 additions and 2 deletions

View file

@ -58,6 +58,17 @@ typedef uint16_t uint_maybe32_t;
printf(" dist: %d\n", h.distance);\
printf(" texcoord: %d\n", h.textureCoord);}\
#define logPixelInfo(p){\
printf("pixel:\n");\
printf(" position: ");\
logVector2D(p.position);\
printf(" depth: %d\n", p.depth);\
printf(" wall: %d\n", p.isWall);\
printf(" textCoordY: %d\n", p.textureCoordY);\
printf(" hit: ");\
logHitResult(p.hit);\
}\
/// Position in 2D space.
typedef struct
{
@ -800,7 +811,7 @@ PixelInfo mapToScreen(Vector2D worldPosition, Unit height, Camera camera)
result.position.x = (a * middleColumn) / b;
result.position.x = 2 * (middleColumn - result.position.x);
// TODO: ^ why is this 2 here?
return result;
}

61
test.c
View file

@ -57,6 +57,49 @@ int testSingleRay(Unit startX, Unit startY, Unit dirX, Unit dirY,
return result;
}
int testSingleMapping(Unit posX, Unit posY, Unit posZ, uint32_t resX,
uint32_t resY, Unit camX, Unit camY, Unit camZ, Unit camDir, Unit fov,
Unit expectX, Unit expectY, Unit expectZ)
{
int result;
Camera c;
c.resolution.x = resX;
c.resolution.y = resY;
c.position.x = camY;
c.position.y = camY;
c.direction = camDir;
c.height = posZ;
c.fovAngle = fov;
Vector2D pos;
Unit height;
pos.x = posX;
pos.y = posY;
height = posZ;
PixelInfo p;
printf("- mapping pixel: %d %d %d\n",posX,posY,posZ);
p = mapToScreen(pos,height,c);
printf("- result:\n");
logPixelInfo(p);
result = p.position.x == expectX && p.position.y == expectY &&
p.depth == expectZ;
if (result)
printf("\nOK\n\n");
else
printf("\nFAIL\n\n");
return result;
}
// returns milliseconds
long measureTime(void (*func)(void))
{
@ -95,7 +138,6 @@ void benchCastRays()
void benchmarkMapping()
{
Vector2D v;
Camera c;
c.resolution.x = 1024;
@ -165,6 +207,23 @@ int main()
16))
return 1;
if (!testSingleMapping(
-UNITS_PER_SQUARE,
0,
UNITS_PER_SQUARE / 2,
1280,
640,
0,
0,
0,
UNITS_PER_SQUARE / 2,
UNITS_PER_SQUARE / 4,
1280, // shouldn't be half?
320,
1024
))
return -1;
for (Unit i = -UNITS_PER_SQUARE; i <= UNITS_PER_SQUARE; i += 64)
{
Unit v = sinInt(i);