LYGIA Shader Library

inside (lygia/math/inside)

does the position lie within the triangle

Use:

bool inside(<float|vec2|vec3> value, <float|vec2|vec3> min, <float|vec2|vec3> max)
bool inside(<vec2|vec3> value, <vec4|AABB> aabb)

Check it on Github


#ifndef FNC_INSIDE
#define FNC_INSIDE
bool inside(float _x, float _min, float _max) {
    return !(_x < _min || _x > _max);
}

bool inside(vec2 _v, vec2 _min, vec2 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y);
}

bool inside(vec3 _v, vec3 _min, vec3 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y ||
             _v.z < _min.z || _v.z > _max.z);
}

bool inside(vec2 _v, vec4 _aabb) {
    return inside(_v, _aabb.xy, _aabb.zw);
}

#ifdef STR_AABB
bool inside(vec3 _v, AABB _aabb) {
    return inside(_v, _aabb.min, _aabb.max);
}
#endif

#endif

Use:

bool inside(<float|float2|float3> value, <float|float2|float3> min, <float|float2|float3> max)
bool inside(<float2|float3> value, <float4|AABB> aabb)

Check it on Github


#ifndef FNC_INSIDE
#define FNC_INSIDE
bool inside(float _x, float _min, float _max) {
    return !(_x < _min || _x > _max);
}

bool inside(float2 _v, float2 _min, float2 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y);
}

bool inside(float3 _v, float3 _min, float3 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y ||
             _v.z < _min.z || _v.z > _max.z);
}

bool inside(float2 _v, float4 _aabb) {
    return inside(_v, _aabb.xy, _aabb.zw);
}

#ifdef STR_AABB
bool inside(float3 _v, AABB _aabb) {
    return inside(_v, _aabb.min, _aabb.max);
}
#endif

#endif

Use:

bool inside(<float|float2|float3> value, <float|float2|float3> min, <float|float2|float3> max)
bool inside(<float2|float3> value, <float4|AABB> aabb)

Check it on Github


#ifndef FNC_INSIDE
#define FNC_INSIDE
bool inside(float _x, float _min, float _max) {
    return !(_x < _min|| _x > _max);
}

bool inside(float2 _v, float2 _min, float2 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y);
}

bool inside(float3 _v, float3 _min, float3 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y ||
             _v.z < _min.z || _v.z > _max.z);
}

bool inside(float2 _v, float4 _aabb) {
    return inside(_v, _aabb.xy, _aabb.zw);
}

#ifdef STR_AABB
bool inside(float3 _v, AABB _aabb) {
    return inside(_v, _aabb.min, _aabb.max);
}
#endif

#endif

Check it on Github


fn inside(_x: f32, _min: f32, _max: f32) -> bool { return !(_x < _min || _x > _max); }

fn inside2(_v: vec2f, _min: vec2f, _max: vec2f) -> bool {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y);
}

fn inside3(_v: vec3f, _min: vec3f, _max: vec3f) -> bool {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y ||
             _v.z < _min.z || _v.z > _max.z);
}

fn insideAABB(_v: vec2f, _aabb: vec4f) -> bool { return inside(_v, _aabb.xy, _aabb.zw); }

Licenses

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.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository