Skip to content

Commit

Permalink
project: fix math interval notation
Browse files Browse the repository at this point in the history
  • Loading branch information
ubitux committed Feb 25, 2024
1 parent 78a2748 commit 8def7a5
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions doc/usr/ref/eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ component of the 3+ dimensional input resources identified by "foo".
| `isinf(x)` | `1` if `x` is infinite, `0` otherwise |
| `isnan(x)` | `1` if `x` is not a number (`NaN`), `0` otherwise |
| `isnormal(x)` | `1` if `x` is normal, `0` otherwise |
| `linear(a,b,x)` | linearly remap `x` in range `[a;b]` to `[0;1]` |
| `linear(a,b,x)` | linearly remap `x` in range `[a,b]` to `[0,1]` |
| `linear2srgb(x)` | convert `x` from linear to sRGB (see also `srgb2linear(x)`) |
| `linearstep(a,b,x)` | saturated version of `linear()` (equivalent to `sat(linear(a,b,x))`) |
| `log(x)` | natural logarithm of `x` (see `e`), also called "ln" in math terminology |
Expand All @@ -69,7 +69,7 @@ component of the 3+ dimensional input resources identified by "foo".
| `luma(r,g,b)` | gamma encoded luma Y' of the R'G'B' value, as defined by BT.709 |
| `max(a,b)` | maximum value between `a` and `b` |
| `min(a,b)` | minimum value between `a` and `b` |
| `mix(a,b,x)` | linearly remap `x` in range `[0;1]` to `[a;b]` |
| `mix(a,b,x)` | linearly remap `x` in range `[0,1]` to `[a,b]` |
| `mla(a,b,c)` | multiply-add in one operation (`a*b + c`) |
| `mod_e(a,b)` | euclidean modulo: `a - b*sign(b)*floor(a/abs(b))` |
| `mod_f(a,b)` | floored modulo: `a - b*floor(a/b)` |
Expand Down
6 changes: 3 additions & 3 deletions libnopegl/nodes.specs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@
"type": "f32",
"default": 0.000000,
"flags": ["live", "node"],
"desc": "position of the gradient point on the axis (within [0;1])"
"desc": "position of the gradient point on the axis (within [0,1])"
},
{
"name": "color",
Expand Down Expand Up @@ -3127,7 +3127,7 @@
"type": "u32",
"default": 3,
"flags": [],
"desc": "number of accumulated noise layers (controls the level of details), must in [1;8]"
"desc": "number of accumulated noise layers (controls the level of details), must in [1,8]"
},
{
"name": "lacunarity",
Expand Down Expand Up @@ -3929,7 +3929,7 @@
"type": "bool",
"default": 0,
"flags": [],
"desc": "clamp ngl_texvideo() output to [0;1]"
"desc": "clamp ngl_texvideo() output to [0,1]"
},
{
"name": "clear_color",
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/distmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ int ngli_distmap_finalize(struct distmap *s)

/*
* We normalize the coordinates with regards to the container shape so that
* distances are within [0;1] while remaining proportionnal against each
* distances are within [0,1] while remaining proportionnal against each
* others. This help making effects consistent accross all shapes.
*/
normalize_coordinates(s);
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/distmap.frag
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ vec3 stitch_3_roots(int topology, vec3 roots, float a, float b, float c)

/*
* Got 3 roots but expected only 1. Likely scenario: the roots are outside
* the [0;1] range, but we can't just exclude outside the boundaries due to
* the [0,1] range, but we can't just exclude outside the boundaries due to
* float inaccuracies.
*/
float da = 3.0 * a, db = 2.0 * b, dc = c;
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/distmap.vert
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const vec2 uvs[] = vec2[](vec2(0.0, 0.0), vec2(0.0, 2.0), vec2(2.0, 0.0));
void main()
{
vec2 ref_uv = uvs[ngl_vertex_index];
vec4 centered_vertices = vertices * 2.0 - 1.0; // [0;1] -> [-1;1]
vec4 centered_vertices = vertices * 2.0 - 1.0; // [0,1] -> [-1,1]
vec2 out_pos = mix(centered_vertices.xy, centered_vertices.zw, ref_uv);
ngl_out_pos = vec4(out_pos, 0.0, 1.0);
uv = ref_uv;
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/filter_contrast.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vec4 filter_contrast(vec4 color, vec2 coords, float contrast, float pivot)
{
vec3 rgb = color.rgb;

/* remap contrast in [0;2] to polar coordinates (in [0;PI/2]) */
/* remap contrast in [0,2] to polar coordinates (in [0,PI/2]) */
float polar_c = contrast * ngli_pi / 4.0;
if (abs(polar_c - ngli_pi / 2.0) < 1e-6) /* at contrast=2, strength is infinite */
return vec4(step(vec3(pivot), rgb), color.a);
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/filter_selector.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ vec4 filter_selector(vec4 color, vec2 coords, vec2 range, int component, int dro

bool within; // whether we are within the range or not
if (component == 2) {
// If we selected the hue, bring both value and reference in the same [0;𝜏] range
// If we selected the hue, bring both value and reference in the same [0,𝜏] range
range = mod(range, ngli_tau);
value = mod(value, ngli_tau);
if (range.x > range.y) {
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/hdr_pq2sdr.frag
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void main()
{
vec4 hdr = ngl_texvideo(tex, tex_coord);

/* Linearize the PQ signal and ensure it is in the [0; 10000] range */
/* Linearize the PQ signal and ensure it is in the [0,10000] range */
vec3 rgb_linear = pq_eotf3(hdr.rgb);
rgb_linear = clamp(rgb_linear, 0.0, 10000.0);

Expand Down
6 changes: 3 additions & 3 deletions libnopegl/src/glsl/helper_noise.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

/*
* Return a random single-precision float between [0;1)
* Return a random single-precision float between [0,1)
* Derived from http://prng.di.unimi.it/
*/
highp float u32tof32(highp uint x)
Expand Down Expand Up @@ -61,7 +61,7 @@ highp float random(highp uvec3 x)

highp vec2 random2(highp uvec3 x)
{
/* Generate 2 random floats in [0;1] using 16-bit of information for each */
/* Generate 2 random floats in [0,1] using 16-bit of information for each */
uint h = hash(x);
float r0 = u32tof32(0x00010001U * (h & 0xffffU));
float r1 = u32tof32(0x00010001U * (h>>16 & 0xffffU));
Expand Down Expand Up @@ -150,7 +150,7 @@ float noise_blocky(vec3 t, uint seed)

float res = bicubic(y0, y1, y2, y3, evolution_f);

/* Scale noise from the [0;1] range to [-1;1] */
/* Scale noise from the [0,1] range to [-1,1] */
return res * 2.0 - 1.0;
}

Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/path.frag
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
void main()
{
/*
* uv_* are normalized [0;1] quad coordinate which we map to the atlas
* uv_* are normalized [0,1] quad coordinate which we map to the atlas
* element coordinate boundaries
*/
vec2 uv_fill = mix(coords_fill.xy, coords_fill.zw, uv);
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/glsl/text_chars.frag
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
void main()
{
/*
* uv is a normalized [0;1] quad coordinate which we map to the atlas
* uv is a normalized [0,1] quad coordinate which we map to the atlas
* element coordinate boundaries
*/
vec2 chr_uv = mix(coords.xy, coords.zw, uv);
Expand Down
4 changes: 2 additions & 2 deletions libnopegl/src/math_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#define NGLI_DEG2RAD(x) ((x) * (TAU_F32 / 360.f))
#define NGLI_CEIL_RSHIFT(a, b) -((-(a)) >> (b))

/* Map a normalized value to [a;b] range */
/* Map a normalized value to [a,b] range */
#define NGLI_MIX_F32(a, b, x) ((a)*(1.f-(x)) + (b)*(x))
#define NGLI_MIX_F64(a, b, x) ((a)*(1.0-(x)) + (b)*(x))

/* Map a value in [a;b] range to a normalized value */
/* Map a value in [a,b] range to a normalized value */
#define NGLI_LINEAR_NORM(a, b, x) (((x) - (a)) / ((b) - (a)))

#define NGLI_VEC2_ADD(a, b) {(a)[0] + (b)[0], (a)[1] + (b)[1]}
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/node_colorkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
static const struct node_param colorkey_params[] = {
{"position", NGLI_PARAM_TYPE_F32, OFFSET(position_node), {.f32=0.f},
.flags=NGLI_PARAM_FLAG_ALLOW_LIVE_CHANGE | NGLI_PARAM_FLAG_ALLOW_NODE,
.desc=NGLI_DOCSTRING("position of the gradient point on the axis (within [0;1])")},
.desc=NGLI_DOCSTRING("position of the gradient point on the axis (within [0,1])")},
{"color", NGLI_PARAM_TYPE_VEC3, OFFSET(color_node), {.vec={1.f, 1.f, 1.f}},
.flags=NGLI_PARAM_FLAG_ALLOW_LIVE_CHANGE | NGLI_PARAM_FLAG_ALLOW_NODE,
.desc=NGLI_DOCSTRING("color at this specific position")},
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/node_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static int filtercolormap_init(struct ngl_node *node)
/* Convert input color to grayscale to obtain the interpolation index */
ngli_bstr_print(str, I "float t = dot(color.rgb, ngli_luma_weights);\n\n");

/* Switch colors to linear space and saturate pos within [0;1] */
/* Switch colors to linear space and saturate pos within [0,1] */
for (size_t i = 0; i < o->nb_colorkeys; i++) {
ngli_bstr_printf(str, I "pos%zu = ngli_sat(pos%zu);\n", i, i);
ngli_bstr_printf(str, I "color%zu = ngli_srgb2linear(color%zu);\n", i, i);
Expand Down
4 changes: 2 additions & 2 deletions libnopegl/src/node_renderother.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static const struct node_param rendernoise_params[] = {
.flags=NGLI_PARAM_FLAG_ALLOW_NODE,
.desc=NGLI_DOCSTRING("by how much it oscillates")},
{"octaves", NGLI_PARAM_TYPE_U32, OFFSET(octaves), {.u32=3},
.desc=NGLI_DOCSTRING("number of accumulated noise layers (controls the level of details), must in [1;8]")},
.desc=NGLI_DOCSTRING("number of accumulated noise layers (controls the level of details), must in [1,8]")},
{"lacunarity", NGLI_PARAM_TYPE_F32, OFFSET(lacunarity_node), {.f32=2.f},
.flags=NGLI_PARAM_FLAG_ALLOW_NODE,
.desc=NGLI_DOCSTRING("frequency multiplier per octave")},
Expand Down Expand Up @@ -715,7 +715,7 @@ static int rendernoise_init(struct ngl_node *node)
struct rendernoise_priv *s = node->priv_data;
struct rendernoise_opts *o = node->opts;
if (o->octaves < 1 || o->octaves > 8) {
LOG(ERROR, "octaves must be in [1;8]");
LOG(ERROR, "octaves must be in [1,8]");
return NGL_ERROR_INVALID_ARG;
}

Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/node_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static const struct node_param texture2d_params[] = {
{"direct_rendering", NGLI_PARAM_TYPE_BOOL, OFFSET(direct_rendering), {.i32=1},
.desc=NGLI_DOCSTRING("whether direct rendering is allowed or not for media playback")},
{"clamp_video", NGLI_PARAM_TYPE_BOOL, OFFSET(clamp_video), {.i32=0},
.desc=NGLI_DOCSTRING("clamp ngl_texvideo() output to [0;1]")},
.desc=NGLI_DOCSTRING("clamp ngl_texvideo() output to [0,1]")},
{"clear_color", NGLI_PARAM_TYPE_VEC4, OFFSET(clear_color),
.desc=NGLI_DOCSTRING("color used to clear the texture when used as an implicit render target")},
{"forward_transforms", NGLI_PARAM_TYPE_BOOL, OFFSET(forward_transforms), {.i32=0},
Expand Down
8 changes: 4 additions & 4 deletions libnopegl/src/noise.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static uint32_t hash(uint32_t x)
}

/*
* Return a random single-precision float between [0;1)
* Return a random single-precision float between [0,1)
* Derived from http://prng.di.unimi.it/
*/
static float u32tof32(uint32_t x)
Expand All @@ -70,7 +70,7 @@ static float u32tof32(uint32_t x)
return u.f - 1.f;
}

/* Gradient noise, returns a value in [-.5;.5) */
/* Gradient noise, returns a value in [-.5,.5) */
static float noise(const struct noise *s, float t)
{
const float i = floorf(t); // integer part (lattice point)
Expand All @@ -79,8 +79,8 @@ static float noise(const struct noise *s, float t)

/*
* The random values correspond to the random slopes found at the 2 lattice
* points surrounding our current point; they are between [0;1) so we
* rescale them to [-1;1), which is equivalent to a tilt between [-π/4;π/4)
* points surrounding our current point; they are between [0,1) so we
* rescale them to [-1,1), which is equivalent to a tilt between [-π/4,π/4)
*/
const float s0 = u32tof32(hash(x)) * 2.f - 1.f;
const float s1 = u32tof32(hash(x + 1)) * 2.f - 1.f;
Expand Down
4 changes: 2 additions & 2 deletions libnopegl/src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ int ngli_path_init(struct path *s, int32_t precision)
* defined by 2 consecutive points in the `values` array, with `values`
* composed of monotonically increasing values.
*
* The range of the returned index is within [0;nb_values-2].
* The range of the returned index is within [0,nb_values-2].
*
* Example:
* values: 2 3 5 8 9
Expand Down Expand Up @@ -593,7 +593,7 @@ static int get_vector_id(const float *values, int nb_values, int *cache, float v
return ret;
}

/* Remap x from [c;d] to [a;b] */
/* Remap x from [c,d] to [a,b] */
static float remap(float a, float b, float c, float d, float x)
{
const float ratio = NGLI_LINEAR_NORM(c, d, x);
Expand Down
2 changes: 1 addition & 1 deletion libnopegl/src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct text_effects_pointers {

struct effect_segmentation {
size_t *positions; // character index (in chars darray) to position in "target unit" (char, word, ...)
size_t total_segments; // total number of segment: all values in positions are between [0;total_segments-1]
size_t total_segments; // total number of segment: all values in positions are between [0,total_segments-1]
};

struct text {
Expand Down
2 changes: 1 addition & 1 deletion pynopegl-utils/pynopegl_utils/diff/shaders/diff.frag
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ vec4 color_diff(vec4 c0, vec4 c1)
vec4 diff2 = diff * diff * vec4(show_r, show_g, show_b, show_a); // filtered squared difference
float sum = diff2.r + diff2.g + diff2.b + diff2.a;
float err = sqrt(sum / n);
float amp = (err - threshold) / (1 - threshold); // remap err from [0;1] to [thres;1]
float amp = (err - threshold) / (1 - threshold); // remap err from [0,1] to [thres,1]
float amount = pow(amp, 1.0 / 3.0); // power 1/3 to boost the differences of the small amplitude
vec3 grad = lin_mix(lin_mix(cmap0, cmap1, amount), lin_mix(cmap1, cmap2, amount), amount);

Expand Down
4 changes: 2 additions & 2 deletions pynopegl-utils/pynopegl_utils/diff/shaders/diff.vert
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void main()
ngl_out_pos = ngl_projection_matrix * ngl_modelview_matrix * vec4(ngl_position, 1.0);
uv = ngl_uvcoord;

/* Re-center space from UV in [0;1] to geometric [-1;1] (+ y-axis flip) */
/* Re-center space from UV in [0,1] to geometric [-1,1] (+ y-axis flip) */
vec2 st = vec2(uv.x, 1.0 - uv.y) * 2.0 - 1.0;

/*
Expand All @@ -36,7 +36,7 @@ void main()
vec2 off = -reframing_off * scale;
st = st * scale + off;

/* Restore space to [0;1] (+ y-axis flip) */
/* Restore space to [0,1] (+ y-axis flip) */
st = vec2(st.x + 1.0, 1.0 - st.y) / 2.0;

tex0_coord = (tex0_coord_matrix * vec4(st, 0.0, 1.0)).xy;
Expand Down
6 changes: 3 additions & 3 deletions pynopegl-utils/pynopegl_utils/examples/shaders/audiotex.frag
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
float wave(float amp, float y, float yoff)
{
float s = (amp + 1.0) / 2.0; // [-1;1] -> [0;1]
float v = yoff + s/4.0; // [0;1] -> [off;off+0.25]
float s = (amp + 1.0) / 2.0; // [-1,1] -> [0,1]
float v = yoff + s/4.0; // [0,1] -> [off,off+0.25]
return smoothstep(v-0.005, v, y)
- smoothstep(v, v+0.005, y);
}

float freq(float power, float y, float yoff)
{
float p = sqrt(power);
float v = clamp(p, 0.0, 1.0) / 4.0; // [0;+oo] -> [0;0.25]
float v = clamp(p, 0.0, 1.0) / 4.0; // [0,+oo] -> [0,0.25]
float a = yoff + 0.25;
float b = a - v;
return step(y, a) * (1.0 - step(y, b)); // y <= a && y > b
Expand Down
2 changes: 1 addition & 1 deletion pynopegl-utils/pynopegl_utils/tests/cmp_cuepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
):
"""
points: dictionary associating point names with their 2D coordinates
within [-1;1] space
within [-1,1] space
"""
super().__init__(scene_func, width=width, height=height, **kwargs)
self._points = points
Expand Down

0 comments on commit 8def7a5

Please sign in to comment.