Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
f97329c7
Commit
f97329c7
authored
Sep 03, 2018
by
Benedikt Zoennchen
Browse files
add missing model tests again :(, dont know why I have deleted them.
parent
50f9c592
Pipeline
#67561
failed with stages
in 53 minutes and 30 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereUtils/src/org/vadere/util/io/TableReader.java
View file @
f97329c7
...
...
@@ -4,10 +4,10 @@ import java.util.Arrays;
import
java.util.Optional
;
import
java.util.stream.Stream
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.commons.lang3.tuple.Triple
;
import
org.vadere.util.data.Row
;
import
org.vadere.util.data.Table
;
import
org.vadere.util.data.Tripel
;
import
org.vadere.util.data.Tupel
;
/**
* This class convert a stream of table lines {@link java.util.stream.Stream<String>} into a
...
...
@@ -55,10 +55,10 @@ public class TableReader {
long
limit
=
headerFormat
.
chars
().
filter
(
c
->
c
==
'%'
).
count
();
return
Stream
.
iterate
(
Tupel
.
of
(
headerFormat
,
line
.
get
()),
t
->
nextResidual
(
t
))
.
iterate
(
Pair
.
of
(
headerFormat
,
line
.
get
()),
t
->
nextResidual
(
t
))
.
limit
(
limit
)
.
filter
(
t
->
t
.
isPresent
()
)
.
map
(
t
->
toValue
(
t
.
v1
,
t
.
v2
).
toString
()).
toArray
(
String
[]::
new
);
.
filter
(
pair
->
pair
.
getValue
()
!=
null
)
.
map
(
pair
->
toValue
(
pair
.
getLeft
(),
pair
.
getRight
()
).
toString
()).
toArray
(
String
[]::
new
);
}
return
headline
;
}
...
...
@@ -74,9 +74,9 @@ public class TableReader {
format
=
Arrays
.
stream
(
line
.
split
(
" "
)).
reduce
(
""
,
(
s1
,
s2
)
->
s1
.
concat
(
"%s "
)).
trim
();
}
Row
row
=
Stream
.
iterate
(
Trip
e
l
.
of
(
0
,
format
,
line
),
t
->
nextResidual
(
t
))
.
iterate
(
Tripl
e
.
of
(
0
,
format
,
line
),
t
->
nextResidual
(
t
))
.
limit
(
variables
.
length
)
.
map
(
tripel
->
toColumn
(
variables
[
tripel
.
v1
],
tripel
.
v2
,
tripel
.
v3
))
.
map
(
tripel
->
toColumn
(
variables
[
tripel
.
getLeft
()
],
tripel
.
getMiddle
(),
tripel
.
getRight
()
))
.
reduce
(
new
Row
(),
(
r1
,
r2
)
->
r1
.
combine
(
r2
));
return
row
;
}
...
...
@@ -105,37 +105,37 @@ public class TableReader {
return
row
;
}
private
Trip
e
l
<
Integer
,
String
,
String
>
nextResidual
(
final
Trip
e
l
<
Integer
,
String
,
String
>
tripel
)
{
Integer
varCount
=
tripel
.
v1
;
Tupel
<
String
,
String
>
tupel
=
nextResidual
(
Tupel
.
of
(
tripel
.
v2
,
tripel
.
v3
));
private
Tripl
e
<
Integer
,
String
,
String
>
nextResidual
(
final
Tripl
e
<
Integer
,
String
,
String
>
tripel
)
{
Integer
varCount
=
tripel
.
getLeft
()
;
Pair
<
String
,
String
>
tupel
=
nextResidual
(
Pair
.
of
(
tripel
.
getMiddle
(),
tripel
.
getRight
()
));
return
tupel
.
isPresent
()
?
Trip
e
l
.
of
(
varCount
+
1
,
tupel
.
v1
,
tupel
.
v2
)
:
Tripel
.
empty
(
);
return
tupel
.
getValue
()
!=
null
?
Tripl
e
.
of
(
varCount
+
1
,
tupel
.
getLeft
(),
tupel
.
getRight
())
:
Triple
.
of
(
null
,
null
,
null
);
}
private
Tupel
<
String
,
String
>
nextResidual
(
final
Tupel
<
String
,
String
>
tupel
)
{
if
(
!
tupel
.
isPresent
()
)
{
return
tupel
;
private
Pair
<
String
,
String
>
nextResidual
(
final
Pair
<
String
,
String
>
pair
)
{
if
(
pair
.
getValue
()
==
null
)
{
return
pair
;
}
String
residualFormat
=
tupel
.
v1
;
String
residualLine
=
tupel
.
v2
;
String
residualFormat
=
pair
.
getLeft
()
;
String
residualLine
=
pair
.
getRight
()
;
int
first
=
residualFormat
.
indexOf
(
'%'
);
residualFormat
=
residualFormat
.
substring
(
first
+
TYPE_PATTERN_LENGTH
);
first
=
residualFormat
.
indexOf
(
'%'
);
Tupel
<
String
,
String
>
result
Tupel
;
Pair
<
String
,
String
>
result
Pair
;
if
(
first
!=
-
1
)
{
String
seperator
=
residualFormat
.
substring
(
0
,
first
);
residualFormat
=
residualFormat
.
substring
(
residualFormat
.
indexOf
(
'%'
));
residualLine
=
residualLine
.
substring
(
residualLine
.
indexOf
(
seperator
)
+
seperator
.
length
());
result
Tupel
=
Tupel
.
of
(
residualFormat
,
residualLine
);
result
Pair
=
Pair
.
of
(
residualFormat
,
residualLine
);
}
else
{
result
Tupel
=
Tupel
.
empty
(
);
result
Pair
=
Pair
.
of
(
null
,
null
);
}
return
result
Tupel
;
return
result
Pair
;
}
/**
...
...
VadereUtils/src/org/vadere/util/potential/FloorDiscretizer.java
View file @
f97329c7
...
...
@@ -65,7 +65,7 @@ public class FloorDiscretizer {
/**
* Similar to
* {@link #setGrid
Distance
ValuesForShape(CellGrid, VShape,
PathFindingTag, PathFindingTag
)},
* {@link #setGridValuesForShape
Centered
(CellGrid, VShape,
CellState
)},
* but sets the values considering the CENTER of the cells, not the left lower corner.
*/
public
static
void
setGridValuesForShapeCentered
(
CellGrid
floorGrid
,
...
...
@@ -103,61 +103,6 @@ public class FloorDiscretizer {
}
}
/**
* Computes the distance to the given shape of all contained plus directly adjacent points.
* A point is considered adjacent if one of its eight neighbors is contained in the shape.
*
* @deprecated not used by any function but its test. The reason for this function was that the
* target shapes were not correctly rendered on the grid. They are now, in the
* FastMarching algorithm itself.
*/
public
static
void
setGridDistanceValuesForShape
(
CellGrid
floorGrid
,
VShape
elementShape
,
PathFindingTag
tagInside
,
PathFindingTag
tagOutside
)
{
// Axis aligned bounds of the given body.
Rectangle2D
bodyBounds
=
elementShape
.
getBounds2D
();
// Nearest points on the grid of the left lower and right upper corners
// of the bounds of the body. These represent the outer bounds of the
// grid points to write.
Point
pointLeftLower
,
pointRightUpper
;
double
eps
=
GeometryUtils
.
DOUBLE_EPS
;
// Compute nearest grid point of the lower left corner of bodyBounds.
pointLeftLower
=
floorGrid
.
getNearestPoint
(
bodyBounds
.
getMinX
()
-
eps
,
bodyBounds
.
getMinY
()
-
eps
);
// Compute nearest grid point of the right upper corner of bodyBounds.
pointRightUpper
=
floorGrid
.
getNearestPoint
(
bodyBounds
.
getMaxX
()
+
eps
,
bodyBounds
.
getMaxY
()
+
eps
);
// Run through all grid points of bounds and set its value if being
// covered by the bodies footprint.
for
(
int
x
=
pointLeftLower
.
x
-
1
;
x
<=
pointRightUpper
.
x
+
1
;
++
x
)
{
for
(
int
y
=
pointLeftLower
.
y
-
1
;
y
<=
pointRightUpper
.
y
+
1
;
++
y
)
{
// Convert the grid point to the bodies coordinate system and
// verify if lies within the bodies shape.
boolean
isCloseToShape
=
false
;
for
(
int
xx
=
x
-
1
;
xx
<=
x
+
1
;
xx
++)
{
for
(
int
yy
=
y
-
1
;
yy
<=
y
+
1
;
yy
++)
{
if
(
elementShape
.
contains
(
floorGrid
.
pointToCoord
(
xx
,
yy
)))
{
isCloseToShape
=
true
;
}
}
}
if
(
isCloseToShape
&&
floorGrid
.
isValidPoint
(
new
Point
(
x
,
y
)))
{
double
dist
=
elementShape
.
distance
(
new
VPoint
(
x
,
y
));
if
(
dist
<
eps
)
{
floorGrid
.
setValue
(
x
,
y
,
new
CellState
(
0.0
,
tagInside
));
}
else
{
floorGrid
.
setValue
(
x
,
y
,
new
CellState
(
dist
,
tagOutside
));
}
}
}
}
}
/**
* Returns the sampling points of the given grid which are covered by the
* footprint of the body.
...
...
VadereUtils/tests/org/vadere/util/potential/TestFloorDiscretizer.java
deleted
100644 → 0
View file @
50f9c592
package
org.vadere.util.potential
;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.vadere.util.geometry.shapes.VRectangle
;
import
org.vadere.util.potential.CellGrid
;
import
org.vadere.util.potential.CellState
;
import
org.vadere.util.potential.FloorDiscretizer
;
import
org.vadere.util.potential.PathFindingTag
;
public
class
TestFloorDiscretizer
{
private
VRectangle
shapeToDiscretize
;
private
double
gridWidth
=
2
;
private
double
gridHeight
=
2
;
private
double
gridResolution
=
1
;
private
CellGrid
cellGrid
;
/**
* @throws java.lang.Exception
*/
@Before
public
void
setUp
()
throws
Exception
{
cellGrid
=
new
CellGrid
(
gridWidth
,
gridHeight
,
gridResolution
,
new
CellState
(
0.0
,
PathFindingTag
.
Undefined
));
}
/**
* Test method for
* {@link org.vadere.util.potential.FloorDiscretizer#setGridDistanceValuesForShape(CellGrid, org.vadere.util.geometry.shapes.VShape, PathFindingTag)}.
*/
@Test
public
void
testSetGridDistanceValuesForShape_halfGrid
()
{
shapeToDiscretize
=
new
VRectangle
(
0
,
0
,
gridWidth
,
gridHeight
/
2
);
FloorDiscretizer
.
setGridDistanceValuesForShape
(
cellGrid
,
shapeToDiscretize
,
PathFindingTag
.
Target
,
PathFindingTag
.
Reachable
);
// test if all the values are set to zero even only half the grid was filled (i.e. the
// initial values are zero)
double
counter
=
0
;
for
(
int
y
=
0
;
y
<
cellGrid
.
numPointsY
;
y
++)
{
for
(
int
x
=
0
;
x
<
cellGrid
.
numPointsX
;
x
++)
{
counter
+=
cellGrid
.
getValue
(
x
,
y
).
potential
;
}
}
assertEquals
(
0
,
counter
,
1
e
-
8
);
// test if all states inside the shape to discretize are set to target
for
(
int
y
=
0
;
y
<
cellGrid
.
numPointsY
/
2
;
y
++)
{
for
(
int
x
=
0
;
x
<
cellGrid
.
numPointsX
;
x
++)
{
assertEquals
(
"y "
+
y
+
" and x "
+
x
+
" produced an error."
,
PathFindingTag
.
Target
,
cellGrid
.
getValue
(
x
,
y
).
tag
);
}
}
}
/**
* Test method for
* {@link org.vadere.util.potential.FloorDiscretizer#setGridDistanceValuesForShape(CellGrid, org.vadere.util.geometry.shapes.VShape, PathFindingTag)}.
* Tests that in case of using a shape larger than the grid, the algorithms still works as if
* the shape were equally large.
*/
@Test
public
void
testSetGridDistanceValuesForShape_halfGridHeightPlusEps
()
{
shapeToDiscretize
=
new
VRectangle
(
0
,
0
,
2.1
,
1
);
FloorDiscretizer
.
setGridDistanceValuesForShape
(
cellGrid
,
shapeToDiscretize
,
PathFindingTag
.
Target
,
PathFindingTag
.
Reachable
);
// test if all the values are set to zero even only half the grid was filled (i.e. the
// initial values are zero)
double
counter
=
0
;
for
(
int
y
=
0
;
y
<
cellGrid
.
numPointsY
;
y
++)
{
for
(
int
x
=
0
;
x
<
cellGrid
.
numPointsX
;
x
++)
{
counter
+=
cellGrid
.
getValue
(
x
,
y
).
potential
;
}
}
assertEquals
(
0
,
counter
,
1
e
-
8
);
}
/**
* Test method for
* {@link org.vadere.util.potential.FloorDiscretizer#setGridDistanceValuesForShape(CellGrid, org.vadere.util.geometry.shapes.VShape, PathFindingTag)}.
* Tests that in case of using a shape slightly overlapping certain cells, the distances are
* computed correctly.
*/
@Test
public
void
testSetGridDistanceValuesForShape_halfGridWidthPlusEps
()
{
shapeToDiscretize
=
new
VRectangle
(
0
,
0
,
2
,
1.1
);
FloorDiscretizer
.
setGridDistanceValuesForShape
(
cellGrid
,
shapeToDiscretize
,
PathFindingTag
.
Target
,
PathFindingTag
.
Reachable
);
// test if not all the values are set to zero even only half the grid was filled (i.e. the
// initial values are zero)
double
counter
=
0
;
int
reachableCounter
=
0
;
int
targetCounter
=
0
;
for
(
int
y
=
0
;
y
<
cellGrid
.
numPointsY
;
y
++)
{
for
(
int
x
=
0
;
x
<
cellGrid
.
numPointsX
;
x
++)
{
counter
+=
cellGrid
.
getValue
(
x
,
y
).
potential
;
if
(
cellGrid
.
getValue
(
x
,
y
).
tag
==
PathFindingTag
.
Reachable
)
{
reachableCounter
++;
}
if
(
cellGrid
.
getValue
(
x
,
y
).
tag
==
PathFindingTag
.
Target
)
{
targetCounter
++;
}
}
}
// compute the distances that should be computed by setGridDistanceValuesForShape:
double
distanceSum
=
cellGrid
.
getNumPointsY
()
*
(
Math
.
ceil
(
shapeToDiscretize
.
height
)
-
shapeToDiscretize
.
height
);
assertEquals
(
distanceSum
,
counter
,
1
e
-
8
);
assertEquals
(
cellGrid
.
getNumPointsY
(),
reachableCounter
);
assertEquals
(
cellGrid
.
getNumPointsY
()
*
(
cellGrid
.
getNumPointsX
()
+
1
)
/
2
,
targetCounter
);
}
}
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