Float fixes, sensible settings
This commit is contained in:
31
src/COMMON.h
31
src/COMMON.h
@@ -114,9 +114,21 @@ static inline std::string string_to_lowercase(std::string string) {
|
||||
return string;
|
||||
}
|
||||
|
||||
#define FLOAT_FORMAT_MAX_DECIMALS 2
|
||||
#define FLOAT_FORMAT_EPSILON 1e-6f
|
||||
static constexpr f32 FLOAT_FORMAT_POW10[] = {1.f, 10.f, 100.f};
|
||||
|
||||
#define FLOAT_FORMAT_MAX_DECIMALS 9
|
||||
#define FLOAT_FORMAT_EPSILON 1e-9f
|
||||
static constexpr f32 FLOAT_FORMAT_POW10[] = {
|
||||
1.f,
|
||||
10.f,
|
||||
100.f,
|
||||
1000.f,
|
||||
10000.f,
|
||||
100000.f,
|
||||
1000000.f,
|
||||
10000000.f,
|
||||
100000000.f,
|
||||
1000000000.f
|
||||
};
|
||||
|
||||
static inline s32 f32_decimals_needed(f32 value)
|
||||
{
|
||||
@@ -130,9 +142,12 @@ static inline s32 f32_decimals_needed(f32 value)
|
||||
for (s32 decimalCount = 1; decimalCount <= FLOAT_FORMAT_MAX_DECIMALS; ++decimalCount)
|
||||
{
|
||||
f32 scaledFraction = fractionalPart * FLOAT_FORMAT_POW10[decimalCount];
|
||||
if (fabsf(scaledFraction - roundf(scaledFraction)) < FLOAT_FORMAT_EPSILON * FLOAT_FORMAT_POW10[decimalCount])
|
||||
if (fabsf(scaledFraction - roundf(scaledFraction)) <
|
||||
FLOAT_FORMAT_EPSILON * FLOAT_FORMAT_POW10[decimalCount])
|
||||
{
|
||||
return decimalCount;
|
||||
}
|
||||
}
|
||||
return FLOAT_FORMAT_MAX_DECIMALS;
|
||||
}
|
||||
|
||||
@@ -140,7 +155,9 @@ static inline const char* f32_format_get(f32 value)
|
||||
{
|
||||
static std::string formatString;
|
||||
const s32 decimalCount = f32_decimals_needed(value);
|
||||
formatString = (decimalCount == 0) ? "%.0f" : ("%." + std::to_string(decimalCount) + "f");
|
||||
formatString = (decimalCount == 0)
|
||||
? "%.0f"
|
||||
: ("%." + std::to_string(decimalCount) + "f");
|
||||
return formatString.c_str();
|
||||
}
|
||||
|
||||
@@ -150,7 +167,9 @@ static inline const char* vec2_format_get(const vec2& value)
|
||||
const s32 decimalCountX = f32_decimals_needed(value.x);
|
||||
const s32 decimalCountY = f32_decimals_needed(value.y);
|
||||
const s32 decimalCount = (decimalCountX > decimalCountY) ? decimalCountX : decimalCountY;
|
||||
formatString = (decimalCount == 0) ? "%.0f" : ("%." + std::to_string(decimalCount) + "f");
|
||||
formatString = (decimalCount == 0)
|
||||
? "%.0f"
|
||||
: ("%." + std::to_string(decimalCount) + "f");
|
||||
return formatString.c_str();
|
||||
}
|
||||
|
||||
|
@@ -88,7 +88,7 @@
|
||||
\
|
||||
X(previewIsAxes, PREVIEW_IS_AXES, TYPE_BOOL, true) \
|
||||
X(previewIsGrid, PREVIEW_IS_GRID, TYPE_BOOL, true) \
|
||||
X(previewIsRootTransform, PREVIEW_IS_ROOT_TRANSFORM, TYPE_BOOL, false) \
|
||||
X(previewIsRootTransform, PREVIEW_IS_ROOT_TRANSFORM, TYPE_BOOL, true) \
|
||||
X(previewIsTriggers, PREVIEW_IS_TRIGGERS, TYPE_BOOL, true) \
|
||||
X(previewIsPivots, PREVIEW_IS_PIVOTS, TYPE_BOOL, false) \
|
||||
X(previewIsIcons, PREVIEW_IS_ICONS, TYPE_BOOL, true) \
|
||||
@@ -103,7 +103,7 @@
|
||||
X(previewAxesColor, PREVIEW_AXES_COLOR, TYPE_VEC4, {1.0,1.0,1.0,0.125}) \
|
||||
X(previewBackgroundColor, PREVIEW_BACKGROUND_COLOR, TYPE_VEC4, {0.113,0.184,0.286,1.0}) \
|
||||
\
|
||||
X(propertiesIsRound, PROPERTIES_IS_ROUND, TYPE_BOOL, true) \
|
||||
X(propertiesIsRound, PROPERTIES_IS_ROUND, TYPE_BOOL, false) \
|
||||
\
|
||||
X(generateStartPosition, GENERATE_START_POSITION, TYPE_IVEC2, {}) \
|
||||
X(generateSize, GENERATE_SIZE, TYPE_IVEC2, {64,64}) \
|
||||
|
Reference in New Issue
Block a user