2#include "nuklear_internal.h"
38#define NK_INV_SQRT nk_inv_sqrt
43 const float threehalfs = 1.5f;
44 union {nk_uint i;
float f;} conv = {0};
47 conv.i = 0x5f375A84 - (conv.i >> 1);
48 conv.f = conv.f * (threehalfs - (x2 * conv.f * conv.f));
57 NK_STORAGE
const float a0 = +1.91059300966915117e-31f;
58 NK_STORAGE
const float a1 = +1.00086760103908896f;
59 NK_STORAGE
const float a2 = -1.21276126894734565e-2f;
60 NK_STORAGE
const float a3 = -1.38078780785773762e-1f;
61 NK_STORAGE
const float a4 = -2.67353392911981221e-2f;
62 NK_STORAGE
const float a5 = +2.08026600266304389e-2f;
63 NK_STORAGE
const float a6 = -3.03996055049204407e-3f;
64 NK_STORAGE
const float a7 = +1.38235642404333740e-4f;
65 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*a7))))));
75 NK_STORAGE
const float a0 = 9.9995999154986614e-1f;
76 NK_STORAGE
const float a1 = 1.2548995793001028e-3f;
77 NK_STORAGE
const float a2 = -5.0648546280678015e-1f;
78 NK_STORAGE
const float a3 = 1.2942246466519995e-2f;
79 NK_STORAGE
const float a4 = 2.8668384702547972e-2f;
80 NK_STORAGE
const float a5 = 7.3726485210586547e-3f;
81 NK_STORAGE
const float a6 = -3.8510875386947414e-3f;
82 NK_STORAGE
const float a7 = 4.7196604604366623e-4f;
83 NK_STORAGE
const float a8 = -1.8776444013090451e-5f;
84 return a0 + x*(a1 + x*(a2 + x*(a3 + x*(a4 + x*(a5 + x*(a6 + x*(a7 + x*a8)))))));
88#define NK_ATAN nk_atan
93 float u = -1.0989005e-05f;
94 NK_ASSERT(x >= 0.0f &&
"TODO support negative floats");
95 u = u * x + 0.00034117949f;
96 u = u * x + -0.0044932296f;
97 u = u * x + 0.032596264f;
98 u = u * x + -0.14088021f;
99 u = u * x + 0.36040401f;
100 u = u * x + -0.47017866f;
101 u = u * x + 0.00050198776f;
102 u = u * x + 1.0077682f;
103 u = u * x + -0.0004765437f;
108#define NK_ATAN2 nk_atan2
110nk_atan2(
float y,
float x)
112 float ax = NK_ABS(x),
116 nk_uint signs = (y < 0) | ((x < 0) << 1);
119 if(y == 0.0 && x == 0.0)
return 0.0f;
121 ? NK_PI_HALF - NK_ATAN(ax / ay)
127 case 2:
return -a + NK_PI;
128 case 3:
return a - NK_PI;
134nk_round_up_pow2(nk_uint v)
146nk_pow(
double x,
int n)
158 return plus ? r : 1.0 / r;
163 x = (double)((
int)x - ((x < 0.0) ? 1 : 0));
169 x = (float)((
int)x - ((x < 0.0f) ? 1 : 0));
177 return (x > i) ? i+1: i;
180 float r = x - (float)t;
181 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) {
203 return (x >= 0.0f) ? (float)nk_ifloorf(x + 0.5f) : (float)nk_iceilf(x - 0.5f);
206nk_get_null_rect(void)
211nk_rect(float x, float y, float w, float h)
231 return nk_rect(pos.x, pos.y, size.x, size.y);
234nk_rectv(const float *r)
236 return nk_rect(r[0], r[1], r[2], r[3]);
239nk_rectiv(const int *r)
241 return nk_recti(r[0], r[1], r[2], r[3]);
247 ret.x = r.x; ret.y = r.y;
254 ret.x = r.w; ret.y = r.h;
258nk_shrink_rect(struct
nk_rect r, float amount)
261 r.w = NK_MAX(r.w, 2 * amount);
262 r.h = NK_MAX(r.h, 2 * amount);
263 res.x = r.x + amount;
264 res.y = r.y + amount;
265 res.w = r.w - 2 * amount;
266 res.h = r.h - 2 * amount;
272 r.w = NK_MAX(r.w, 2 * pad.x);
273 r.h = NK_MAX(r.h, 2 * pad.y);
274 r.x += pad.x; r.y += pad.y;
283 ret.x = x; ret.y = y;
295nk_vec2v(const float *v)
300nk_vec2iv(const int *v)
305nk_unify(
struct nk_rect *clip,
const struct nk_rect *a,
float x0,
float y0,
310 clip->x = NK_MAX(a->x, x0);
311 clip->y = NK_MAX(a->y, y0);
312 clip->w = NK_MIN(a->x + a->w, x1) - clip->x;
313 clip->h = NK_MIN(a->y + a->h, y1) - clip->y;
314 clip->w = NK_MAX(0, clip->w);
315 clip->h = NK_MAX(0, clip->h);
319nk_triangle_from_direction(
struct nk_vec2 *result,
struct nk_rect r,
320 float pad_x,
float pad_y,
enum nk_heading direction)
322 float w_half, h_half;
325 r.w = NK_MAX(2 * pad_x, r.w);
326 r.h = NK_MAX(2 * pad_y, r.h);
327 r.w = r.w - 2 * pad_x;
328 r.h = r.h - 2 * pad_y;
336 if (direction == NK_UP) {
337 result[0] =
nk_vec2(r.x + w_half, r.y);
338 result[1] =
nk_vec2(r.x + r.w, r.y + r.h);
339 result[2] =
nk_vec2(r.x, r.y + r.h);
340 }
else if (direction == NK_RIGHT) {
342 result[1] =
nk_vec2(r.x + r.w, r.y + h_half);
343 result[2] =
nk_vec2(r.x, r.y + r.h);
344 }
else if (direction == NK_DOWN) {
346 result[1] =
nk_vec2(r.x + r.w, r.y);
347 result[2] =
nk_vec2(r.x + w_half, r.y + r.h);
349 result[0] =
nk_vec2(r.x, r.y + h_half);
350 result[1] =
nk_vec2(r.x + r.w, r.y);
351 result[2] =
nk_vec2(r.x + r.w, r.y + r.h);
main API and documentation file