| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/ObjectStream/SerializableObject.h> |
| 8 |
#include <Jolt/Core/QuickSort.h> |
| 9 |
|
| 10 |
JPH_NAMESPACE_BEGIN |
| 11 |
|
| 12 |
class StreamOut; |
| 13 |
class StreamIn; |
| 14 |
|
| 15 |
|
| 16 |
class JPH_EXPORT LinearCurve |
| 17 |
{ |
| 18 |
JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, LinearCurve) |
| 19 |
|
| 20 |
public: |
| 21 |
|
| 22 |
class Point |
| 23 |
{ |
| 24 |
JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Point) |
| 25 |
|
| 26 |
public: |
| 27 |
float mX = 0.0f; |
| 28 |
float mY = 0.0f; |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
void Clear() { mPoints.clear(); } |
| 33 |
|
| 34 |
|
| 35 |
void Reserve(uint inNumPoints) { mPoints.reserve(inNumPoints); } |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void AddPoint(float inX, float inY) { mPoints.push_back({ inX, inY }); } |
| 41 |
|
| 42 |
|
| 43 |
void Sort() { QuickSort(mPoints.begin(), mPoints.end(), [](const Point &inLHS, const Point &inRHS) { return inLHS.mX < inRHS.mX; }); } |
| 44 |
|
| 45 |
|
| 46 |
float GetMinX() const { return mPoints.empty()? 0.0f : mPoints.front().mX; } |
| 47 |
|
| 48 |
|
| 49 |
float GetMaxX() const { return mPoints.empty()? 0.0f : mPoints.back().mX; } |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
float GetValue(float inX) const; |
| 55 |
|
| 56 |
|
| 57 |
void SaveBinaryState(StreamOut &inStream) const; |
| 58 |
|
| 59 |
|
| 60 |
void RestoreBinaryState(StreamIn &inStream); |
| 61 |
|
| 62 |
|
| 63 |
using Points = Array<Point>; |
| 64 |
Points mPoints; |
| 65 |
}; |
| 66 |
|
| 67 |
JPH_NAMESPACE_END |