Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
vadere
vadere
Commits
20d550f3
Commit
20d550f3
authored
Aug 26, 2019
by
Daniel Lehmberg
Browse files
add tests for interpolation
parent
72e271e1
Pipeline
#148252
failed with stages
in 63 minutes and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereState/src/org/vadere/state/simulation/FootStep.java
View file @
20d550f3
...
...
@@ -127,20 +127,21 @@ public final class FootStep {
static
public
VPoint
interpolateFootStep
(
FootStep
footStep
,
double
time
){
double
startTime
=
footStep
.
getStartTime
();
double
endTime
=
footStep
.
getEndTime
();
double
d
iffTime
=
endTime
-
startTime
;
double
d
uration
=
footStep
.
duration
()
;
if
(
startTime
>
time
||
endTime
<
time
){
throw
new
IllegalArgumentException
(
"Requested time "
+
time
+
" outside of FootSteps [start="
+
startTime
+
", end="
+
endTime
+
"] time (no extrapolation!)."
);
if
(
startTime
>
time
||
endTime
<
time
||
startTime
<
0
){
throw
new
IllegalArgumentException
(
"Requested time "
+
time
+
" outside of valid region. Outside of "
+
"FootStep [start="
+
startTime
+
", end="
+
endTime
+
"] time (no extrapolation!) or smaller than "
+
"zero;"
);
}
VPoint
interpolationResult
;
if
(
d
iffTime
<
1
E
-
1
3
){
if
(
d
uration
<
1
E
-
1
4
){
// to avoid problems with division by very small number, simply return the start point
interpolationResult
=
footStep
.
getStart
();
}
else
{
double
linearTime
=
(
time
-
startTime
)
/
d
iffTime
;
double
linearTime
=
(
time
-
startTime
)
/
d
uration
;
VPoint
diffPoint
=
footStep
.
getEnd
().
subtract
(
footStep
.
getStart
());
diffPoint
.
x
=
diffPoint
.
x
*
linearTime
;
...
...
VadereState/tests/org/vadere/state/simulation/FootStepTest.java
0 → 100644
View file @
20d550f3
package
org.vadere.state.simulation
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
org.vadere.util.geometry.shapes.VPoint
;
public
class
FootStepTest
{
private
FootStep
footStepHorizontal
;
private
FootStep
footStepVertical
;
private
FootStep
footStepDiagonal
;
@Before
public
void
setup
(){
footStepHorizontal
=
new
FootStep
(
new
VPoint
(
1
,
1
),
new
VPoint
(
2
,
1
),
0
,
1
);
footStepVertical
=
new
FootStep
(
new
VPoint
(
1
,
1
),
new
VPoint
(
1
,
2
),
0
,
1
);
footStepDiagonal
=
new
FootStep
(
new
VPoint
(
1
,
1
),
new
VPoint
(
2
,
2
),
0
,
1
);
}
@Test
public
void
interpolationTestStart
(){
// Give start point of FootStep
VPoint
actual
,
expected
;
actual
=
FootStep
.
interpolateFootStep
(
footStepHorizontal
,
0
);
expected
=
new
VPoint
(
1
,
1
.);
assertEquals
(
actual
,
expected
);
actual
=
FootStep
.
interpolateFootStep
(
footStepVertical
,
0
);
expected
=
new
VPoint
(
1
,
1
.);
assertEquals
(
actual
,
expected
);
actual
=
FootStep
.
interpolateFootStep
(
footStepDiagonal
,
0
);
expected
=
new
VPoint
(
1
,
1
.);
assertEquals
(
actual
,
expected
);
}
@Test
public
void
interpolationTestMid
(){
// Get point in the middle of direction from start
VPoint
actual
,
expected
;
actual
=
FootStep
.
interpolateFootStep
(
footStepHorizontal
,
0.5
);
expected
=
new
VPoint
(
1.5
,
1
.);
assertEquals
(
actual
,
expected
);
actual
=
FootStep
.
interpolateFootStep
(
footStepVertical
,
0.5
);
expected
=
new
VPoint
(
1
.
,
1.5
);
assertEquals
(
actual
,
expected
);
actual
=
FootStep
.
interpolateFootStep
(
footStepDiagonal
,
0.5
);
expected
=
new
VPoint
(
1.5
,
1.5
);
assertEquals
(
actual
,
expected
);
}
@Test
public
void
interpolationTestEnd
(){
// Get last point of FootStep
VPoint
actual
,
expected
;
actual
=
FootStep
.
interpolateFootStep
(
footStepHorizontal
,
1
);
expected
=
new
VPoint
(
2
.
,
1
.);
// Give same start point
assertEquals
(
actual
,
expected
);
actual
=
FootStep
.
interpolateFootStep
(
footStepVertical
,
1
);
expected
=
new
VPoint
(
1
.
,
2
.);
// Give same start point
assertEquals
(
actual
,
expected
);
actual
=
FootStep
.
interpolateFootStep
(
footStepDiagonal
,
1
);
expected
=
new
VPoint
(
2
.
,
2
.);
// Give same start point
assertEquals
(
actual
,
expected
);
}
@Test
public
void
interpolationTestTinyFootStep
(){
FootStep
footStep
=
new
FootStep
(
new
VPoint
(
0
,
0
),
new
VPoint
(
0.0001
,
0
),
0
,
0
+
1
E
-
15
);
VPoint
actual
=
FootStep
.
interpolateFootStep
(
footStep
,
1
E
-
16
);
VPoint
expected
=
footStep
.
getStart
();
// Return start, when footstep duration is too small
assertEquals
(
actual
,
expected
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
interpolationTestFail01
(){
FootStep
.
interpolateFootStep
(
footStepHorizontal
,
2
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
interpolationTestFail02
(){
FootStep
.
interpolateFootStep
(
footStepHorizontal
,
-
1
);
}
}
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