Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pierre Fernbach
curves
Commits
899dd9db
Commit
899dd9db
authored
Aug 09, 2019
by
Pierre Fernbach
Browse files
[piecewise] refactor/simplify constructor from discret point
parent
4cc0b596
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/curves/piecewise_curve.h
View file @
899dd9db
...
...
@@ -216,51 +216,23 @@ namespace curves
}
template
<
typename
Polynomial
>
static
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
convert_discrete_points_to_polynomial
(
T_Point
points
,
Time
T_min
,
Time
T_max
)
static
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
convert_discrete_points_to_polynomial
(
T_Point
points
,
t_time_t
time_points
)
{
if
(
Safe
&!
(
points
.
size
()
>
1
))
{
//std::cout<<"[Min,Max]=["<<T_min_<<","<<T_max_<<"]"<<" t="<<t<<std::endl;
throw
std
::
invalid_argument
(
"piecewise_curve
->
convert_discrete_points_to_polynomial
,
Error, less than 2 discrete points"
);
throw
std
::
invalid_argument
(
"piecewise_curve
::
convert_discrete_points_to_polynomial
:
Error, less than 2 discrete points"
);
}
typedef
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
piecewise_curve_out_t
;
Time
discretization_step
=
(
T_max
-
T_min
)
/
Time
(
points
.
size
()
-
1
);
Time
time_actual
=
T_min
;
// Initialization at first points
point_t
actual_point
=
points
[
0
];
point_t
next_point
=
points
[
1
];
point_t
coeff_order_zero
(
actual_point
);
point_t
coeff_order_one
((
next_point
-
actual_point
)
/
discretization_step
);
t_point_t
coeffs
;
coeffs
.
push_back
(
coeff_order_zero
);
coeffs
.
push_back
(
coeff_order_one
);
Polynomial
pol
(
coeffs
,
time_actual
,
time_actual
+
discretization_step
);
piecewise_curve_out_t
ppc
(
pol
);
time_actual
+=
discretization_step
;
// Other points
for
(
std
::
size_t
i
=
1
;
i
<
points
.
size
()
-
2
;
i
++
)
{
coeffs
.
clear
();
actual_point
=
points
[
i
];
next_point
=
points
[
i
+
1
];
coeff_order_zero
=
actual_point
;
coeff_order_one
=
(
next_point
-
actual_point
)
/
discretization_step
;
coeffs
.
push_back
(
coeff_order_zero
);
coeffs
.
push_back
(
coeff_order_one
);
ppc
.
add_curve
(
Polynomial
(
coeffs
,
time_actual
,
time_actual
+
discretization_step
));
time_actual
+=
discretization_step
;
if
(
points
.
size
()
!=
time_points
.
size
()){
throw
std
::
invalid_argument
(
"piecewise_curve::convert_discrete_points_to_polynomial: Error, points and time_points must have the same size."
);
}
piecewise_curve
<
Time
,
Numeric
,
Safe
,
Point
,
T_Point
,
Polynomial
>
piecewise_res
;
for
(
size_t
i
=
1
;
i
<
points
.
size
()
;
++
i
){
piecewise_res
.
add_curve
(
Polynomial
(
points
[
i
-
1
],
points
[
i
],
time_points
[
i
-
1
],
time_points
[
i
]));
}
// Last points
coeffs
.
clear
();
actual_point
=
points
[
points
.
size
()
-
2
];
next_point
=
points
[
points
.
size
()
-
1
];
coeff_order_zero
=
actual_point
;
coeff_order_one
=
(
next_point
-
actual_point
)
/
discretization_step
;
coeffs
.
push_back
(
coeff_order_zero
);
coeffs
.
push_back
(
coeff_order_one
);
ppc
.
add_curve
(
Polynomial
(
coeffs
,
time_actual
,
T_max
));
return
ppc
;
return
piecewise_res
;
}
private:
...
...
@@ -357,4 +329,4 @@ namespace curves
}
// end namespace
#endif // _CLASS_PIECEWISE_CURVE
\ No newline at end of file
#endif // _CLASS_PIECEWISE_CURVE
tests/Main.cpp
View file @
899dd9db
...
...
@@ -1335,37 +1335,28 @@ void curveAbcDimDynamicTest(bool& error)
void
piecewiseCurveConversionFromDiscretePointsTest
(
bool
&
error
)
{
try
{
std
::
string
errMsg
(
"piecewiseCurveConversionFromDiscretePointsTest, Error, value on curve is wrong : "
);
point_t
p0
(
0.
,
0.
,
0.
);
point_t
p1
(
1.
,
2.
,
3.
);
point_t
p2
(
4.
,
4.
,
4.
);
point_t
p3
(
10.
,
10.
,
10.
);
point_t
p_test_0_5
=
(
p0
+
p1
)
/
2.0
;
t_point_t
points
;
points
.
push_back
(
p0
);
points
.
push_back
(
p1
);
points
.
push_back
(
p2
);
points
.
push_back
(
p3
);
double
T_min
=
1.0
;
double
T_max
=
3.0
;
double
timestep
=
(
T_max
-
T_min
)
/
double
(
points
.
size
()
-
1
);
piecewise_polynomial_curve_t
ppc
=
piecewise_polynomial_curve_t
::
convert_discrete_points_to_polynomial
<
polynomial_t
>
(
points
,
T_min
,
T_max
);
if
(
!
ppc
.
is_continuous
(
0
))
{
std
::
cout
<<
"piecewiseCurveConversionFromDiscretePointsTest, Error, piecewise curve is not C0"
<<
std
::
endl
;
error
=
true
;
}
ComparePoints
(
p0
,
ppc
(
T_min
),
errMsg
,
error
);
ComparePoints
(
p_test_0_5
,
ppc
(
T_min
+
timestep
/
2.0
),
errMsg
,
error
);
ComparePoints
(
p1
,
ppc
(
T_min
+
timestep
),
errMsg
,
error
);
ComparePoints
(
p2
,
ppc
(
T_min
+
2
*
timestep
),
errMsg
,
error
);
ComparePoints
(
p3
,
ppc
(
T_max
),
errMsg
,
error
);
}
catch
(...)
{
std
::
string
errMsg
(
"piecewiseCurveConversionFromDiscretePointsTest, Error, value on curve is wrong : "
);
point_t
p0
(
0.
,
0.
,
0.
);
point_t
p1
(
1.
,
2.
,
3.
);
point_t
p2
(
4.
,
4.
,
4.
);
point_t
p3
(
10.
,
10.
,
10.
);
point_t
p_test_0_5
=
(
p0
+
p1
)
/
2.0
;
t_point_t
points
;
points
.
push_back
(
p0
);
points
.
push_back
(
p1
);
points
.
push_back
(
p2
);
points
.
push_back
(
p3
);
double
T_min
=
1.0
;
double
T_max
=
3.0
;
double
timestep
=
(
T_max
-
T_min
)
/
double
(
points
.
size
()
-
1
);
std
::
vector
<
double
>
time_points
;
for
(
size_t
i
=
0
;
i
<
points
.
size
();
++
i
)
time_points
.
push_back
(
T_min
+
i
*
timestep
);
piecewise_polynomial_curve_t
ppc
=
piecewise_polynomial_curve_t
::
convert_discrete_points_to_polynomial
<
polynomial_t
>
(
points
,
time_points
);
if
(
!
ppc
.
is_continuous
(
0
))
{
std
::
cout
<<
"piecewiseCurveConversionFromDiscretePointsTest, Error, piecewise curve is not C0"
<<
std
::
endl
;
error
=
true
;
std
::
cout
<<
"Error in piecewiseCurveConversionFromDiscretePointsTest"
<<
std
::
endl
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment