improve rect triangle init readability

This commit is contained in:
jacekpoz 2024-08-13 11:31:50 +02:00
parent 2b3f4c58c4
commit 43707826d9
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -36,13 +36,18 @@ void triangle(PtkTriangle *triangle, size_t uvs_offset) {
}
void rect(PtkRect *rect) {
float x = rect->top_left.x;
float y = rect->top_left.y;
float w = rect->size.w;
float h = rect->size.h;
PtkPos t1_positions[3];
// top left
t1_positions[0] = (PtkPos){ .x = rect->top_left.x, .y = rect->top_left.y };
t1_positions[0] = (PtkPos){ .x = x, .y = y };
// bottom left
t1_positions[1] = (PtkPos){ .x = rect->top_left.x + rect->size.w, .y = rect->top_left.y };
t1_positions[1] = (PtkPos){ .x = x + w, .y = y };
// top right
t1_positions[2] = (PtkPos){ .x = rect->top_left.x, .y = rect->top_left.y + rect->size.h };
t1_positions[2] = (PtkPos){ .x = x, .y = y + h };
PtkTriangle *t1 = (PtkTriangle *)ptk_triangle((PtkPos *)t1_positions, rect->color);
t1->type = rect->type;
@ -50,11 +55,11 @@ void rect(PtkRect *rect) {
PtkPos t2_positions[3];
// bottom left
t2_positions[0] = (PtkPos){ .x = rect->top_left.x + rect->size.w, .y = rect->top_left.y };
t2_positions[0] = (PtkPos){ .x = x + w, .y = y };
// top right
t2_positions[1] = (PtkPos){ .x = rect->top_left.x, .y = rect->top_left.y + rect->size.h };
t2_positions[1] = (PtkPos){ .x = x, .y = y + h };
// bottom right
t2_positions[2] = (PtkPos){ .x = rect->top_left.x + rect->size.w, .y = rect->top_left.y + rect->size.h };
t2_positions[2] = (PtkPos){ .x = x + w, .y = y + h };
PtkTriangle *t2 = (PtkTriangle *)ptk_triangle((PtkPos *)t2_positions, rect->color);
t2->type = rect->type;