Skip to content

Commit

Permalink
OcdFileImport: Process coords with std::for_each
Browse files Browse the repository at this point in the history
... and use iterators for input and output.

Preparation for improved state handling and bug fixes:
No tight coupling of input position and output position.
No observable change of behavior intented.
  • Loading branch information
dg0yt committed Aug 4, 2024
1 parent f33b1ef commit 164a7e2
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/fileformats/ocd_file_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2132,20 +2132,20 @@ Object* OcdFileImport::importRectangleObject(const Ocd::OcdPoint32* ocd_points,
void OcdFileImport::fillPathCoords(OcdImportedPathObject *object, bool is_area, quint32 num_points, const Ocd::OcdPoint32* ocd_points) const
{
object->coords.resize(num_points);

auto const out_first = object->coords.begin();
auto out_coord = out_first;
int ignore_flag_hole = 2;
for (auto i = 0u; i < num_points; i++)
{
const auto& ocd_point = ocd_points[i];
object->coords[i] = convertOcdPoint(ocd_point);
std::for_each(ocd_points, ocd_points + num_points, [&](auto& ocd_point) {
*out_coord = convertOcdPoint(ocd_point);
if ((ocd_point.y & Ocd::OcdPoint32::FlagDash) || (ocd_point.y & Ocd::OcdPoint32::FlagCorner))
{
object->coords[i].setDashPoint(true);
out_coord->setDashPoint(true);
}

if (ocd_point.x & Ocd::OcdPoint32::FlagCtl1 && i > 0)
if ((ocd_point.x & Ocd::OcdPoint32::FlagCtl1) && out_coord != out_first)
{
// CurveStart needs to be applied to the start point
object->coords[i-1].setCurveStart(true);
(out_coord-1)->setCurveStart(true);
ignore_flag_hole = 2; // 2nd control point + end point
}
else if (is_area)
Expand All @@ -2156,12 +2156,13 @@ void OcdFileImport::fillPathCoords(OcdImportedPathObject *object, bool is_area,
}
else if (ocd_point.y & Ocd::OcdPoint32::FlagHole)
{
Q_ASSERT(i >= 2); // implied by initialization of ignore_hole_points
Q_ASSERT(std::distance(out_first, out_coord) >= 2); // implied by initialization of ignore_flag_hole
// HolePoint needs to be applied to the last point of a part
object->coords[i-1].setHolePoint(true);
(out_coord-1)->setHolePoint(true);
}
}
};
++out_coord;
});

// For path objects, create closed parts where the position of the last point is equal to that of the first point
if (object->getType() == Object::Path)
Expand Down

0 comments on commit 164a7e2

Please sign in to comment.