lygia
/v1.1.6
/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:
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:
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
Dependencies:
Use:
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