https://github.com/realtrippr/svtl
C89 2D Vertex Transformation Library
https://github.com/realtrippr/svtl
c c89 vertex vertex-2d
Last synced: 6 days ago
JSON representation
C89 2D Vertex Transformation Library
- Host: GitHub
- URL: https://github.com/realtrippr/svtl
- Owner: RealTrippR
- License: mit
- Created: 2025-08-16T20:43:13.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-09-02T03:02:19.000Z (10 months ago)
- Last Synced: 2025-09-02T03:32:59.964Z (10 months ago)
- Topics: c, c89, vertex, vertex-2d
- Language: C
- Homepage:
- Size: 188 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Simple Vertex Transformation Library ##
Brief
SVTL is a basic vertex transformation library written in C89. It provides a handful of functions to perform simple geometric transformations on vertices.
**Functions**
```SVTL_register``` - registers a usage of SVTL
```SVTL_unregister``` - unregisters a usage of SVTL
```SVTL_translate2D``` - translates by a given displacement
```SVTL_rotate2D``` - rotates around the origin
```SVTL_scale2D``` - scales relative to the origin
```SVTL_skew2D``` - skews relative to the origin
```SVTL_mirror2D``` - mirrors around a given line
```SVTL_unindexedToIndexed2D``` - converts a list of unindexed vertices to indexed vertices
```SVTL_findSignedArea``` - returns the signed area of a simple closed polygon
```SVTL_findCentroid2D``` - returns the centroid of a simple closed polygon
```SVTL_extractVertexPositions2D``` - writes vertex positions to a buffer
```SVTL_extractVertexPositions2D_s``` - writes vertex positions to a bounds checked buffer
**Example**
```
#include
struct Vertex2D {
float x;
float y;
float r;
float g;
float b;
};
int main()
{
SVTL_register();
struct Vertex2D vertices[4] = { {0,0}, {1,0}, {1,1}, {0,1} };
struct SVTL_VertexInfo vi;
vi.count = sizeof(vertices)/sizeof(vertices[0]);
vi.stride = sizeof(struct Vertex2D);
vi.positionOffset = 0u;
vi.positionType = SVTL_POS_TYPE_VEC2_F32;
vi.vertices = vertices;
vi.indices=NULL;
struct SVTL_F64Vec2 v = { 0, 1 };
struct SVTL_F64Vec2 v2 = { 0, 1 };
SVTL_translate2D(&vi, v);
v.x = 0.f;
v.y = 0.f;
v2.x = 2.f;
v2.y = 2.f;
SVTL_scale2D(&vi, v2, v);
v.x = 0;
v.y = 0;
SVTL_rotate2D(&vi, 3.141592653589, v);
SVTL_rotate2D(&vi, -3.141592653589, v);
v.x = 1.f;
v.y = 0.f;
v2.x = 1.f;
v2.y = 3.f;
SVTL_skew2D(&vi, v, v2);
SVTL_unregister();
}
```
**Naming Conventions**
- Preprocessor Macros: UPPER_SNAKE_CASE
- Function Names: CamelCase
- Variable names: pascalCase
- Enum Types: CamelCase
- Enum Values: UPPER_SNAKE_CASE