SPH
Curve.h
Go to the documentation of this file.
1 #pragma once
2 
5 
7 
8 struct CurvePoint {
11 
12  bool operator==(const CurvePoint& other) const {
13  return x == other.x && y == other.y;
14  }
15 };
16 
19 class Curve {
20 private:
24 
25 public:
27  Curve();
28 
30  Curve(const Interval& rangeX, const Interval& rangeY);
31 
35  Curve(Array<CurvePoint>&& curve);
36 
37  Curve(const Curve& curve);
38 
39  Curve& operator=(const Curve& curve);
40 
42  Float operator()(const Float x) const;
43 
45  Size getPointCnt() const;
46 
48  const CurvePoint& getPoint(const Size idx) const;
49 
51  void setPoint(const Size idx, const CurvePoint& newPoint);
52 
56  void addPoint(const CurvePoint& newPoint);
57 
59  void deletePoint(const Size idx);
60 
64  bool getSegment(const Size idx) const;
65 
67  void setSegment(const Size idx, const bool cubic);
68 
70  Interval rangeX() const;
71 
73  Interval rangeY() const;
74 
75 private:
76  Float linear(const CurvePoint& p1, const CurvePoint& p2, const Float x) const;
77 
78  Float cubic(const CurvePoint& p1,
79  const CurvePoint& p2,
80  const Float dy1,
81  const Float dy2,
82  const Float x) const;
83 
84  void sort();
85 };
86 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
Object representing interval of real values.
#define NAMESPACE_SPH_END
Definition: Object.h:12
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Represents a user-defined function, defined by a set of points interpolated by either piecewise linea...
Definition: Curve.h:19
const CurvePoint & getPoint(const Size idx) const
Returns the position of idx-th point.
Definition: Curve.cpp:99
Interval rangeY() const
Returns the extent of the curve in y-direction.
Definition: Curve.cpp:142
Curve & operator=(const Curve &curve)
Definition: Curve.cpp:90
void setPoint(const Size idx, const CurvePoint &newPoint)
Modifies the position of idx-th points.
Definition: Curve.cpp:103
Size getPointCnt() const
Returns the number of points defining the curve.
Definition: Curve.cpp:95
void addPoint(const CurvePoint &newPoint)
Adds a new point to the curve.
Definition: Curve.cpp:108
void setSegment(const Size idx, const bool cubic)
Modifies the interpolation type of idx-th segment.
Definition: Curve.cpp:130
Interval rangeX() const
Returns the extent of the curve in x-direction.
Definition: Curve.cpp:134
Float operator()(const Float x) const
Evaluates the function and returns the result.
Definition: Curve.cpp:150
bool getSegment(const Size idx) const
Returns the interpolation type of idx-th segment.
Definition: Curve.cpp:126
Curve()
Creates an identity function, defined in interval [0, 1].
Definition: Curve.cpp:64
void deletePoint(const Size idx)
Removes idx-th point from curve.
Definition: Curve.cpp:120
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
Float x
Definition: Curve.h:9
bool operator==(const CurvePoint &other) const
Definition: Curve.h:12
Float y
Definition: Curve.h:10