Skip to content

Commit e24a576

Browse files
committed
Revert to not using subranges
CURA-12528 subranges is not working at all on our old Apple compiler, so just use the custom structures and ranges::partition.
1 parent 9e0e1c6 commit e24a576

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/unwrap.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <numeric>
88
#include <set>
99

10+
#include <range/v3/algorithm/partition.hpp>
1011
#include <range/v3/view/enumerate.hpp>
1112
#include <range/v3/view/map.hpp>
12-
#include <range/v3/view/subrange.hpp>
1313
#include <spdlog/spdlog.h>
1414

1515
#include "Face.h"
@@ -56,27 +56,36 @@ std::vector<Vector> calculateProjectionNormals(const std::vector<FaceData>& face
5656
return &face_data;
5757
});
5858

59+
using FaceDataIterator = std::vector<const FaceData*>::iterator;
60+
struct FaceDataRange
61+
{
62+
FaceDataIterator begin;
63+
FaceDataIterator end;
64+
};
65+
5966
// The unprocessed_faces is a sub-range of the faces list, that contains all the faces that have not been assigned to a group yet.
60-
auto unprocessed_faces = ranges::subrange(faces_to_process.begin(), faces_to_process.end());
67+
FaceDataRange unprocessed_faces = { .begin = faces_to_process.begin(), .end = faces_to_process.end() };
6168

6269
while (true)
6370
{
6471
// Get all the faces that belong to the group of the current projection normal,
65-
// by placing them at the end of the unprocessed faces
66-
auto current_faces_group = std::ranges::partition(
67-
unprocessed_faces,
72+
// by placing them at the beginning of the unprocessed faces
73+
FaceDataRange current_faces_group{ .begin = unprocessed_faces.begin };
74+
current_faces_group.end = ranges::partition(
75+
unprocessed_faces.begin,
76+
unprocessed_faces.end,
6877
[&project_normal, &group_angle_limit_half_cos](const FaceData* face_data)
6978
{
70-
return face_data->normal.dot(*project_normal) <= group_angle_limit_half_cos;
79+
return face_data->normal.dot(*project_normal) > group_angle_limit_half_cos;
7180
});
7281

7382
// All the faces placed to the current group are now no more in the unprocessed faces
74-
unprocessed_faces = ranges::subrange(unprocessed_faces.begin(), current_faces_group.begin());
83+
unprocessed_faces.begin = current_faces_group.end;
7584

7685
// Sum all the normals of the current faces group to get the average direction
7786
Vector summed_normals = std::accumulate(
78-
current_faces_group.begin(),
79-
current_faces_group.end(),
87+
current_faces_group.begin,
88+
current_faces_group.end,
8089
Vector(),
8190
[](const Vector& normal, const FaceData* face_data)
8291
{
@@ -89,9 +98,9 @@ std::vector<Vector> calculateProjectionNormals(const std::vector<FaceData>& face
8998

9099
// For the next iteration, try to find the most different remaining normal from all generated normals
91100
float best_outlier_angle = std::numeric_limits<float>::max();
92-
auto best_outlier_face = faces_to_process.end();
101+
FaceDataIterator best_outlier_face = faces_to_process.end();
93102

94-
for (auto iterator = unprocessed_faces.begin(); iterator != unprocessed_faces.end(); ++iterator)
103+
for (auto iterator = unprocessed_faces.begin; iterator != unprocessed_faces.end; ++iterator)
95104
{
96105
float face_best_angle = std::numeric_limits<float>::lowest();
97106
for (const Vector& projection_normal : projection_normals)
@@ -112,9 +121,8 @@ std::vector<Vector> calculateProjectionNormals(const std::vector<FaceData>& face
112121
project_normal = &(*best_outlier_face)->normal;
113122

114123
// Remove the faces from the unprocessed faces
115-
const auto last_position = std::prev(unprocessed_faces.end());
116-
std::iter_swap(best_outlier_face, last_position);
117-
unprocessed_faces = ranges::subrange(unprocessed_faces.begin(), last_position);
124+
std::iter_swap(best_outlier_face, unprocessed_faces.begin);
125+
++unprocessed_faces.begin;
118126
}
119127
else if (! projection_normals.empty())
120128
{

0 commit comments

Comments
 (0)