Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Rocs
Commits
f5a3f7f8
Commit
f5a3f7f8
authored
Jul 24, 2020
by
Dilson Guimarães
Committed by
Caio Tonetti
Nov 20, 2020
Browse files
Fixed edge crossing test in the quality benchmark.
parent
497c98df
Changes
2
Show whitespace changes
Inline
Side-by-side
libgraphtheory/modifiers/autotests/layoutevaluator.cpp
View file @
f5a3f7f8
...
...
@@ -2,6 +2,8 @@
#include
<QLineF>
#include
<QVector2D>
#include
<iostream>
#include
<iomanip>
void
LayoutEvaluator
::
showMetric
(
const
MetricSummarizer
&
metric
,
std
::
ostream
&
outputStream
)
const
{
...
...
@@ -10,6 +12,41 @@ void LayoutEvaluator::showMetric(const MetricSummarizer& metric, std::ostream& o
outputStream
<<
"
\t
average: "
<<
metric
.
average
()
<<
std
::
endl
;
}
QPointF
LayoutEvaluator
::
projectOntoSegment
(
const
QLineF
&
segment
,
const
QPointF
&
point
)
const
{
const
QPointF
p1p2
=
segment
.
p1
()
-
segment
.
p2
();
const
QPointF
pointp2
=
point
-
segment
.
p2
();
const
qreal
denominator
=
QPointF
::
dotProduct
(
p1p2
,
p1p2
);
const
qreal
numerator
=
QPointF
::
dotProduct
(
p1p2
,
pointp2
);
const
qreal
lambda
=
qMin
(
1.
,
qMax
(
0.
,
numerator
/
denominator
));
return
segment
.
p1
()
*
lambda
+
segment
.
p2
()
*
(
1.
-
lambda
);
}
qreal
LayoutEvaluator
::
squaredDistance
(
const
QPointF
&
pointA
,
const
QPointF
&
pointB
)
const
{
return
QPointF
::
dotProduct
(
pointA
-
pointB
,
pointA
-
pointB
);
}
bool
LayoutEvaluator
::
doSegmentsIntersect
(
const
QLineF
&
segmentA
,
const
QLineF
&
segmentB
)
const
{
constexpr
qreal
EPS
=
1.e-1
;
QPointF
point
;
if
(
segmentA
.
intersects
(
segmentB
,
&
point
)
!=
QLineF
::
BoundedIntersection
)
{
return
false
;
}
if
(
squaredDistance
(
point
,
projectOntoSegment
(
segmentA
,
point
))
>
EPS
)
{
return
false
;
}
if
(
squaredDistance
(
point
,
projectOntoSegment
(
segmentB
,
point
))
>
EPS
)
{
return
false
;
}
return
true
;
}
bool
LayoutEvaluator
::
crosses
(
const
EdgePtr
a
,
const
EdgePtr
b
)
const
{
if
(
a
->
from
()
==
b
->
from
()
or
a
->
from
()
==
b
->
to
()
or
...
...
@@ -18,11 +55,15 @@ bool LayoutEvaluator::crosses(const EdgePtr a, const EdgePtr b) const
return
false
;
}
QLineF
segmentA
(
a
->
from
()
->
x
(),
a
->
from
()
->
y
(),
a
->
to
()
->
x
(),
a
->
to
()
->
y
());
QLineF
segmentB
(
b
->
from
()
->
x
(),
b
->
from
()
->
y
(),
b
->
to
()
->
x
(),
b
->
to
()
->
y
());
QPointF
aFrom
(
a
->
from
()
->
x
(),
a
->
from
()
->
y
());
QPointF
aTo
(
a
->
to
()
->
x
(),
a
->
to
()
->
y
());
QPointF
bFrom
(
b
->
from
()
->
x
(),
b
->
from
()
->
y
());
QPointF
bTo
(
b
->
to
()
->
x
(),
b
->
to
()
->
y
());
QPointF
point
;
return
segmentA
.
intersects
(
segmentB
,
&
point
)
==
QLineF
::
BoundedIntersection
;
QLineF
segmentA
(
aFrom
,
aTo
);
QLineF
segmentB
(
bFrom
,
bTo
);
return
doSegmentsIntersect
(
segmentA
,
segmentB
);
}
int
LayoutEvaluator
::
calculateNumberOfEdgeCrosses
(
GraphDocumentPtr
document
)
...
...
libgraphtheory/modifiers/autotests/layoutevaluator.h
View file @
f5a3f7f8
...
...
@@ -54,6 +54,9 @@ private:
bool
intersects
(
const
NodePtr
a
,
const
NodePtr
b
)
const
;
int
calculateNumberOfNodeIntersections
(
GraphDocumentPtr
document
);
int
calculateNumberOfNodesWithIntersections
(
GraphDocumentPtr
document
);
QPointF
projectOntoSegment
(
const
QLineF
&
segment
,
const
QPointF
&
point
)
const
;
qreal
squaredDistance
(
const
QPointF
&
pointA
,
const
QPointF
&
pointB
)
const
;
bool
doSegmentsIntersect
(
const
QLineF
&
segmentA
,
const
QLineF
&
segmentB
)
const
;
public:
/*
...
...
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