mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-19 04:38:01 +00:00
Switch float compares to epsilon version
This commit is contained in:
parent
5d99f75ab6
commit
9b34af6e3e
26
clay.h
26
clay.h
@ -2018,9 +2018,19 @@ void Clay__InitializePersistentMemory(Clay_Context* context) {
|
|||||||
context->arenaResetOffset = arena->nextAllocation;
|
context->arenaResetOffset = arena->nextAllocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Clay__FloatEq(float left, float right) {
|
float CLAY__EPSILON = 0.01;
|
||||||
|
|
||||||
|
bool Clay__FloatEqual(float left, float right) {
|
||||||
float subtracted = left - right;
|
float subtracted = left - right;
|
||||||
return subtracted < 0.01 && subtracted > -0.01;
|
return subtracted < CLAY__EPSILON && subtracted > -CLAY__EPSILON;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Clay__FloatGreaterThan(float left, float right) {
|
||||||
|
return left > (right + CLAY__EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Clay__FloatLessThan(float left, float right) {
|
||||||
|
return (left + CLAY__EPSILON) < right;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clay__SizeContainersAlongAxis(bool xAxis) {
|
void Clay__SizeContainersAlongAxis(bool xAxis) {
|
||||||
@ -2130,11 +2140,11 @@ void Clay__SizeContainersAlongAxis(bool xAxis) {
|
|||||||
for (int childIndex = 0; childIndex < resizableContainerBuffer.length; childIndex++) {
|
for (int childIndex = 0; childIndex < resizableContainerBuffer.length; childIndex++) {
|
||||||
Clay_LayoutElement *child = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&resizableContainerBuffer, childIndex));
|
Clay_LayoutElement *child = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&resizableContainerBuffer, childIndex));
|
||||||
float childSize = xAxis ? child->dimensions.width : child->dimensions.height;
|
float childSize = xAxis ? child->dimensions.width : child->dimensions.height;
|
||||||
if (childSize > largest) {
|
if (Clay__FloatGreaterThan(childSize, largest)) {
|
||||||
secondLargest = largest;
|
secondLargest = largest;
|
||||||
largest = childSize;
|
largest = childSize;
|
||||||
}
|
}
|
||||||
if (childSize < largest) {
|
if (Clay__FloatLessThan(childSize, largest)) {
|
||||||
secondLargest = CLAY__MAX(secondLargest, childSize);
|
secondLargest = CLAY__MAX(secondLargest, childSize);
|
||||||
widthToAdd = secondLargest - largest;
|
widthToAdd = secondLargest - largest;
|
||||||
}
|
}
|
||||||
@ -2147,7 +2157,7 @@ void Clay__SizeContainersAlongAxis(bool xAxis) {
|
|||||||
float *childSize = xAxis ? &child->dimensions.width : &child->dimensions.height;
|
float *childSize = xAxis ? &child->dimensions.width : &child->dimensions.height;
|
||||||
float minSize = xAxis ? child->minDimensions.width : child->minDimensions.height;
|
float minSize = xAxis ? child->minDimensions.width : child->minDimensions.height;
|
||||||
float previousWidth = *childSize;
|
float previousWidth = *childSize;
|
||||||
if (Clay__FloatEq(*childSize, largest)) {
|
if (Clay__FloatEqual(*childSize, largest)) {
|
||||||
*childSize += widthToAdd;
|
*childSize += widthToAdd;
|
||||||
if (*childSize <= minSize) {
|
if (*childSize <= minSize) {
|
||||||
*childSize = minSize;
|
*childSize = minSize;
|
||||||
@ -2173,11 +2183,11 @@ void Clay__SizeContainersAlongAxis(bool xAxis) {
|
|||||||
for (int childIndex = 0; childIndex < resizableContainerBuffer.length; childIndex++) {
|
for (int childIndex = 0; childIndex < resizableContainerBuffer.length; childIndex++) {
|
||||||
Clay_LayoutElement *child = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&resizableContainerBuffer, childIndex));
|
Clay_LayoutElement *child = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_GetValue(&resizableContainerBuffer, childIndex));
|
||||||
float childSize = xAxis ? child->dimensions.width : child->dimensions.height;
|
float childSize = xAxis ? child->dimensions.width : child->dimensions.height;
|
||||||
if (childSize < smallest) {
|
if (Clay__FloatLessThan(childSize, smallest)) {
|
||||||
secondSmallest = smallest;
|
secondSmallest = smallest;
|
||||||
smallest = childSize;
|
smallest = childSize;
|
||||||
}
|
}
|
||||||
if (childSize > smallest) {
|
if (Clay__FloatGreaterThan(childSize, smallest)) {
|
||||||
secondSmallest = CLAY__MIN(secondSmallest, childSize);
|
secondSmallest = CLAY__MIN(secondSmallest, childSize);
|
||||||
widthToAdd = secondSmallest - smallest;
|
widthToAdd = secondSmallest - smallest;
|
||||||
}
|
}
|
||||||
@ -2190,7 +2200,7 @@ void Clay__SizeContainersAlongAxis(bool xAxis) {
|
|||||||
float *childSize = xAxis ? &child->dimensions.width : &child->dimensions.height;
|
float *childSize = xAxis ? &child->dimensions.width : &child->dimensions.height;
|
||||||
float maxSize = xAxis ? child->layoutConfig->sizing.width.size.minMax.max : child->layoutConfig->sizing.height.size.minMax.max;
|
float maxSize = xAxis ? child->layoutConfig->sizing.width.size.minMax.max : child->layoutConfig->sizing.height.size.minMax.max;
|
||||||
float previousWidth = *childSize;
|
float previousWidth = *childSize;
|
||||||
if (Clay__FloatEq(*childSize, smallest)) {
|
if (Clay__FloatEqual(*childSize, smallest)) {
|
||||||
*childSize += widthToAdd;
|
*childSize += widthToAdd;
|
||||||
if (*childSize >= maxSize) {
|
if (*childSize >= maxSize) {
|
||||||
*childSize = maxSize;
|
*childSize = maxSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user