Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disallowed areas #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/libnest2d/nester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ class _Item {
int binid_{BIN_ID_UNSET}, priority_{0};
bool fixed_{false};

/**
* \brief If this is a fixed area, indicates whether it is a disallowed area
* or a previously placed item.
*
* If this is a disallowed area, other objects will not get packed close
* together with this item. It only blocks other items in its area.
*/
bool disallowed_{false};

public:

/// The type of the shape which was handed over as the template argument.
Expand Down Expand Up @@ -129,10 +138,18 @@ class _Item {
sh_(sl::create<RawShape>(std::move(contour), std::move(holes))) {}

inline bool isFixed() const noexcept { return fixed_; }
inline bool isDisallowedArea() const noexcept { return disallowed_; }
inline void markAsFixedInBin(int binid)
{
fixed_ = binid >= 0;
binid_ = binid;
disallowed_ = false;
}
inline void markAsDisallowedAreaInBin(int binid)
{
fixed_ = binid >= 0;
binid_ = binid;
disallowed_ = fixed_;
}

inline void binId(int idx) { binid_ = idx; }
Expand Down
5 changes: 3 additions & 2 deletions include/libnest2d/placers/nfpplacer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct NfpPConfig {
* alignment with the candidate item or do anything else.
*
* \param remaining A container with the remaining items waiting to be
* placed. You can use some features about the remaining items to alter to
* placed. You can use some features about the remaining items to alter the
* score of the current placement. If you know that you have to leave place
* for other items as well, that might influence your decision about where
* the current candidate should be placed. E.g. imagine three big circles
Expand Down Expand Up @@ -735,7 +735,8 @@ class _NofitPolyPlacer: public PlacerBoilerplate<_NofitPolyPlacer<RawShape, TBin
remlist.insert(remlist.end(), remaining.from, remaining.to);
}

if(items_.empty()) {
if(std::all_of(items_.begin(), items_.end(),
[](const Item& item) { return item.isDisallowedArea(); })) {
setInitialPosition(item);
best_overfit = overfit(item.transformedShape(), bin_);
can_pack = best_overfit <= 0;
Expand Down