Vuo  2.4.0
VuoTransform2d.c
Go to the documentation of this file.
1
10#include <string.h>
11#include "type.h"
12
14#ifdef VUO_COMPILER
16 "title" : "2D Transform",
17 "description" : "A 2D transformation (scale, rotation, translation).",
18 "keywords" : [ ],
19 "version" : "1.0.0",
20 "dependencies" : [
21 "VuoPoint2d",
22 "VuoReal",
23 "VuoText",
24 "VuoTransform",
25 ]
26 });
27#endif
29
35{
37}
38
43VuoTransform2d VuoTransform2d_make(VuoPoint2d translation, VuoReal rotation, VuoPoint2d scale)
44{
46 t.translation = translation;
47 t.rotation = rotation;
48 t.scale = scale;
49 return t;
50}
51
66{
68 json_object *o = NULL;
69
70 if (json_object_object_get_ex(js, "rotation", &o))
71 t.rotation = json_object_get_double(o);
72
73 if (json_object_object_get_ex(js, "translation", &o))
74 {
75 t.translation.x = json_object_get_double(json_object_array_get_idx(o,0));
76 t.translation.y = json_object_get_double(json_object_array_get_idx(o,1));
77 }
78
79 if (json_object_object_get_ex(js, "scale", &o))
80 {
81 t.scale.x = json_object_get_double(json_object_array_get_idx(o,0));
82 t.scale.y = json_object_get_double(json_object_array_get_idx(o,1));
83 }
84
85 return t;
86}
87
93{
95 return json_object_new_string("identity");
96
97 json_object *js = json_object_new_object();
98
99 {
100 json_object * o = json_object_new_array();
101 json_object_array_add(o,json_object_new_double(value.translation.x));
102 json_object_array_add(o,json_object_new_double(value.translation.y));
103 json_object_object_add(js, "translation", o);
104 }
105
106 json_object_object_add(js, "rotation", json_object_new_double(value.rotation));
107
108 {
109 json_object * o = json_object_new_array();
110 json_object_array_add(o,json_object_new_double(value.scale.x));
111 json_object_array_add(o,json_object_new_double(value.scale.y));
112 json_object_object_add(js, "scale", o);
113 }
114
115 return js;
116}
117
118
124{
125 if (VuoTransform2d_isIdentity(value))
126 return strdup("identity transform (no change)");
127
128 VuoReal rotationInDegrees = value.rotation * 180./M_PI;
129 return VuoText_format("<div>translation (%g, %g)</div>\n<div>rotation %g°</div>\n<div>scale (%g, %g)</div>",
130 value.translation.x, value.translation.y, rotationInDegrees, value.scale.x, value.scale.y);
131}
132
136VuoPoint2d VuoTransform2d_transform_VuoPoint2d(VuoTransform2d transform, VuoPoint2d point)
137{
139}
140
144VuoPoint3d VuoTransform2d_transform_VuoPoint3d(VuoTransform2d transform, VuoPoint3d point)
145{
147}