[apps/shared] Range1D is used in a Storage::Record::DataBuffer and thus

should be packed and might be unaligned
This commit is contained in:
Émilie Feral
2019-09-04 14:23:17 +02:00
parent bac7fe0fce
commit 065edbbf05

View File

@@ -6,7 +6,11 @@
namespace Shared {
class Range1D {
/* This class is used in a DataBuffer of a Storage::Record. See comment in
* Shared::Function::FunctionRecordDataBuffer about packing. */
#pragma pack(push,1)
class Range1D final {
public:
constexpr static float k_minFloat = 1E-4f;
Range1D(float min = -10.0f, float max = 10.0f) :
@@ -20,9 +24,17 @@ public:
static float clipped(float x, bool isMax, float lowerMaxFloat, float upperMaxFloat);
static float defaultRangeLengthFor(float position);
private:
#if __EMSCRIPTEN__
// See comment about emscripten alignement in Shared::Function::FunctionRecordDataBuffer
static_assert(sizeof(emscripten_align1_short) == sizeof(uint16_t), "emscripten_align1_short should have the same size as uint16_t");
emscripten_align1_float m_min;
emscripten_align1_float m_max;
#else
float m_min;
float m_max;
#endif
};
#pragma pack(pop)
static_assert(Range1D::k_minFloat >= FLT_EPSILON, "InteractiveCurveViewRange's minimal float range is lower than float precision, it might draw uglily curves such as cos(x)^2+sin(x)^2");