Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
LinearCurve.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
12class StreamOut;
13class StreamIn;
14
15// A set of points (x, y) that form a linear curve
17{
19
20public:
22 class Point
23 {
25
26 public:
27 float mX = 0.0f;
28 float mY = 0.0f;
29 };
30
32 void Clear() { mPoints.clear(); }
33
35 void Reserve(uint inNumPoints) { mPoints.reserve(inNumPoints); }
36
40 void AddPoint(float inX, float inY) { mPoints.push_back({ inX, inY }); }
41
43 void Sort() { QuickSort(mPoints.begin(), mPoints.end(), [](const Point &inLHS, const Point &inRHS) { return inLHS.mX < inRHS.mX; }); }
44
46 float GetMinX() const { return mPoints.empty()? 0.0f : mPoints.front().mX; }
47
49 float GetMaxX() const { return mPoints.empty()? 0.0f : mPoints.back().mX; }
50
54 float GetValue(float inX) const;
55
57 void SaveBinaryState(StreamOut &inStream) const;
58
60 void RestoreBinaryState(StreamIn &inStream);
61
65};
66
#define JPH_EXPORT
Definition Core.h:236
unsigned int uint
Definition Core.h:453
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
void QuickSort(Iterator inBegin, Iterator inEnd, Compare inCompare)
Implementation of the quick sort algorithm. The STL version implementation is not consistent across p...
Definition QuickSort.h:53
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:80
A point on the curve.
Definition LinearCurve.h:23
Definition LinearCurve.h:17
Points mPoints
Definition LinearCurve.h:64
void Reserve(uint inNumPoints)
Reserve memory for inNumPoints points.
Definition LinearCurve.h:35
void AddPoint(float inX, float inY)
Definition LinearCurve.h:40
float GetMaxX() const
Get the highest X value.
Definition LinearCurve.h:49
float GetMinX() const
Get the lowest X value.
Definition LinearCurve.h:46
void Sort()
Sort the points on X ascending.
Definition LinearCurve.h:43
void Clear()
Remove all points.
Definition LinearCurve.h:32
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13