Refactoring. Use std::optional.
This commit is contained in:
parent
8cd3bfb803
commit
15750a749c
|
@ -1194,7 +1194,7 @@ auto VLayoutPiece::LayoutEdge(int i) const -> QLineF
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
auto VLayoutPiece::LayoutEdgeByPoint(const QPointF &p1) const -> int
|
||||
auto VLayoutPiece::LayoutEdgeByPoint(const QPointF &p1) const -> EdgeIndex
|
||||
{
|
||||
return EdgeByPoint(d->m_layoutAllowance, p1);
|
||||
}
|
||||
|
@ -1790,20 +1790,19 @@ auto VLayoutPiece::Edge(const QVector<QPointF> &path, int i) const -> QLineF
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
// NOTE: Once C++17 is made mandatory, this method can further be refactored with std::optional<int>
|
||||
auto VLayoutPiece::EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const -> int
|
||||
auto VLayoutPiece::EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const -> EdgeIndex
|
||||
{
|
||||
if (p1.isNull() || path.count() < 3)
|
||||
{
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto points = Map(path);
|
||||
const QVector<QPointF> points = Map(path);
|
||||
const auto *const posIter = std::find_if(points.cbegin(), points.cend(),
|
||||
[&p1](const QPointF &point){ return VFuzzyComparePoints(point, p1); });
|
||||
if (posIter != points.cend())
|
||||
{
|
||||
return static_cast<int>(posIter - points.cbegin() + 1);
|
||||
}
|
||||
return 0; // Did not find edge
|
||||
return {}; // Did not find edge
|
||||
}
|
||||
|
|
|
@ -46,6 +46,14 @@
|
|||
#include "../vmisc/typedef.h"
|
||||
#include "../vpatterndb/floatItemData/floatitemdef.h"
|
||||
|
||||
#if __cplusplus >= 201703L // C++17
|
||||
#include <optional>
|
||||
using EdgeIndex = std::optional<int>;
|
||||
#else
|
||||
#include "../vmisc/bpstd/optional.hpp"
|
||||
using EdgeIndex = bpstd::optional<int>;
|
||||
#endif
|
||||
|
||||
class VLayoutPieceData;
|
||||
class VLayoutPiecePath;
|
||||
class QGraphicsItem;
|
||||
|
@ -158,7 +166,7 @@ public:
|
|||
auto LayoutEdgesCount() const -> int;
|
||||
|
||||
auto LayoutEdge(int i) const -> QLineF;
|
||||
auto LayoutEdgeByPoint(const QPointF &p1) const -> int;
|
||||
auto LayoutEdgeByPoint(const QPointF &p1) const -> EdgeIndex;
|
||||
|
||||
auto MappedDetailBoundingRect() const -> QRectF;
|
||||
auto DetailBoundingRect() const -> QRectF;
|
||||
|
@ -221,7 +229,7 @@ private:
|
|||
auto Map(QVector<T> points) const -> QVector<T>;
|
||||
|
||||
auto Edge(const QVector<QPointF> &path, int i) const -> QLineF;
|
||||
auto EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const -> int;
|
||||
auto EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const -> EdgeIndex;
|
||||
};
|
||||
|
||||
QT_WARNING_POP
|
||||
|
|
|
@ -356,13 +356,13 @@ auto VPosition::CheckCombineEdges(VLayoutPiece &detail, int j, int &dEdge) -> bo
|
|||
# endif
|
||||
#endif
|
||||
|
||||
dEdge = detail.LayoutEdgeByPoint(globalEdge.p2());
|
||||
|
||||
if (dEdge <= 0)
|
||||
EdgeIndex layoutEdge = detail.LayoutEdgeByPoint(globalEdge.p2());
|
||||
if (not layoutEdge.has_value())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dEdge = layoutEdge.value();
|
||||
CrossingType type = CrossingType::Intersection;
|
||||
if (SheetContains(detail.MappedDetailBoundingRect()))
|
||||
{
|
||||
|
|
|
@ -31,8 +31,12 @@
|
|||
#ifndef BPSTD_DETAIL_ENABLE_OVERLOAD_HPP
|
||||
#define BPSTD_DETAIL_ENABLE_OVERLOAD_HPP
|
||||
|
||||
#pragma GCC system_header
|
||||
#pragma clang system_header
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#pragma system_header
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
namespace bpstd {
|
||||
|
|
Loading…
Reference in New Issue
Block a user