Skip to content

Commit

Permalink
add plutovg_matrix_rotate_translate
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Jan 15, 2021
1 parent e779c12 commit 91ebcfc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/plutovg.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ void plutovg_matrix_init_translate(plutovg_matrix_t* matrix, double x, double y)
void plutovg_matrix_init_scale(plutovg_matrix_t* matrix, double x, double y);
void plutovg_matrix_init_shear(plutovg_matrix_t* matrix, double x, double y);
void plutovg_matrix_init_rotate(plutovg_matrix_t* matrix, double radians);
void plutovg_matrix_init_rotate_translate(plutovg_matrix_t* matrix, double radians, double x, double y);
void plutovg_matrix_translate(plutovg_matrix_t* matrix, double x, double y);
void plutovg_matrix_scale(plutovg_matrix_t* matrix, double x, double y);
void plutovg_matrix_shear(plutovg_matrix_t* matrix, double x, double y);
void plutovg_matrix_rotate(plutovg_matrix_t* matrix, double radians);
void plutovg_matrix_rotate_translate(plutovg_matrix_t* matrix, double radians, double x, double y);
void plutovg_matrix_multiply(plutovg_matrix_t* matrix, const plutovg_matrix_t* a, const plutovg_matrix_t* b);
int plutovg_matrix_invert(plutovg_matrix_t* matrix);
void plutovg_matrix_map(const plutovg_matrix_t* matrix, double x, double y, double* _x, double* _y);
Expand Down
18 changes: 18 additions & 0 deletions source/plutovg-geometry.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ void plutovg_matrix_init_rotate(plutovg_matrix_t* matrix, double radians)
plutovg_matrix_init(matrix, c, s, -s, c, 0.0, 0.0);
}

void plutovg_matrix_init_rotate_translate(plutovg_matrix_t* matrix, double radians, double x, double y)
{
double c = cos(radians);
double s = sin(radians);

double cx = x * (1 - c) + y * s;
double cy = y * (1 - c) - x * s;

plutovg_matrix_init(matrix, c, s, -s, c, cx, cy);
}

void plutovg_matrix_translate(plutovg_matrix_t* matrix, double x, double y)
{
plutovg_matrix_t m;
Expand Down Expand Up @@ -67,6 +78,13 @@ void plutovg_matrix_rotate(plutovg_matrix_t* matrix, double radians)
plutovg_matrix_multiply(matrix, &m, matrix);
}

void plutovg_matrix_rotate_translate(plutovg_matrix_t* matrix, double radians, double x, double y)
{
plutovg_matrix_t m;
plutovg_matrix_init_rotate_translate(&m, radians, x, y);
plutovg_matrix_multiply(matrix, &m, matrix);
}

void plutovg_matrix_multiply(plutovg_matrix_t* matrix, const plutovg_matrix_t* a, const plutovg_matrix_t* b)
{
double m00 = a->m00 * b->m00 + a->m10 * b->m01;
Expand Down

0 comments on commit 91ebcfc

Please sign in to comment.