Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
unionized-triangles-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Brandon Lai-Cheong
unionized-triangles-2
Commits
81167391
Commit
81167391
authored
4 months ago
by
Brandon Lai-Cheong
Browse files
Options
Downloads
Patches
Plain Diff
fixed z interpolation
parent
526671eb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/utilities/interpolate_z.cpp
+9
-4
9 additions, 4 deletions
src/utilities/interpolate_z.cpp
src/utilities/intersections.cpp
+2
-3
2 additions, 3 deletions
src/utilities/intersections.cpp
tests/unit_tests/interpolate_z_tests.cpp
+22
-7
22 additions, 7 deletions
tests/unit_tests/interpolate_z_tests.cpp
with
33 additions
and
14 deletions
src/utilities/interpolate_z.cpp
+
9
−
4
View file @
81167391
...
@@ -11,10 +11,15 @@ float dist2D(const Point &p) {
...
@@ -11,10 +11,15 @@ float dist2D(const Point &p) {
float
interpolateZ
(
const
Edge
&
e
,
const
Point
&
p
)
{
float
interpolateZ
(
const
Edge
&
e
,
const
Point
&
p
)
{
const
float
p1Dist
=
dist2D
(
e
.
p1
);
const
float
p1Dist
=
dist2D
(
e
.
p1
);
const
float
p2Dist
=
dist2D
(
e
.
p2
);
const
float
p2Dist
=
dist2D
(
e
.
p2
);
const
float
pDist
=
dist2D
(
p
);
const
float
b
=
(
p2Dist
*
e
.
p1
.
z
-
p1Dist
*
e
.
p2
.
z
)
/
(
p2Dist
-
p1Dist
);
if
(
p1Dist
-
p2Dist
==
0
)
{
return
e
.
p1
.
z
;
const
float
m
=
(
e
.
p2
.
z
-
b
)
/
p2Dist
;
}
return
m
*
dist2D
(
p
)
+
b
;
const
float
m
=
(
e
.
p1
.
z
-
e
.
p2
.
z
)
/
(
p1Dist
-
p2Dist
);
const
float
b
=
e
.
p1
.
z
-
p1Dist
*
m
;
return
m
*
pDist
+
b
;
}
}
This diff is collapsed.
Click to expand it.
src/utilities/intersections.cpp
+
2
−
3
View file @
81167391
...
@@ -62,6 +62,8 @@ std::optional<Point> intersectionFirstSide(const Edge &e1, const Edge &e2) {
...
@@ -62,6 +62,8 @@ std::optional<Point> intersectionFirstSide(const Edge &e1, const Edge &e2) {
auto
candPoint
=
intersection
(
e1
,
e2
);
auto
candPoint
=
intersection
(
e1
,
e2
);
if
(
candPoint
.
has_value
()
&&
withinEdge
(
e2
,
candPoint
.
value
()))
{
if
(
candPoint
.
has_value
()
&&
withinEdge
(
e2
,
candPoint
.
value
()))
{
float
z
=
interpolateZ
(
e2
,
candPoint
.
value
());
candPoint
.
value
().
z
=
z
;
return
candPoint
;
return
candPoint
;
}
}
return
{};
return
{};
...
@@ -172,9 +174,6 @@ std::vector<Point> intersections(const std::vector<Point> &points, const Edge &l
...
@@ -172,9 +174,6 @@ std::vector<Point> intersections(const std::vector<Point> &points, const Edge &l
auto
cand
=
intersectionFirstSide
(
line
,
es
[
i
]);
auto
cand
=
intersectionFirstSide
(
line
,
es
[
i
]);
if
(
cand
.
has_value
())
if
(
cand
.
has_value
())
{
{
// add depth information
float
z
=
interpolateZ
(
es
[
i
],
cand
.
value
());
cand
.
value
().
z
=
z
;
result
.
push_back
(
cand
.
value
());
result
.
push_back
(
cand
.
value
());
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/unit_tests/interpolate_z_tests.cpp
+
22
−
7
View file @
81167391
#include
<gtest/gtest.h>
#include
<gtest/gtest.h>
#include
<interpolate_z.h>
#include
<interpolate_z.h>
#include
<point.h>
#include
<point.h>
#include
<edge.h>
struct
InterpolateParams
{
struct
InterpolateParams
{
std
::
vector
<
Point
>
points
;
Edge
e
;
Point
point
;
float
expected_z
;
float
expected_z
;
};
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Edge
&
e
)
{
return
out
<<
e
.
p1
<<
", "
<<
e
.
p2
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
InterpolateParams
&
p
)
{
return
out
<<
"Edge: "
<<
p
.
e
<<
"Point: "
<<
p
.
point
;
}
class
InstantiateInterpolateZTests
:
public
testing
::
TestWithParam
<
InterpolateParams
>
{
class
InstantiateInterpolateZTests
:
public
testing
::
TestWithParam
<
InterpolateParams
>
{
};
};
TEST_P
(
InstantiateInterpolateZTests
,
Interpolate
)
{
TEST_P
(
InstantiateInterpolateZTests
,
Interpolate
)
{
std
::
vector
<
Point
>
points
=
GetParam
().
points
;
Edge
e
=
GetParam
().
e
;
Point
point
=
GetParam
().
point
;
float
z
=
interpolateZ
(
point
s
,
{
0
,
1
,
0
}
);
float
z
=
interpolateZ
(
e
,
point
);
EXPECT_EQ
(
z
,
GetParam
().
expected_z
);
EXPECT_EQ
(
z
,
GetParam
().
expected_z
);
}
}
INSTANTIATE_TEST_SUITE_P
(
Interpolation
,
InstantiateInterpolateZTests
,
testing
::
Values
(
INSTANTIATE_TEST_SUITE_P
(
Interpolation
,
InstantiateInterpolateZTests
,
testing
::
Values
(
InterpolateParams
{
InterpolateParams
{{{
1
,
1
,
3
},
{
2
,
2
,
3
}},
{
1.5
,
1.5
},
3
},
{{
1
,
1
,
3
},
{
2
,
2
,
3
},
{
4
,
5
,
3
}}
InterpolateParams
{{{
1
,
1
,
5
},
{
1
,
1
,
5
}},
{
1
,
1
},
5
},
,
3
},
InterpolateParams
{{{
1
,
1
,
10
},
{
2
,
3
,
15
}},
{
2
,
3
},
15
},
InterpolateParams
{{{
1
,
1
,
5
},
{
1
,
1
,
5
},
{
1
,
1
,
5
}},
5
}));
InterpolateParams
{{{
1
,
1
,
10
},
{
2
,
2
,
0
}},
{
1
,
1
},
10
},
\ No newline at end of file
InterpolateParams
{{{
1
,
1
,
10
},
{
2
,
2
,
0
}},
{
2
,
2
},
0
},
InterpolateParams
{{{
5
,
3
,
3
},
{
2.5
,
6
,
3
}},
{
0.540541
,
3.64865
},
3
}
));
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