Skip to content

Commit 2b3c6eb

Browse files
authored
Merge pull request #3 from Ultimaker/CURA-12766_fix-preview-projection
CURA-12766 fix preview projection
2 parents c2984f3 + 32628f6 commit 2b3c6eb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/project.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Triangle2F projectToViewport(const Triangle3F& triangle, const Matrix44F& matrix
5252
projectToViewport(triangle.p3(), matrix, is_camera_perspective, viewport_width, viewport_height) };
5353
}
5454

55-
std::optional<std::vector<Point3F>> getBarycentricCoordinates(const Polygon& polygon, const Triangle2F& triangle)
55+
std::vector<Point3F> getBarycentricCoordinates(const Polygon& polygon, const Triangle2F& triangle)
5656
{
5757
// Calculate base vectors
5858
const Vector2F v0(triangle.p1, triangle.p2);
@@ -67,10 +67,10 @@ std::optional<std::vector<Point3F>> getBarycentricCoordinates(const Polygon& pol
6767
const double denom = d00 * d11 - d01 * d01;
6868

6969
// Check if triangle is degenerate
70-
constexpr double epsilon_triangle_cross_products = 0.000001;
70+
constexpr double epsilon_triangle_cross_products = 0.001;
7171
if (std::abs(denom) < epsilon_triangle_cross_products)
7272
{
73-
return std::nullopt;
73+
return {};
7474
}
7575

7676
std::vector<Point3F> result;
@@ -207,15 +207,15 @@ std::vector<Polygon> doProject(
207207
const Triangle2F face_uv = getFaceUv(mesh_uv, face);
208208
for (const Polygon& uv_area : uv_areas)
209209
{
210-
const std::optional<std::vector<Point3F>> projected_stroke_polygon = getBarycentricCoordinates(uv_area, projected_face_triangle);
211-
if (! projected_stroke_polygon.has_value())
210+
const std::vector<Point3F> projected_stroke_polygon = getBarycentricCoordinates(uv_area, projected_face_triangle);
211+
if (projected_stroke_polygon.empty())
212212
{
213213
continue;
214214
}
215215

216216
Polygon result_polygon;
217-
result_polygon.reserve(projected_stroke_polygon.value().size());
218-
for (const Point3F& point : projected_stroke_polygon.value())
217+
result_polygon.reserve(projected_stroke_polygon.size());
218+
for (const Point3F& point : projected_stroke_polygon)
219219
{
220220
result_polygon.push_back(getTextureCoordinates(point, face_uv, texture_width, texture_height));
221221
}

0 commit comments

Comments
 (0)