Vuo  2.0.0
VuoPoint4d.c
Go to the documentation of this file.
1 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "type.h"
14 
16 #ifdef VUO_COMPILER
18  "title" : "4D Point",
19  "description" : "A floating-point 4-dimensional Cartesian spatial location.",
20  "keywords" : [ "coordinate" ],
21  "version" : "1.0.0",
22  "dependencies" : [
23  "VuoReal",
24  "VuoText"
25  ]
26  });
27 #endif
28 
44 {
45  VuoPoint4d point = {0,0,0,0};
46 
47  json_type t = json_object_get_type(js);
48  if (t == json_type_string)
49  {
50  const char *s = json_object_get_string(js);
51  float x, y, z, w;
52  sscanf(s, "%20g, %20g, %20g, %20g", &x, &y, &z, &w);
53  return (VuoPoint4d){x, y, z, w};
54  }
55  else if (t == json_type_array)
56  {
57  int len = json_object_array_length(js);
58  if (len >= 1)
59  point.x = json_object_get_double(json_object_array_get_idx(js, 0));
60  if (len >= 2)
61  point.y = json_object_get_double(json_object_array_get_idx(js, 1));
62  if (len >= 3)
63  point.z = json_object_get_double(json_object_array_get_idx(js, 2));
64  if (len >= 4)
65  point.w = json_object_get_double(json_object_array_get_idx(js, 3));
66  return point;
67  }
68 
69  json_object *o = NULL;
70 
71  if (json_object_object_get_ex(js, "x", &o))
72  point.x = VuoReal_makeFromJson(o);
73  else if (json_object_object_get_ex(js, "X", &o))
74  point.x = VuoReal_makeFromJson(o);
75 
76  if (json_object_object_get_ex(js, "y", &o))
77  point.y = VuoReal_makeFromJson(o);
78  else if (json_object_object_get_ex(js, "Y", &o))
79  point.y = VuoReal_makeFromJson(o);
80 
81  if (json_object_object_get_ex(js, "z", &o))
82  point.z = VuoReal_makeFromJson(o);
83  else if (json_object_object_get_ex(js, "Z", &o))
84  point.z = VuoReal_makeFromJson(o);
85 
86  if (json_object_object_get_ex(js, "w", &o))
87  point.w = VuoReal_makeFromJson(o);
88  else if (json_object_object_get_ex(js, "W", &o))
89  point.w = VuoReal_makeFromJson(o);
90 
91  return point;
92 }
93 
98 json_object * VuoPoint4d_getJson(const VuoPoint4d value)
99 {
100  json_object *js = json_object_new_object();
101 
102  json_object *xObject = VuoReal_getJson(value.x);
103  json_object_object_add(js, "x", xObject);
104 
105  json_object *yObject = VuoReal_getJson(value.y);
106  json_object_object_add(js, "y", yObject);
107 
108  json_object *zObject = VuoReal_getJson(value.z);
109  json_object_object_add(js, "z", zObject);
110 
111  json_object *wObject = VuoReal_getJson(value.w);
112  json_object_object_add(js, "w", wObject);
113 
114  return js;
115 }
116 
121 char * VuoPoint4d_getSummary(const VuoPoint4d value)
122 {
123  return VuoText_format("%g, %g, %g, %g", value.x, value.y, value.z, value.w);
124 }
125 
129 bool VuoPoint4d_areEqual(const VuoPoint4d value1, const VuoPoint4d value2)
130 {
131  return VuoReal_areEqual(value1.x, value2.x)
132  && VuoReal_areEqual(value1.y, value2.y)
133  && VuoReal_areEqual(value1.z, value2.z)
134  && VuoReal_areEqual(value1.w, value2.w);
135 }
136 
144 bool VuoPoint4d_isLessThan(const VuoPoint4d a, const VuoPoint4d b)
145 {
150  return false;
151 }
152 
158 VuoPoint4d VuoPoint4d_random(const VuoPoint4d minimum, const VuoPoint4d maximum)
159 {
160  return VuoPoint4d_make(
161  VuoReal_random(minimum.x, maximum.x),
162  VuoReal_random(minimum.y, maximum.y),
163  VuoReal_random(minimum.z, maximum.z),
164  VuoReal_random(minimum.w, maximum.w));
165 }
166 
172 VuoPoint4d VuoPoint4d_randomWithState(unsigned short state[3], const VuoPoint4d minimum, const VuoPoint4d maximum)
173 {
174  return VuoPoint4d_make(
175  VuoReal_randomWithState(state, minimum.x, maximum.x),
176  VuoReal_randomWithState(state, minimum.y, maximum.y),
177  VuoReal_randomWithState(state, minimum.z, maximum.z),
178  VuoReal_randomWithState(state, minimum.w, maximum.w));
179 }