Fixing items partially outside the bed when auto-placing new items.

This commit is contained in:
tamasmeszaros
2019-01-23 16:35:21 +01:00
parent 22ffb93ee5
commit 6819c506d8
5 changed files with 65 additions and 44 deletions
@@ -69,12 +69,14 @@ struct PointPair {
RawPoint p2;
};
struct PointTag {};
struct PolygonTag {};
struct PathTag {};
struct MultiPolygonTag {};
struct BoxTag {};
struct CircleTag {};
/// Meta-functions to derive the tags
template<class Shape> struct ShapeTag { using Type = typename Shape::Tag; };
template<class S> using Tag = typename ShapeTag<remove_cvref_t<S>>::Type;
@@ -131,7 +133,7 @@ public:
_Circle(const RawPoint& center, double r): center_(center), radius_(r) {}
inline const RawPoint& center() const BP2D_NOEXCEPT { return center_; }
inline const void center(const RawPoint& c) { center_ = c; }
inline void center(const RawPoint& c) { center_ = c; }
inline double radius() const BP2D_NOEXCEPT { return radius_; }
inline void radius(double r) { radius_ = r; }
@@ -518,21 +520,19 @@ inline bool intersects(const RawShape& /*sh*/, const RawShape& /*sh*/)
return false;
}
template<class RawShape>
inline bool isInside(const TPoint<RawShape>& /*point*/,
const RawShape& /*shape*/)
{
static_assert(always_false<RawShape>::value,
"shapelike::isInside(point, shape) unimplemented!");
template<class TGuest, class THost>
inline bool isInside(const TGuest&, const THost&,
const PointTag&, const PolygonTag&) {
static_assert(always_false<THost>::value,
"shapelike::isInside(point, path) unimplemented!");
return false;
}
template<class RawShape>
inline bool isInside(const RawShape& /*shape*/,
const RawShape& /*shape*/)
{
static_assert(always_false<RawShape>::value,
"shapelike::isInside(shape, shape) unimplemented!");
template<class TGuest, class THost>
inline bool isInside(const TGuest&, const THost&,
const PolygonTag&, const PolygonTag&) {
static_assert(always_false<THost>::value,
"shapelike::isInside(shape, shape) unimplemented!");
return false;
}
@@ -651,7 +651,7 @@ template<class RawPath> inline bool isConvex(const RawPath& sh, const PathTag&)
template<class RawShape>
inline typename TContour<RawShape>::iterator
begin(RawShape& sh, const PolygonTag& t)
begin(RawShape& sh, const PolygonTag&)
{
return begin(contour(sh), PathTag());
}
@@ -818,16 +818,16 @@ inline auto convexHull(const RawShape& sh)
return convexHull(sh, Tag<RawShape>());
}
template<class RawShape>
inline bool isInside(const TPoint<RawShape>& point,
const _Circle<TPoint<RawShape>>& circ)
template<class TP, class TC>
inline bool isInside(const TP& point, const TC& circ,
const PointTag&, const CircleTag&)
{
return pointlike::distance(point, circ.center()) < circ.radius();
}
template<class RawShape>
inline bool isInside(const TPoint<RawShape>& point,
const _Box<TPoint<RawShape>>& box)
template<class TP, class TB>
inline bool isInside(const TP& point, const TB& box,
const PointTag&, const BoxTag&)
{
auto px = getX(point);
auto py = getY(point);
@@ -839,27 +839,27 @@ inline bool isInside(const TPoint<RawShape>& point,
return px > minx && px < maxx && py > miny && py < maxy;
}
template<class RawShape>
inline bool isInside(const RawShape& sh,
const _Circle<TPoint<RawShape>>& circ)
template<class RawShape, class TC>
inline bool isInside(const RawShape& sh, const TC& circ,
const PolygonTag&, const CircleTag&)
{
return std::all_of(cbegin(sh), cend(sh),
[&circ](const TPoint<RawShape>& p){
return isInside<RawShape>(p, circ);
return std::all_of(cbegin(sh), cend(sh), [&circ](const TPoint<RawShape>& p)
{
return isInside(p, circ, PointTag(), CircleTag());
});
}
template<class RawShape>
inline bool isInside(const _Box<TPoint<RawShape>>& box,
const _Circle<TPoint<RawShape>>& circ)
template<class TB, class TC>
inline bool isInside(const TB& box, const TC& circ,
const BoxTag&, const CircleTag&)
{
return isInside<RawShape>(box.minCorner(), circ) &&
isInside<RawShape>(box.maxCorner(), circ);
return isInside(box.minCorner(), circ, BoxTag(), CircleTag()) &&
isInside(box.maxCorner(), circ, BoxTag(), CircleTag());
}
template<class RawShape>
inline bool isInside(const _Box<TPoint<RawShape>>& ibb,
const _Box<TPoint<RawShape>>& box)
template<class TBGuest, class TBHost>
inline bool isInside(const TBGuest& ibb, const TBHost& box,
const BoxTag&, const BoxTag&)
{
auto iminX = getX(ibb.minCorner());
auto imaxX = getX(ibb.maxCorner());
@@ -874,6 +874,18 @@ inline bool isInside(const _Box<TPoint<RawShape>>& ibb,
return iminX > minX && imaxX < maxX && iminY > minY && imaxY < maxY;
}
template<class RawShape, class TB>
inline bool isInside(const RawShape& poly, const TB& box,
const PolygonTag&, const BoxTag&)
{
return isInside(boundingBox(poly), box, BoxTag(), BoxTag());
}
template<class TGuest, class THost>
inline bool isInside(const TGuest& guest, const THost& host) {
return isInside(guest, host, Tag<TGuest>(), Tag<THost>());
}
template<class RawShape> // Potential O(1) implementation may exist
inline TPoint<RawShape>& vertex(RawShape& sh, unsigned long idx,
const PolygonTag&)