Vuo  2.0.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  ]
25  });
26 #endif
27 
34 {
36 }
37 
42 VuoTransform2d VuoTransform2d_make(VuoPoint2d translation, VuoReal rotation, VuoPoint2d scale)
43 {
45  t.translation = translation;
46  t.rotation = rotation;
47  t.scale = scale;
48  return t;
49 }
50 
65 {
67  json_object *o = NULL;
68 
69  if (json_object_object_get_ex(js, "rotation", &o))
70  t.rotation = json_object_get_double(o);
71 
72  if (json_object_object_get_ex(js, "translation", &o))
73  {
74  t.translation.x = json_object_get_double(json_object_array_get_idx(o,0));
75  t.translation.y = json_object_get_double(json_object_array_get_idx(o,1));
76  }
77 
78  if (json_object_object_get_ex(js, "scale", &o))
79  {
80  t.scale.x = json_object_get_double(json_object_array_get_idx(o,0));
81  t.scale.y = json_object_get_double(json_object_array_get_idx(o,1));
82  }
83 
84  return t;
85 }
86 
92 {
93  if (VuoTransform2d_isIdentity(value))
94  return json_object_new_string("identity");
95 
96  json_object *js = json_object_new_object();
97 
98  {
99  json_object * o = json_object_new_array();
100  json_object_array_add(o,json_object_new_double(value.translation.x));
101  json_object_array_add(o,json_object_new_double(value.translation.y));
102  json_object_object_add(js, "translation", o);
103  }
104 
105  json_object_object_add(js, "rotation", json_object_new_double(value.rotation));
106 
107  {
108  json_object * o = json_object_new_array();
109  json_object_array_add(o,json_object_new_double(value.scale.x));
110  json_object_array_add(o,json_object_new_double(value.scale.y));
111  json_object_object_add(js, "scale", o);
112  }
113 
114  return js;
115 }
116 
117 
123 {
124  if (VuoTransform2d_isIdentity(value))
125  return strdup("identity transform (no change)");
126 
127  VuoReal rotationInDegrees = value.rotation * 180./M_PI;
128  return VuoText_format("<div>translation (%g, %g)</div><div>rotation %g°</div><div>scale (%g, %g)</div>",
129  value.translation.x, value.translation.y, rotationInDegrees, value.scale.x, value.scale.y);
130 }