-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransform.h
89 lines (74 loc) · 1.92 KB
/
transform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2021 Justin Meiners
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSFORM_H
#define TRANSFORM_H
#include "bitmap.h"
// TODO: should this be an affine transform?
// how do we invert affine transform?
typedef struct
{
double m[4];
} CcTransform;
typedef struct
{
double x;
double y;
} Vec2;
static inline CcTransform cc_transform_create(double a, double b, double c, double d)
{
CcTransform t = {
{ a, b, c, d }
};
return t;
}
static inline CcTransform cc_transform_identity(void)
{
CcTransform t = {
{ 1.0, 0.0, 0.0, 1.0 }
};
return t;
}
static inline
CcTransform cc_transform_rotate(double angle)
{
double c = cos(angle);
double s = sin(angle);
CcTransform t = {
{ c, s, -s, c }
};
return t;
}
static inline
CcTransform cc_transform_scale(double w, double h)
{
CcTransform t = {
{ w, 0.0, 0.0, h }
};
return t;
}
static inline
Vec2 cc_transform_apply(CcTransform t, Vec2 v)
{
Vec2 r;
r.x = t.m[0] * v.x + t.m[1] * v.y;
r.y = t.m[2] * v.x + t.m[3] * v.y;
return r;
}
CcTransform cc_transform_inverse(CcTransform t);
CcTransform cc_transform_skew(double x_angle, double y_angle);
CcTransform cc_transform_concat(CcTransform a, CcTransform b);
CcBitmap* cc_bitmap_transform(const CcBitmap* src, CcBitmap* dst, CcTransform A, uint32_t bg_color);
#endif