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
da89eafa
Commit
da89eafa
authored
Nov 30, 2020
by
Benedikt Kleinmeier
Browse files
Merge branch 'master' into psychology
parents
4a2ef232
47dae5ed
Pipeline
#373179
passed with stages
in 128 minutes and 56 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereUtils/src/org/vadere/util/geometry/shapes/VRectangle.java
View file @
da89eafa
...
...
@@ -43,6 +43,18 @@ public class VRectangle extends Rectangle2D.Double implements VShape {
this
(
rectangle
.
x
,
rectangle
.
y
,
rectangle
.
width
,
rectangle
.
height
);
}
@Override
public
boolean
contains
(
VCircle
otherShape
)
{
double
centerX
=
otherShape
.
getCentroid
().
x
;
double
centerY
=
otherShape
.
getCentroid
().
y
;
double
radius
=
otherShape
.
getRadius
();
boolean
circleFitsIntoHorizontally
=
(
centerX
>
(
this
.
x
+
radius
))
&&
((
this
.
x
+
this
.
width
)
>
(
centerX
+
radius
));
boolean
circleFitsIntoVertically
=
(
centerY
>
(
this
.
y
+
radius
))
&&
((
this
.
y
+
this
.
height
)
>
(
centerY
+
radius
));
return
circleFitsIntoHorizontally
&&
circleFitsIntoVertically
;
}
@Override
public
double
distance
(
IPoint
point
)
{
VPoint
closestPoint
=
closestPoint
(
point
);
...
...
VadereUtils/src/org/vadere/util/geometry/shapes/VShape.java
View file @
da89eafa
...
...
@@ -76,7 +76,12 @@ public interface VShape extends Shape, Cloneable, Geometry {
return
thisShape
.
isEmpty
();
}
// numerical not stable for comparision with VCircle.
// use contains(VCircle otherShape)
default
boolean
containsShape
(
VShape
otherShape
)
{
if
(
otherShape
instanceof
VCircle
){
return
this
.
contains
((
VCircle
)
otherShape
);
}
Area
thisArea
=
new
Area
(
this
);
Area
otherArea
=
new
Area
(
otherShape
);
thisArea
.
intersect
(
otherArea
);
...
...
@@ -84,6 +89,15 @@ public interface VShape extends Shape, Cloneable, Geometry {
}
// todo: remove default implementation and implement specific performance optimized and numerical stable versions.
default
boolean
contains
(
VCircle
otherShape
){
// override in specific shapes for more performance optimized implementations
Area
thisArea
=
new
Area
(
this
);
Area
otherArea
=
new
Area
(
otherShape
);
thisArea
.
intersect
(
otherArea
);
return
thisArea
.
equals
(
otherArea
);
}
/**
* Returns a list of points (p1, p2, ..., pn) such that the line (p1,p2) is part of the boundary
* of the approximation of this shape. p1 != pn i.e. it is not a closed path.
...
...
VadereUtils/tests/org/vadere/util/geometry/shapes/VShapeTest.java
View file @
da89eafa
package
org.vadere.util.geometry.shapes
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
java.awt.geom.Path2D
;
import
static
org
.
junit
.
Assert
.*;
public
class
VShapeTest
{
...
...
@@ -16,6 +15,66 @@ public class VShapeTest {
assertTrue
(
a
.
intersects
(
b
));
}
@Test
(
timeout
=
1000
)
//ms
public
void
loopAtEdgeCase1
(){
VRectangle
rec
=
new
VRectangle
(
0.0
,
114.0
,
44.0
,
5.0
);
VCircle
circle
=
new
VCircle
(
new
VPoint
(
0.005096532915902063
,
118.69364126200188
),
0.2
);
boolean
contains
=
rec
.
containsShape
(
circle
);
assertFalse
(
contains
);
}
@Test
(
timeout
=
1000
)
//ms
public
void
loopAtEdgeCase2
(){
VRectangle
rec
=
new
VRectangle
(
0.0
,
114.0
,
44.0
,
5.0
);
VCircle
circle
=
new
VCircle
(
new
VPoint
(
0.008096532915902063
,
118.69364126200188
),
0.2
);
boolean
contains
=
rec
.
containsShape
(
circle
);
assertFalse
(
contains
);
}
@Ignore
@Test
(
timeout
=
1000
)
//ms
/**
* Error at magic number. With given Shapes in this test the AWT Area equals comparision
* will start loop forever. Small changes (0.005 --> 0.008) will fix this.
* Problem occurs if the contains check involves circles because they get transformed
* to awt Paths for the comparision (bezier curve) which is probably the reason.
* Current fix introduces a new contains(VCircle otherShape) overload in which
* specialized check should take place. Currently only VRectangle implement this.
* Other shapes will still use the numerical unstable version.
*/
public
void
loopAtEdgeCase_asVPolygon1
(){
VRectangle
rec
=
new
VRectangle
(
0.0
,
114.0
,
44.0
,
5.0
);
VCircle
circle
=
new
VCircle
(
new
VPoint
(
0.005096532915902063
,
118.69364126200188
),
0.2
);
VPolygon
poly
=
new
VPolygon
(
rec
);
boolean
contains
=
poly
.
contains
(
circle
);
assertFalse
(
contains
);
}
@Test
(
timeout
=
1000
)
public
void
loopAtEdgeCase_asVPolygon2
(){
VRectangle
rec
=
new
VRectangle
(
0.0
,
114.0
,
44.0
,
5.0
);
VCircle
circle
=
new
VCircle
(
new
VPoint
(
0.008096532915902063
,
118.69364126200188
),
0.2
);
VPolygon
poly
=
new
VPolygon
(
rec
);
boolean
contains
=
poly
.
contains
(
circle
);
assertFalse
(
contains
);
}
@Test
(
timeout
=
1000
)
//ms
public
void
loopAtEdgeCase_asVRectangle
(){
VRectangle
rec
=
new
VRectangle
(
0.0
,
114.0
,
44.0
,
5.0
);
VCircle
circle
=
new
VCircle
(
new
VPoint
(
0.005096532915902063
,
118.69364126200188
),
0.2
);
boolean
contains
=
rec
.
contains
(
circle
);
assertFalse
(
contains
);
}
@Test
public
void
containsShapeFalse
(){
VRectangle
rec
=
new
VRectangle
(
0.0
,
114.0
,
44.0
,
5.0
);
VCircle
circle
=
new
VCircle
(
new
VPoint
(
300.0
,
300.0
),
0.2
);
boolean
contains
=
rec
.
containsShape
(
circle
);
assertFalse
(
contains
);
}
@Test
public
void
testIntersectShapesReturnsFalseWithNonOverlappingShapes
()
{
VShape
a
=
new
VRectangle
(
0
,
0
,
1
,
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