12 Commits

Author SHA1 Message Date
da2539692a chore: remove unity and fetch instead
All checks were successful
CI / build (pull_request) Successful in 15s
CI / build (push) Successful in 15s
2026-03-16 15:04:03 +01:00
acbbbc4436 bump version to 0.2.1
All checks were successful
CI / build (push) Successful in 13s
2026-03-16 11:21:33 +01:00
6cb9b4584c fix: export namespaced target
All checks were successful
CI / build (pull_request) Successful in 13s
CI / build (push) Successful in 13s
2026-03-16 11:11:05 +01:00
3ef3035cb5 Merge pull request 'release: release v0.2.0' (#12) from release/0.2.0 into main
All checks were successful
CI / build (push) Successful in 13s
Reviewed-on: #12
2026-03-15 02:24:09 +01:00
80a9457876 bump version to 0.2.0
All checks were successful
CI / build (push) Successful in 13s
CI / build (pull_request) Successful in 13s
2026-03-15 02:23:34 +01:00
9c33df5256 feat: update README.md
All checks were successful
CI / build (push) Successful in 13s
CI / build (pull_request) Successful in 12s
2026-03-15 02:17:57 +01:00
0279742c0e fix: only build tests if top level
All checks were successful
CI / build (pull_request) Successful in 13s
CI / build (push) Successful in 12s
2026-03-15 02:08:37 +01:00
4d9fd00784 fix: small improvements in the CMakeLists.txt
All checks were successful
CI / build (pull_request) Successful in 12s
CI / build (push) Successful in 13s
2026-03-15 01:11:50 +01:00
e9df33520a feat: add cmake config for building and installing
All checks were successful
CI / build (push) Successful in 13s
Reviewed-on: #8
2026-03-15 00:52:26 +01:00
11c891c2f1 test: add tests for vectors
All checks were successful
CI / build (pull_request) Successful in 13s
CI / build (push) Successful in 13s
2026-03-14 21:46:53 +01:00
fdb5dfd75e fix: link mathlib on Linux etc.
All checks were successful
CI / build (push) Successful in 12s
2026-03-14 17:35:06 +01:00
5e70354ec2 feat: add common vec2 and vec3 operations
Some checks failed
CI / build (push) Failing after 13s
2026-03-14 17:25:54 +01:00
8 changed files with 395 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
name: CI name: CI
on: [push, pull_request] on: [ push, pull_request ]
jobs: jobs:
build: build:

View File

@@ -1,27 +1,60 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(curtle VERSION 0.1.1 LANGUAGES C) project(curtle VERSION 0.2.2 LANGUAGES C)
add_library(curtle include(GNUInstallDirs)
src/vector.c include(CMakePackageConfigHelpers)
)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
add_library(curtle STATIC src/vector.c)
add_library(curtle::curtle ALIAS curtle)
target_include_directories(curtle target_include_directories(curtle
PUBLIC PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
) )
target_link_libraries(curtle PUBLIC m)
install(TARGETS curtle install(TARGETS curtle
EXPORT curtleTargets EXPORT curtleTargets
LIBRARY DESTINATION lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION lib ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
) )
install(DIRECTORY include/ DESTINATION include) install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
enable_testing() install(EXPORT curtleTargets
FILE curtleTargets.cmake
NAMESPACE curtle::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curtle
)
add_executable(test_vector tests/test_vector.c) write_basic_package_version_file(
target_link_libraries(test_vector curtle) ${CMAKE_CURRENT_BINARY_DIR}/curtleConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
add_test(NAME vector_test COMMAND test_vector) configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/curtleConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curtle
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/curtleConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/curtleConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/curtle
)
if(${PROJECT_IS_TOP_LEVEL})
enable_testing()
add_subdirectory(tests)
endif()

5
Config.cmake.in Normal file
View File

@@ -0,0 +1,5 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/curtleTargets.cmake")
check_required_components(curtle)

View File

@@ -1,3 +1,57 @@
![Logo](https://git.lowearthorbit.de/attachments/89a7215a-33ac-4284-a3c5-5647167802c3)
# curtle # curtle
Curtle is a smart turtle that helps you with math tasks. curtle is a simple open source cross platform math library for C.
## Roadmap
The goal of curtle is to provide an easy to use and easy to integrate math library. If you are interested in specific features please reach out to me!
- add much math tooling
- provide easy install via package managers etc.
## Features
- Basic operations on 2D Vectors
- Basic operations on 3D Vectors
## Installation
Clone the repository:
```
git clone https://git.lowearthorbit.de/lowearthorbit/curtle.git
cd curtle
```
You can build and install the library using cmake:
```
mkdir build && cd build
cmake ..
sudo cmake --install .
```
## Usage/Examples
Once installed, you can use curtle with CMake:
```CMake
find_package(curtle REQUIRED)
add_executable(myapp main.c)
target_link_libraries(myapp PRIVATE curtle::curtle)
```
Example in C
```C
#include "curtle/curtle.h"
int main(void) {
struct vec2 a = { 1.0, 1.0 };
printf("%f", vec2_len(a)); // Prints sqrt(2)
}
```
## Authors
- [@lowearthorbit](https://git.lowearthorbit.de/lowearthorbit)

View File

@@ -1,12 +1,43 @@
#ifndef CURTLE_VECTOR_H #ifndef CURTLE_VECTOR_H
#define CURTLE_VECTOR_H #define CURTLE_VECTOR_H
struct vec2 struct vec2 {
{ float x;
double x; float y;
double y; };
struct vec3 {
float x;
float y;
float z;
}; };
struct vec2 vec2_add(struct vec2 a, struct vec2 b); struct vec2 vec2_add(struct vec2 a, struct vec2 b);
struct vec2 vec2_sub(struct vec2 a, struct vec2 b);
float vec2_dot(struct vec2 a, struct vec2 b);
float vec2_det(struct vec2 a, struct vec2 b);
struct vec2 vec2_scale(struct vec2 v, float s);
float vec2_len(struct vec2 v);
struct vec2 vec2_normalize(struct vec2 v);
struct vec3 vec3_add(struct vec3 a, struct vec3 b);
struct vec3 vec3_sub(struct vec3 a, struct vec3 b);
float vec3_dot(struct vec3 a, struct vec3 b);
struct vec3 vec3_cross(struct vec3 a, struct vec3 b);
struct vec3 vec3_scale(struct vec3 v, float s);
float vec3_len(struct vec3 v);
struct vec3 vec3_normalize(struct vec3 v);
#endif #endif

View File

@@ -1,6 +1,73 @@
#include "curtle/vector.h" #include "curtle/vector.h"
#include <math.h>
struct vec2 vec2_add(struct vec2 a, struct vec2 b) struct vec2 vec2_add(const struct vec2 a, const struct vec2 b)
{ {
return (struct vec2){a.x + b.x, a.y + b.y}; return (struct vec2){ a.x + b.x, a.y + b.y };
}
struct vec2 vec2_sub(const struct vec2 a, const struct vec2 b)
{
return (struct vec2){ a.x - b.x, a.y - b.y };
}
float vec2_dot(const struct vec2 a, const struct vec2 b)
{
return a.x * b.x + a.y * b.y;
}
float vec2_det(const struct vec2 a, const struct vec2 b)
{
return a.x * b.y - a.y * b.x;
}
struct vec2 vec2_scale(const struct vec2 v, const float s)
{
return (struct vec2){ v.x * s, v.y * s };
}
float vec2_len(const struct vec2 v)
{
return sqrtf(v.x * v.x + v.y * v.y);
}
struct vec2 vec2_normalize(const struct vec2 v)
{
return vec2_scale(v, 1.0f / vec2_len(v));
}
struct vec3 vec3_add(const struct vec3 a, const struct vec3 b)
{
return (struct vec3){ a.x + b.x, a.y + b.y, a.z + b.z };
}
struct vec3 vec3_sub(const struct vec3 a, const struct vec3 b)
{
return (struct vec3){ a.x - b.x, a.y - b.y, a.z - b.z };
}
float vec3_dot(const struct vec3 a, const struct vec3 b)
{
return a.x * b.x + a.y * b.y + a.z * b.z;
}
struct vec3 vec3_cross(const struct vec3 a, const struct vec3 b)
{
return (struct vec3){ a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x };
}
struct vec3 vec3_scale(const struct vec3 v, const float s)
{
return (struct vec3){ v.x * s, v.y * s, v.z * s };
}
float vec3_len(const struct vec3 v)
{
return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
}
struct vec3 vec3_normalize(const struct vec3 v)
{
return vec3_scale(v, 1.0f / vec3_len(v));
} }

15
tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
set(UNITY_VERSION v2.6.1)
FetchContent_Declare(unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
GIT_TAG ${UNITY_VERSION}
)
FetchContent_MakeAvailable(unity)
add_executable(test_vector test_vector.c)
target_link_libraries(test_vector PRIVATE curtle unity)
add_test(NAME vector_test COMMAND test_vector)

View File

@@ -1,13 +1,176 @@
#include <assert.h> #include "unity.h"
#include "curtle/vector.h" #include "curtle/vector.h"
int main() void setUp(void)
{ {
struct vec2 a = {1, 2}; }
struct vec2 b = {3, 4};
void tearDown(void)
struct vec2 r = vec2_add(a, b); {
}
assert(r.x == 4);
assert(r.y == 6); void test_vec2_add()
{
struct vec2 a = { 1, 2 };
struct vec2 b = { 3, 4 };
struct vec2 r = vec2_add(a, b);
struct vec2 e = { 4, 6 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 8);
}
void test_vec2_sub()
{
struct vec2 a = { 1, 2 };
struct vec2 b = { 3, 4 };
struct vec2 r = vec2_sub(a, b);
struct vec2 e = { -2, -2 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 8);
}
void test_vec2_dot()
{
struct vec2 a = { 1, 2 };
struct vec2 b = { 3, 4 };
float r = vec2_dot(a, b);
TEST_ASSERT_EQUAL_FLOAT(11, r);
}
void test_vec2_det()
{
struct vec2 a = { 1, 2 };
struct vec2 b = { 3, 4 };
float r = vec2_det(a, b);
TEST_ASSERT_EQUAL_FLOAT(-2, r);
}
void test_vec2_scale()
{
struct vec2 a = { 1, 2 };
float s = 2;
struct vec2 r = vec2_scale(a, 2);
struct vec2 e = { 2, 4 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 8);
}
void test_vec2_len()
{
struct vec2 a = { 4, 3 };
float r = vec2_len(a);
TEST_ASSERT_EQUAL_FLOAT(5, r);
}
void test_vec2_normalize()
{
struct vec2 a = { 4, 0 };
struct vec2 r = vec2_normalize(a);
struct vec2 e = { 1, 0 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 8);
}
void test_vec3_add()
{
struct vec3 a = { 1, 2, 5 };
struct vec3 b = { 3, 4, 2 };
struct vec3 r = vec3_add(a, b);
struct vec3 e = { 4, 6, 7 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 12);
}
void test_vec3_sub()
{
struct vec3 a = { 1, 2, 5 };
struct vec3 b = { 3, 4, 2 };
struct vec3 r = vec3_sub(a, b);
struct vec3 e = { -2, -2, 3 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 12);
}
void test_vec3_dot()
{
struct vec3 a = { 1, 2, 5 };
struct vec3 b = { 3, 4, 2 };
float r = vec3_dot(a, b);
TEST_ASSERT_EQUAL_FLOAT(21, r);
}
void test_vec3_cross()
{
struct vec3 a = { 1, 2, 5 };
struct vec3 b = { 3, 4, 2 };
struct vec3 r = vec3_cross(a, b);
struct vec3 e = { -16, 13, -2 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 12);
}
void test_vec3_scale()
{
struct vec3 a = { 1, 2, 5 };
float s = 2;
struct vec3 r = vec3_scale(a, 2);
struct vec3 e = { 2, 4, 10 };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 12);
}
void test_vec3_len()
{
struct vec3 a = { 4, 3, 12 };
float r = vec3_len(a);
TEST_ASSERT_EQUAL_FLOAT(13, r);
}
void test_vec3_normalize()
{
struct vec3 a = { 1, 2, 2 };
struct vec3 r = vec3_normalize(a);
struct vec3 e = { 1.f / 3.f, 2.f / 3.f, 2.f / 3.f };
TEST_ASSERT_EQUAL_MEMORY(&e, &r, 12);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_vec2_add);
RUN_TEST(test_vec2_sub);
RUN_TEST(test_vec2_dot);
RUN_TEST(test_vec2_det);
RUN_TEST(test_vec2_scale);
RUN_TEST(test_vec2_len);
RUN_TEST(test_vec2_normalize);
RUN_TEST(test_vec3_add);
RUN_TEST(test_vec3_sub);
RUN_TEST(test_vec3_dot);
RUN_TEST(test_vec3_cross);
RUN_TEST(test_vec3_scale);
RUN_TEST(test_vec3_len);
RUN_TEST(test_vec3_normalize);
return UNITY_END();
} }