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)
#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)
#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
Use:
<float> within(<float> _min, <float|float2|float3|float4> maxVal, <float|float2|float3|float4> x)
#ifndef FNC_WITHIN
#define FNC_WITHIN
float within(float x, float _min, float _max) {
return step(_min, x) * (1. - step(_max, x));
}
float within(float2 x, float2 _min, float2 _max) {
float2 rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y;
}
float within(float3 x, float3 _min, float3 _max) {
float3 rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y * rta.z;
}
float within(float4 x, float4 _min, float4 _max) {
float4 rta = step(_min, x) * (1. - step(_max, x));
return rta.x * rta.y * rta.z * rta.w;
}
#endif
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)
#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
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository