Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaofan Chen
ogs
Commits
c422def2
Commit
c422def2
authored
9 years ago
by
Tom Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[T/GL] Test line segment intersecting algorithm (2d).
parent
0cbd4086
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/GeoLib/TestLineSegmentIntersect2d.cpp
+137
-0
137 additions, 0 deletions
Tests/GeoLib/TestLineSegmentIntersect2d.cpp
with
137 additions
and
0 deletions
Tests/GeoLib/TestLineSegmentIntersect2d.cpp
0 → 100644
+
137
−
0
View file @
c422def2
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
#include
"gtest/gtest.h"
#include
<array>
#include
<ctime>
#include
<functional>
#include
<memory>
#include
<random>
#include
"Tests/GeoLib/AutoCheckGenerators.h"
#include
"MathLib/Point3d.h"
#include
"GeoLib/AnalyticalGeometry.h"
namespace
ac
=
autocheck
;
class
LineSegmentIntersect2dTest
:
public
testing
::
Test
{
public:
using
PointGenerator
=
ac
::
RandomCirclePointGeneratorXY
<
ac
::
generator
<
double
>>
;
using
SymmSegmentGenerator
=
ac
::
SymmSegmentGeneratorXY
<
PointGenerator
>
;
using
PairSegmentGenerator
=
ac
::
PairSegmentGeneratorXY
<
SymmSegmentGenerator
>
;
PointGenerator
point_generator1
=
PointGenerator
(
MathLib
::
Point3d
(
std
::
array
<
double
,
3
>
{{
0.0
,
0.0
,
0.0
}}),
1.0
);
SymmSegmentGenerator
segment_generator1
=
SymmSegmentGenerator
{
point_generator1
,
std
::
bind
(
ac
::
reflect
,
point_generator1
.
center
,
std
::
placeholders
::
_1
)};
PointGenerator
point_generator2
=
PointGenerator
(
MathLib
::
Point3d
(
std
::
array
<
double
,
3
>
{{
2.0
,
0.0
,
0.0
}}),
1.0
);
SymmSegmentGenerator
segment_generator2
=
SymmSegmentGenerator
{
point_generator2
,
std
::
bind
(
ac
::
reflect
,
point_generator2
.
center
,
std
::
placeholders
::
_1
)};
MathLib
::
Vector3
const
translation_vector1
=
{
2
,
2
,
0
};
PairSegmentGenerator
pair_segment_generator1
=
PairSegmentGenerator
{
segment_generator1
,
std
::
bind
(
ac
::
translate
,
translation_vector1
,
std
::
placeholders
::
_1
)};
MathLib
::
Vector3
const
translation_vector2
=
{
0
,
0
,
0
};
PairSegmentGenerator
pair_segment_generator2
=
PairSegmentGenerator
{
segment_generator1
,
std
::
bind
(
ac
::
translate
,
translation_vector2
,
std
::
placeholders
::
_1
)};
ac
::
gtest_reporter
gtest_reporter
;
};
// Test the intersection of intersecting line segments. Line segments are chords
// of the same circle that both contains the center of the circle. As a
// consequence the center of the circle is the intersection point.
TEST_F
(
LineSegmentIntersect2dTest
,
RandomSegmentOrientationIntersecting
)
{
auto
intersect
=
[](
GeoLib
::
LineSegment
const
&
s0
,
GeoLib
::
LineSegment
const
&
s1
)
{
auto
ipnts
=
GeoLib
::
lineSegmentIntersect2d
(
s0
.
a
,
s0
.
b
,
s1
.
a
,
s1
.
b
);
if
(
ipnts
.
size
()
==
1
)
{
MathLib
::
Point3d
const
center
{
std
::
array
<
double
,
3
>
{
{(
s0
.
a
[
0
]
+
s0
.
b
[
0
])
/
2
,
(
s0
.
a
[
1
]
+
s0
.
b
[
1
])
/
2
,
0.0
}}};
const
double
sqr_dist
(
MathLib
::
sqrDist
(
ipnts
[
0
],
center
));
if
(
sqr_dist
<
std
::
numeric_limits
<
double
>::
epsilon
())
return
true
;
else
return
false
;
}
return
ipnts
.
size
()
==
2
;
};
ac
::
check
<
GeoLib
::
LineSegment
,
GeoLib
::
LineSegment
>
(
intersect
,
1000
,
ac
::
make_arbitrary
(
segment_generator1
,
segment_generator1
),
gtest_reporter
);
}
// Test the intersection of non-intersecting line segments. Line segments are
// chords of non-intersecting circles.
TEST_F
(
LineSegmentIntersect2dTest
,
RandomSegmentOrientationNonIntersecting
)
{
auto
intersect
=
[](
GeoLib
::
LineSegment
const
&
s0
,
GeoLib
::
LineSegment
const
&
s1
)
{
auto
ipnts
=
GeoLib
::
lineSegmentIntersect2d
(
s0
.
a
,
s0
.
b
,
s1
.
a
,
s1
.
b
);
return
ipnts
.
empty
();
};
// generate non-intersecting segments
ac
::
check
<
GeoLib
::
LineSegment
,
GeoLib
::
LineSegment
>
(
intersect
,
1000
,
ac
::
make_arbitrary
(
segment_generator1
,
segment_generator2
),
gtest_reporter
);
}
// Test the intersection of non-intersecting, parallel line segments. The second
// line segment is created by translating the first line segment.
TEST_F
(
LineSegmentIntersect2dTest
,
ParallelNonIntersectingSegmentOrientation
)
{
auto
intersect
=
[](
std
::
pair
<
GeoLib
::
LineSegment
const
&
,
GeoLib
::
LineSegment
const
&>
const
&
segment_pair
)
{
auto
ipnts
=
GeoLib
::
lineSegmentIntersect2d
(
segment_pair
.
first
.
a
,
segment_pair
.
first
.
b
,
segment_pair
.
second
.
a
,
segment_pair
.
second
.
b
);
return
ipnts
.
empty
();
};
// generate non-intersecting segments
ac
::
check
<
std
::
pair
<
GeoLib
::
LineSegment
,
GeoLib
::
LineSegment
>>
(
intersect
,
1000
,
ac
::
make_arbitrary
(
pair_segment_generator1
),
gtest_reporter
);
}
// Test the intersection of parallel, interfering line segments.
TEST_F
(
LineSegmentIntersect2dTest
,
ParallelIntersectingSegmentOrientation
)
{
auto
intersect
=
[](
std
::
pair
<
GeoLib
::
LineSegment
const
&
,
GeoLib
::
LineSegment
const
&>
const
&
segment_pair
)
{
auto
ipnts
=
GeoLib
::
lineSegmentIntersect2d
(
segment_pair
.
first
.
a
,
segment_pair
.
first
.
b
,
segment_pair
.
second
.
a
,
segment_pair
.
second
.
b
);
return
ipnts
.
size
()
==
2
;
};
// generate non-intersecting segments
ac
::
check
<
std
::
pair
<
GeoLib
::
LineSegment
,
GeoLib
::
LineSegment
>>
(
intersect
,
1000
,
ac
::
make_arbitrary
(
pair_segment_generator2
),
gtest_reporter
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment