mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-25 18:05:12 -04:00
c17dc1a4ff
Adapted from the original feature commits, retaining their author credit: [82695b75](https://github.com/FractalEngineer/psxrecomp/commit/82695b75d79610ca7a99783adf9dd5195edfcdd0) [5633e868](https://github.com/FractalEngineer/psxrecomp/commit/5633e86878611a14d3a78e8f9708452a07bc7238) [bbd01ccf](https://github.com/FractalEngineer/psxrecomp/commit/bbd01ccfc91c1d9ebe199dad071df64e5b13d06d) [39d478db](https://github.com/FractalEngineer/psxrecomp/commit/39d478db83132815c2c8c593fc719c4bf67301b0) Source scope and current-master validation: docs/internal/upstream/gte-projection-distance-scale.md Co-authored-by: Yves <calibratedbeats@gmail.com>
26 lines
935 B
C++
26 lines
935 B
C++
#pragma once
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#include <cerrno>
|
|
#include <cctype>
|
|
inline bool psx_projection_scale_valid(double v) {
|
|
return std::isfinite(v) && v > 0.0 && v <= 8.0;
|
|
}
|
|
inline bool psx_projection_scale_parse(const char* text, double* out) {
|
|
if (!text || !out) return false;
|
|
char* end = nullptr;
|
|
errno = 0;
|
|
const double value = std::strtod(text, &end);
|
|
if (end == text || errno == ERANGE) return false;
|
|
while (*end && std::isspace(static_cast<unsigned char>(*end))) ++end;
|
|
if (*end || !psx_projection_scale_valid(value)) return false;
|
|
*out = value;
|
|
return true;
|
|
}
|
|
/* Preserve the existing milliscale precision without rounding tiny positive
|
|
* values to a zero denominator (which would silently restore identity). */
|
|
inline int psx_projection_scale_denominator(double v) {
|
|
const int quantized = static_cast<int>(v * 1000.0 + 0.5);
|
|
return quantized < 1 ? 1 : quantized;
|
|
}
|