-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95c4e60
commit d933775
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(HmahBezierLibTests) | ||
|
||
unset(CMAKE_CXX_COMPILER) | ||
|
||
function(add_test TEST_NAME) | ||
add_executable(${TEST_NAME} "${TEST_NAME}.c") | ||
target_include_directories(${TEST_NAME} PRIVATE ../src) | ||
target_link_libraries(${TEST_NAME} PRIVATE hmahbezier) | ||
endfunction() | ||
|
||
add_test(linear_test) | ||
add_test(quadratic_test) | ||
add_test(cubic_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "bezier2.h" | ||
#include "test_plot.h" | ||
|
||
#include <stdio.h> | ||
|
||
#define PCOUNT 10 | ||
|
||
int main() { | ||
printf("Cubic bezier test with %d points\n", PCOUNT); | ||
|
||
const Bezier2f curve = Bezier2f_CreateCubic(0, 0, 20, 20, 20, 0, 40, 0); | ||
const float dt = 1.0f / (float)PCOUNT; | ||
|
||
Point2f points[PCOUNT]; | ||
|
||
float t = 0.0f; | ||
for (int i = 0; i < PCOUNT; i++, t += dt) | ||
points[i] = Bezier2f_Get(&curve, t); | ||
|
||
plot2Df((const float*)points, PCOUNT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "bezier2.h" | ||
#include "test_plot.h" | ||
|
||
#include <stdio.h> | ||
|
||
#define PCOUNT 10 | ||
|
||
int main() { | ||
printf("Linear bezier test with %d points\n", PCOUNT); | ||
|
||
const Bezier2f curve = Bezier2f_CreateLinear(0, 0, 20, 20); | ||
const float dt = 1.0f / (float)PCOUNT; | ||
|
||
Point2f points[PCOUNT]; | ||
|
||
float t = 0.0f; | ||
for (int i = 0; i < PCOUNT; i++, t += dt) | ||
points[i] = Bezier2f_Get(&curve, t); | ||
|
||
plot2Df((const float*)points, PCOUNT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "bezier2.h" | ||
#include "test_plot.h" | ||
|
||
#include <stdio.h> | ||
|
||
#define PCOUNT 10 | ||
|
||
int main() { | ||
printf("Quadratic bezier test with %d points\n", PCOUNT); | ||
|
||
const Bezier2f curve = Bezier2f_CreateQuadratic(0, 0, 20, 20, 40, 0); | ||
const float dt = 1.0f / (float)PCOUNT; | ||
|
||
Point2f points[PCOUNT]; | ||
|
||
float t = 0.0f; | ||
for (int i = 0; i < PCOUNT; i++, t += dt) | ||
points[i] = Bezier2f_Get(&curve, t); | ||
|
||
plot2Df((const float*)points, PCOUNT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef __HMAH_BEZIER_TEST_PLOT_H__ | ||
#define __HMAH_BEZIER_TEST_PLOT_H__ | ||
|
||
#include <stdio.h> | ||
#include <stddef.h> | ||
|
||
#define PLOT_FILL '#' | ||
#define PLOT_SPACE '.' | ||
#define PLOT_WIDTH 40 | ||
#define PLOT_HEIGHT 20 | ||
|
||
float absf(const float v) { | ||
return v < 0.0f ? -v : v; | ||
} | ||
|
||
void plot2Df(const float* points, const size_t pointsCount) { | ||
char canvas[PLOT_HEIGHT][PLOT_WIDTH]; | ||
for (int y = 0; y < PLOT_HEIGHT; y++) | ||
for (int x = 0; x < PLOT_WIDTH; x++) | ||
canvas[y][x] = PLOT_SPACE; | ||
|
||
for (size_t i = 0; i < pointsCount; i++) { | ||
const int x = (int)points[i * 2 + 0]; | ||
const int y = (int)points[i * 2 + 1]; | ||
if (x < 0 || x >= PLOT_WIDTH || y < 0 || y >= PLOT_HEIGHT) continue; | ||
canvas[y][x] = PLOT_FILL; | ||
} | ||
|
||
printf("Plot %dx%d\n", PLOT_WIDTH, PLOT_HEIGHT); | ||
for (int y = 0; y < PLOT_HEIGHT; y++) { | ||
for (int x = 0; x < PLOT_WIDTH; x++) { | ||
putchar(canvas[y][x]); | ||
} | ||
putchar('\n'); | ||
} | ||
} | ||
|
||
#endif // __HMAH_BEZIER_TEST_PLOT_H__ |