lygia
/v1.1.4
/space
/ratio
)Fix the aspect ratio of a space keeping things squared for you.
Use:
ratio(vec2 st, vec2 st_size)
#ifndef FNC_RATIO
#define FNC_RATIO
vec2 ratio(in vec2 st, in vec2 s) {
return mix( vec2((st.x*s.x/s.y)-(s.x*.5-s.y*.5)/s.y,st.y),
vec2(st.x,st.y*(s.y/s.x)-(s.y*.5-s.x*.5)/s.x),
step(s.x,s.y));
}
#endif
Use:
ratio(float2 st, float2 st_size)
#ifndef FNC_RATIO
#define FNC_RATIO
float2 ratio(in float2 st, in float2 s) {
return lerp( float2((st.x*s.x/s.y)-(s.x*.5-s.y*.5)/s.y,st.y),
float2(st.x,st.y*(s.y/s.x)-(s.y*.5-s.x*.5)/s.x),
step(s.x, s.y));
}
#endif
fn ratio(st: vec2<f32>, s: vec2<f32>) -> vec2<f32> {
return mix( vec2<f32>((st.x*s.x/s.y)-(s.x*.5-s.y*.5)/s.y,st.y),
vec2<f32>(st.x,st.y*(s.y/s.x)-(s.y*.5-s.x*.5)/s.x),
step(s.x,s.y));
}
Dependencies:
Use:
ratio(float2 st, float2 st_size)
#ifndef FNC_RATIO
#define FNC_RATIO
inline __host__ __device__ float2 ratio(float2 st, float2 s) {
return lerp( make_float2((st.x*s.x/s.y)-(s.x*.5-s.y*.5)/s.y, st.y),
make_float2( st.x,st.y*(s.y/s.x)-(s.y*.5-s.x*.5)/s.x),
step(s.x, s.y) );
}
#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