Path: blob/master/thirdparty/jolt_physics/Jolt/Core/LinearCurve.h
9906 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/ObjectStream/SerializableObject.h>7#include <Jolt/Core/QuickSort.h>89JPH_NAMESPACE_BEGIN1011class StreamOut;12class StreamIn;1314// A set of points (x, y) that form a linear curve15class JPH_EXPORT LinearCurve16{17JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, LinearCurve)1819public:20/// A point on the curve21class Point22{23JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Point)2425public:26float mX = 0.0f;27float mY = 0.0f;28};2930/// Remove all points31void Clear() { mPoints.clear(); }3233/// Reserve memory for inNumPoints points34void Reserve(uint inNumPoints) { mPoints.reserve(inNumPoints); }3536/// Add a point to the curve. Points must be inserted in ascending X or Sort() needs to be called when all points have been added.37/// @param inX X value38/// @param inY Y value39void AddPoint(float inX, float inY) { mPoints.push_back({ inX, inY }); }4041/// Sort the points on X ascending42void Sort() { QuickSort(mPoints.begin(), mPoints.end(), [](const Point &inLHS, const Point &inRHS) { return inLHS.mX < inRHS.mX; }); }4344/// Get the lowest X value45float GetMinX() const { return mPoints.empty()? 0.0f : mPoints.front().mX; }4647/// Get the highest X value48float GetMaxX() const { return mPoints.empty()? 0.0f : mPoints.back().mX; }4950/// Sample value on the curve51/// @param inX X value to sample at52/// @return Interpolated Y value53float GetValue(float inX) const;5455/// Saves the state of this object in binary form to inStream.56void SaveBinaryState(StreamOut &inStream) const;5758/// Restore the state of this object from inStream.59void RestoreBinaryState(StreamIn &inStream);6061/// The points on the curve, should be sorted ascending by x62using Points = Array<Point>;63Points mPoints;64};6566JPH_NAMESPACE_END676869