Skip to content

Commit 74c93d2

Browse files
committed
refactor: improve naming + remove unused functions; rename CubicSpline to CubicProfile since it's not a spline, change function names to more common and correct naming
1 parent 1c297c7 commit 74c93d2

19 files changed

Lines changed: 143 additions & 153 deletions

include/CubicBezier.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ struct CubicBezier
1818
CubicBezier() = default;
1919
CubicBezier(std::array<Vec<T, Dim>, 4> control_points);
2020

21-
Vec<T, Dim> get(const T t) const;
22-
Vec<T, Dim> get_grad(const T t) const;
21+
Vec<T, Dim> evaluate(const T t) const;
22+
Vec<T, Dim> derivative(const T t) const;
2323
T get_t(const T arclen) const;
2424
T get_length() const;
2525
std::array<Vec<T, Dim>, 4> get_subcurve(const T t_start, const T t_end) const;
@@ -89,8 +89,8 @@ CubicBezier<T, Dim>::CubicBezier(std::array<Vec<T, Dim>, 4> control_points) : co
8989
T arclen(0);
9090
for (auto t_val_iter = std::next(t_vals.begin()); t_val_iter != t_vals.end(); t_val_iter++)
9191
{
92-
const Vec<T, Dim> pt_prev = this->get(*std::prev(t_val_iter));
93-
const Vec<T, Dim> pt = this->get(*t_val_iter);
92+
const Vec<T, Dim> pt_prev = this->evaluate(*std::prev(t_val_iter));
93+
const Vec<T, Dim> pt = this->evaluate(*t_val_iter);
9494
arclen += euclDistance(pt, pt_prev);
9595
this->arclen_t[arclen] = *t_val_iter;
9696
}
@@ -99,7 +99,7 @@ CubicBezier<T, Dim>::CubicBezier(std::array<Vec<T, Dim>, 4> control_points) : co
9999
}
100100

101101
template<typename T, std::size_t Dim>
102-
Vec<T, Dim> CubicBezier<T, Dim>::get(const T t) const
102+
Vec<T, Dim> CubicBezier<T, Dim>::evaluate(const T t) const
103103
{
104104
Vec<T, Dim> out_pt;
105105
for (std::size_t dim = 0; dim < Dim; dim++)
@@ -142,7 +142,7 @@ T CubicBezier<T, Dim>::get_length() const
142142
}
143143

