## within (`lygia`/`math`/`within`)

Similar to step but for an interval instead of a threshold. Returns 1 is x is between left and right, 0 otherwise

Use:

``````<float> within(<float> _min, <float|vec2|vec3|vec4> maxVal, <float|vec2|vec3|vec4> x)
``````

Check it on Github

``````
#ifndef FNC_WITHIN
#define FNC_WITHIN
float within(in float x, in float _min, in float _max) {
return step(_min, x) * (1. - step(_max, x));
}

float within(in vec2 x, in vec2 _min, in vec2 _max) {
vec2 rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y;
}

float within(in vec3 x, in vec3 _min, in vec3 _max) {
vec3 rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y * rta.z;
}

float within(in vec4 x, in vec4 _min, in vec4 _max) {
vec4 rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y * rta.z * rta.w;
}
#endif
``````

Use:

``````<float> within(<float> minVal, <float|float2|float3|float4> maxVal, <float|float2|float3|float4> x)
``````

Check it on Github

``````

#ifndef FNC_WITHIN
#define FNC_WITHIN
float within(in float minVal, in float maxVal, in float x) {
return step(minVal, x) * (1. - step(maxVal, x));
}

float within(in float2 minVal, in float2 maxVal, in float2 x) {
float2 rta = step(minVal, x) * (1. - step(maxVal, x));
return rta.x * rta.y;
}

float within(in float3 minVal, in float3 maxVal, in float3 x) {
float3 rta = step(minVal, x) * (1. - step(maxVal, x));
return rta.x * rta.y * rta.z;
}

float within(in float4 minVal, in float4 maxVal, in float4 x) {
float4 rta = step(minVal, x) * (1. - step(maxVal, x));
return rta.x * rta.y * rta.z * rta.w;
}
#endif
``````

Check it on Github

``````
fn within(x: f32, _min: f32, _max: f32) -> f32 {
return step(_min, x) * (1. - step(_max, x));
}

fn within2(x: vec2f, _min: vec2f, _max: vec2f) -> f32 {
let rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y;
}

fn within3(x: vec3f, _min: vec3f, _max: vec3f) -> f32 {
let rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y * rta.z;
}

fn within4(x: vec4f, _min: vec4f, _max: vec4f) -> f32 {
let rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y * rta.z * rta.w;
}
``````

Dependencies:

Use:

``````<float> within(<float> minVal, <float|float2|float3|float4> maxVal, <float|float2|float3|float4> x)
``````

Check it on Github

``````

#ifndef FNC_WITHIN
#define FNC_WITHIN
inline __host__ __device__ float within(float minVal, float maxVal, float x) {
return step(minVal, x) * (1.0f - step(maxVal, x));
}

inline __host__ __device__ float within(const float2& minVal, const float2& maxVal, const float2& x) {
float2 rta = step(minVal, x) * (1.0f - step(maxVal, x));
return rta.x * rta.y;
}

inline __host__ __device__ float within(const float3& minVal, const float3& maxVal, const float3& x) {
float3 rta = step(minVal, x) * (1.0f - step(maxVal, x));
return rta.x * rta.y * rta.z;
}

inline __host__ __device__ float within(const float4& minVal, const float4& maxVal, const float4& x) {
float4 rta = step(minVal, x) * (1.0f - step(maxVal, x));
return rta.x * rta.y * rta.z * rta.w;
}
#endif
``````