Vuo 2.4.4
Loading...
Searching...
No Matches
VuoTransform2d.c
Go to the documentation of this file.
1
10#include <string.h>
11#include "VuoTransform2d.h"
12#include "VuoTransform.h"
13#include "VuoText.h"
14
16#ifdef VUO_COMPILER
18 "title" : "2D Transform",
19 "description" : "A 2D transformation (scale, rotation, translation).",
20 "keywords" : [ ],
21 "version" : "1.0.0",
22 "dependencies" : [
23 "VuoPoint2d",
24 "VuoReal",
25 "VuoText",
26 "VuoTransform",
27 ]
28 });
29#endif
31
40
45VuoTransform2d VuoTransform2d_make(VuoPoint2d translation, VuoReal rotation, VuoPoint2d scale)
46{
48 t.translation = translation;
49 t.rotation = rotation;
50 t.scale = scale;
51 return t;
52}
53
68{
70 json_object *o = NULL;
71
72 if (json_object_object_get_ex(js, "rotation", &o))
73 t.rotation = json_object_get_double(o);
74
75 if (json_object_object_get_ex(js, "translation", &o))
76 {
77 t.translation.x = json_object_get_double(json_object_array_get_idx(o,0));
78 t.translation.y = json_object_get_double(json_object_array_get_idx(o,1));
79 }
80
81 if (json_object_object_get_ex(js, "scale", &o))
82 {
83 t.scale.x = json_object_get_double(json_object_array_get_idx(o,0));
84 t.scale.y = json_object_get_double(json_object_array_get_idx(o,1));
85 }
86
87 return t;
88}
89
94json_object * VuoTransform2d_getJson(const VuoTransform2d value)
95{
97 return json_object_new_string("identity");
98
99 json_object *js = json_object_new_object();
100
101 {
102 json_object * o = json_object_new_array();
103 json_object_array_add(o,json_object_new_double(value.translation.x));
104 json_object_array_add(o,json_object_new_double(value.translation.y));
105 json_object_object_add(js, "translation", o);
106 }
107
108 json_object_object_add(js, "rotation", json_object_new_double(value.rotation));
109
110 {
111 json_object * o = json_object_new_array();
112 json_object_array_add(o,json_object_new_double(value.scale.x));
113 json_object_array_add(o,json_object_new_double(value.scale.y));
114 json_object_object_add(js, "scale", o);
115 }
116
117 return js;
118}
119
120
126{
127 if (VuoTransform2d_isIdentity(value))
128 return strdup("identity transform (no change)");
129
130 VuoReal rotationInDegrees = value.rotation * 180./M_PI;
131 return VuoText_format("<div>translation (%g, %g)</div>\n<div>rotation %g°</div>\n<div>scale (%g, %g)</div>",
132 value.translation.x, value.translation.y, rotationInDegrees, value.scale.x, value.scale.y);
133}
134
138VuoPoint2d VuoTransform2d_transform_VuoPoint2d(VuoTransform2d transform, VuoPoint2d point)
139{
141}
142
146VuoPoint3d VuoTransform2d_transform_VuoPoint3d(VuoTransform2d transform, VuoPoint3d point)
147{
149}