144144
template<typename T, std::size_t Dim>
145-
Vec<T, Dim> CubicBezier<T, Dim>::get_grad(const T t) const
145+
Vec<T, Dim> CubicBezier<T, Dim>::derivative(const T t) const
146146
{
147147
std::array<Vec<T, Dim>, 4> coefficients = this->get_coefficients(this->control_points);
148148

@@ -156,7 +156,7 @@ Vec<T, Dim> CubicBezier<T, Dim>::get_grad(const T t) const
156156
template<typename T, std::size_t Dim>
157157
std::array<Vec<T, Dim>, 4> CubicBezier<T, Dim>::get_subcurve(const T t_start, const T t_end) const
158158
{
159-
/* modified get(T t) allowing different t values for segments */
159+
/* modified evaluate(T t) allowing different t values for segments */
160160
auto f_cubic_t123 = [](const T& t1, const T& t2, const T& t3, const std::array<Vec<T, Dim>, 4>& ctrl_pts) -> Vec<T, Dim>
161161
{
162162
Vec<T, Dim> out;

include/Geometries/Arc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Arc : public RoadGeometry
1515
std::unique_ptr<RoadGeometry> clone() const override;
1616

1717
Vec2D get_xy(double s) const override;
18-
Vec2D get_grad(double s) const override;
18+
Vec2D derivative(double s) const override;
1919

2020
std::set<double> approximate_linear(double eps) const override;
2121

include/Geometries/CubicSpline.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@
66
namespace odr
77
{
88

9-
struct Poly3
9+
struct CubicPoly
1010
{
11-
Poly3() = default;
12-
Poly3(double s0, double a, double b, double c, double d);
11+
CubicPoly() = default;
12+
CubicPoly(double a, double b, double c, double d, double s_origin = 0.0); // constructs a global cubic from local coefficients in (s - s_origin)
1313

14-
double get(double s) const;
15-
double get_grad(double s) const;
16-
double get_max(double s_start, double s_end) const;
17-
void negate();
18-
bool is_zero() const;
19-
void set_zero();
20-
bool isnan() const;
14+
double evaluate(const double s) const;
15+
double derivative(const double s) const;
16+
double max_value(const double s_start, const double s_end) const;
2117

22-
std::set<double> approximate_linear(double eps, double s_start, double s_end) const;
18+
void negate();
19+
bool is_zero() const;
20+
void set_zero();
21+
bool isnan() const;
22+
23+
std::set<double> approximate_linear(const double eps, const double s_start, const double s_end) const;
2324

2425
double a = 0;
2526
double b = 0;
2627
double c = 0;
2728
double d = 0;
2829
};
2930

30-
struct CubicSpline
31+
struct CubicProfile
3132
{
32-
CubicSpline() = default;
33+
CubicProfile() = default;
34+
35+
double evaluate(const double s, const double default_val = 0.0, const bool extend_start = true) const;
36+
double derivative(const double s, const double default_val = 0.0, const bool extend_start = true) const;
37+
double max_value(const double s_start, const double s_end) const;
3338

34-
double get(double s, double default_val = 0.0, bool extend_start = true) const;
35-
double get_grad(double s, double default_val = 0.0, bool extend_start = true) const;
36-
double get_max(double s_start, double s_end) const;
37-
Poly3 get_poly(double s, bool extend_start = true) const;
39+
CubicPoly get_poly(const double s, const bool extend_start = true) const;
3840

39-
bool empty() const;
40-
std::size_t size() const;
41-
CubicSpline negate() const;
42-
CubicSpline add(const CubicSpline& other) const;
41+
[[nodiscard]] CubicProfile negate() const;
42+
[[nodiscard]] CubicProfile add(const CubicProfile& other) const;
4343

4444
std::set<double> approximate_linear(double eps, double s_start, double s_end) const;
4545

46-
std::map<double, Poly3> s0_to_poly;
46+
std::map<double /* s0 */, CubicPoly> segments;
4747
};
4848

4949
} // namespace odr

include/Geometries/Line.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Line : public RoadGeometry
1515
std::unique_ptr<RoadGeometry> clone() const override;
1616

1717
Vec2D get_xy(double s) const override;
18-
Vec2D get_grad(double s) const override;
18+
Vec2D derivative(double s) const override;
1919

2020
std::set<double> approximate_linear(double eps) const override;
2121
};

include/Geometries/ParamPoly3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ParamPoly3 : public RoadGeometry
2929
std::unique_ptr<RoadGeometry> clone() const override;
3030

3131
Vec2D get_xy(double s) const override;
32-
Vec2D get_grad(double s) const override;
32+
Vec2D derivative(double s) const override;
3333

3434
std::set<double> approximate_linear(double eps) const override;
3535

include/Geometries/RoadGeometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct RoadGeometry
1515
virtual std::unique_ptr<RoadGeometry> clone() const = 0;
1616

1717
virtual Vec2D get_xy(double s) const = 0;
18-
virtual Vec2D get_grad(double s) const = 0;
18+
virtual Vec2D derivative(double s) const = 0;
1919

2020
virtual std::set<double> approximate_linear(double eps) const = 0;
2121

include/Geometries/Spiral.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct Spiral : public RoadGeometry
1515
std::unique_ptr<RoadGeometry> clone() const override;
1616

1717
Vec2D get_xy(double s) const override;
18-
Vec2D get_grad(double s) const override;
18+
Vec2D derivative(double s) const override;
1919

2020
std::set<double> approximate_linear(double eps) const override;
2121

include/Lane.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ struct Lane
6262
std::optional<int> predecessor;
6363
std::optional<int> successor;
6464

65-
CubicSpline lane_width;
66-
CubicSpline outer_border;
65+
CubicProfile lane_width;
66+
CubicProfile outer_border;
6767

6868
std::map<double, HeightOffset> s_to_height_offset;
6969
std::set<RoadMarkGroup> roadmark_groups;

include/RefLine.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ struct RefLine
2323
RoadGeometry* get_geometry(const double s);
2424

2525
Vec3D get_xyz(const double s) const;
26-
Vec3D get_grad(const double s) const;
26+
Vec3D derivative(const double s) const;
2727
Line3D get_line(const double s_start, const double s_end, const double eps) const;
2828
double match(const double x, const double y) const;
2929
std::set<double> approximate_linear(const double eps, const double s_start, const double s_end) const;
3030

31-
double length = 0;
32-
CubicSpline elevation_profile;
31+
double length = 0;
32+
CubicProfile elevation_profile;
3333

3434
std::map<double, std::unique_ptr<RoadGeometry>> s0_to_geometry;
3535
};

include/Road.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace odr
1919
struct Lane;
2020
struct RoadMark;
2121

22-
struct Crossfall : public CubicSpline
22+
struct Crossfall : public CubicProfile
2323
{
2424
enum class Side
2525
{
@@ -121,10 +121,10 @@ class Road
121121
RoadLink successor;
122122
std::vector<RoadNeighbor> neighbors;
123123

124-
CubicSpline lane_offset;
125-
CubicSpline superelevation;
126-
Crossfall crossfall;
127-
RefLine ref_line;
124+
CubicProfile lane_offset;
125+
CubicProfile superelevation;
126+
Crossfall crossfall;
127+
RefLine ref_line;
128128

129129
std::map<double, LaneSection> s_to_lanesection;
130130
std::map<double, std::string> s_to_type;

0 commit comments

Comments
 (0)