2#include "nuklear_internal.h"
37#ifdef NK_INV_SQRT_NEEDED
42 const float threehalfs = 1.5f;
43 union {nk_uint i;
float f;} conv = {0};
46 conv.i = 0x5f375A84 - (conv.i >> 1);
47 conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f));
55 NK_STORAGE
const float a0 = +1.91059300966915117e-31f;
56 NK_STORAGE
const float a1 = +1.00086760103908896f;
57 NK_STORAGE
const float a2 = -1.21276126894734565e-2f;
58 NK_STORAGE
const float a3 = -1.38078780785773762e-1f;
59 NK_STORAGE
const float a4 = -2.67353392911981221e-2f;
60 NK_STORAGE
const float a5 = +2.08026600266304389e-2f;
61 NK_STORAGE
const float a6 = -3.03996055049204407e-3f;
62 NK_STORAGE
const float a7 = +1.38235642404333740e-4f;
63 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
72 NK_STORAGE
const float a0 = 9.9995999154986614e-1f;
73 NK_STORAGE
const float a1 = 1.2548995793001028e-3f;
74 NK_STORAGE
const float a2 = -5.0648546280678015e-1f;
75 NK_STORAGE
const float a3 = 1.2942246466519995e-2f;
76 NK_STORAGE
const float a4 = 2.8668384702547972e-2f;
77 NK_STORAGE
const float a5 = 7.3726485210586547e-3f;
78 NK_STORAGE
const float a6 = -3.8510875386947414e-3f;
79 NK_STORAGE
const float a7 = 4.7196604604366623e-4f;
80 NK_STORAGE
const float a8 = -1.8776444013090451e-5f;
81 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8)))))));
89 float u = -1.0989005e-05f;
90 NK_ASSERT(x >= 0.0f &&
"TODO support negative floats");
91 u = u * x + 0.00034117949f;
92 u = u * x + -0.0044932296f;
93 u = u * x + 0.032596264f;
94 u = u * x + -0.14088021f;
95 u = u * x + 0.36040401f;
96 u = u * x + -0.47017866f;
97 u = u * x + 0.00050198776f;
98 u = u * x + 1.0077682f;
99 u = u * x + -0.0004765437f;
103#ifdef NK_ATAN2_NEEDED
105nk_atan2(
float y,
float x)
107 float ax = NK_ABS(x),
111 nk_uint signs = (y < 0) | ((x < 0) << 1);
114 if(y == 0.0 && x == 0.0)
return 0.0f;
116 ? NK_PI_HALF - NK_ATAN(ax / ay)
122 case 2:
return -a + NK_PI;
123 case 3:
return a - NK_PI;
129nk_round_up_pow2(nk_uint v)
142nk_pow(
double x,
int n)
154 return plus ? r : 1.0 / r;
161 x = (double)((
int)x - ((x < 0.0) ? 1 : 0));
168 x = (float)((
int)x - ((x < 0.0f) ? 1 : 0));
176 return (x > i) ? i+1: i;
179 float r = x - (float)t;
180 return (r > 0.0f) ? t+1: t;
191 neg = (n < 0) ? 1 : 0;
192 ret = (neg) ? (
int)-n : (int)n;
193 while ((ret / 10) > 0) {
204 return (x >= 0.0f) ? (float)nk_ifloorf(x + 0.5f) : (float)nk_iceilf(x - 0.5f);
207nk_get_null_rect(void)
212nk_rect(float x, float y, float w, float h)
232 return nk_rect(pos.x, pos.y, size.x, size.y);
235nk_rectv(const float *r)
237 return nk_rect(r[0], r[1], r[2], r[3]);
240nk_rectiv(const int *r)
242 return nk_recti(r[0], r[1], r[2], r[3]);
248 ret.x = r.x; ret.y = r.y;
255 ret.x = r.w; ret.y = r.h;
259nk_shrink_rect(struct
nk_rect r, float amount)
262 r.w = NK_MAX(r.w, 2 * amount);
263 r.h = NK_MAX(r.h, 2 * amount);
264 res.x = r.x + amount;
265 res.y = r.y + amount;
266 res.w = r.w - 2 * amount;
267 res.h = r.h - 2 * amount;
273 r.w = NK_MAX(r.w, 2 * pad.x);
274 r.h = NK_MAX(r.h, 2 * pad.y);
275 r.x += pad.x; r.y += pad.y;
284 ret.x = x; ret.y = y;
296nk_vec2v(const float *v)
301nk_vec2iv(const int *v)
306nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
311 clip->x = NK_MAX(a->x, x0);
312 clip->y = NK_MAX(a->y, y0);
313 clip->w = NK_MIN(a->x + a->w, x1) - clip->x;
314 clip->h = NK_MIN(a->y + a->h, y1) - clip->y;
315 clip->w = NK_MAX(0, clip->w);
316 clip->h = NK_MAX(0, clip->h);
320nk_triangle_from_direction(
struct nk_vec2 *result,
struct nk_rect r,
321 float pad_x,
float pad_y,
enum nk_heading direction)
323 float w_half, h_half;
326 r.w = NK_MAX(2 * pad_x, r.w);
327 r.h = NK_MAX(2 * pad_y, r.h);
328 r.w = r.w - 2 * pad_x;
329 r.h = r.h - 2 * pad_y;
337 if (direction == NK_UP) {
338 result[0] =
nk_vec2(r.x + w_half, r.y);
339 result[1] =
nk_vec2(r.x + r.w, r.y + r.h);
340 result[2] =
nk_vec2(r.x, r.y + r.h);
341 }
else if (direction == NK_RIGHT) {
343 result[1] =
nk_vec2(r.x + r.w, r.y + h_half);
344 result[2] =
nk_vec2(r.x, r.y + r.h);
345 }
else if (direction == NK_DOWN) {
347 result[1] =
nk_vec2(r.x + r.w, r.y);
348 result[2] =
nk_vec2(r.x + w_half, r.y + r.h);
350 result[0] =
nk_vec2(r.x, r.y + h_half);
351 result[1] =
nk_vec2(r.x + r.w, r.y);
352 result[2] =
nk_vec2(r.x + r.w, r.y + r.h);
main API and documentation file