mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-25 09:41:11 -06:00
Changing the internal representation of Point / Pointf / Point3 / Pointf3 to Eigen Matrix types, first step
This commit is contained in:
parent
077680b806
commit
86da661097
60 changed files with 1228 additions and 1206 deletions
|
|
@ -54,9 +54,9 @@ static std::vector<coordf_t> perpendPoints(const coordf_t offset, const size_t b
|
|||
// components that are outside these limits are set to the limits.
|
||||
static inline void trim(Pointfs &pts, coordf_t minX, coordf_t minY, coordf_t maxX, coordf_t maxY)
|
||||
{
|
||||
for (Pointfs::iterator it = pts.begin(); it != pts.end(); ++ it) {
|
||||
it->x = clamp(minX, maxX, it->x);
|
||||
it->y = clamp(minY, maxY, it->y);
|
||||
for (Pointf &pt : pts) {
|
||||
pt.x() = clamp(minX, maxX, pt.x());
|
||||
pt.y() = clamp(minY, maxY, pt.y());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ static Polylines makeGrid(coord_t z, coord_t gridSize, size_t gridWidth, size_t
|
|||
result.push_back(Polyline());
|
||||
Polyline &polyline = result.back();
|
||||
for (Pointfs::const_iterator it = it_polylines->begin(); it != it_polylines->end(); ++ it)
|
||||
polyline.points.push_back(Point(coord_t(it->x * scaleFactor), coord_t(it->y * scaleFactor)));
|
||||
polyline.points.push_back(Point(coord_t(it->x() * scaleFactor), coord_t(it->y() * scaleFactor)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -153,13 +153,13 @@ void Fill3DHoneycomb::_fill_surface_single(
|
|||
Polylines polylines = makeGrid(
|
||||
scale_(this->z),
|
||||
distance,
|
||||
ceil(bb.size().x / distance) + 1,
|
||||
ceil(bb.size().y / distance) + 1,
|
||||
ceil(bb.size().x() / distance) + 1,
|
||||
ceil(bb.size().y() / distance) + 1,
|
||||
((this->layer_id/thickness_layers) % 2) + 1);
|
||||
|
||||
// move pattern in place
|
||||
for (Polylines::iterator it = polylines.begin(); it != polylines.end(); ++ it)
|
||||
it->translate(bb.min.x, bb.min.y);
|
||||
it->translate(bb.min.x(), bb.min.y());
|
||||
|
||||
// clip pattern to boundaries
|
||||
polylines = intersection_pl(polylines, (Polygons)expolygon);
|
||||
|
|
|
|||
|
|
@ -121,11 +121,11 @@ public:
|
|||
return aligned;
|
||||
}
|
||||
static Point _align_to_grid(Point coord, Point spacing)
|
||||
{ return Point(_align_to_grid(coord.x, spacing.x), _align_to_grid(coord.y, spacing.y)); }
|
||||
{ return Point(_align_to_grid(coord.x(), spacing.x()), _align_to_grid(coord.y(), spacing.y())); }
|
||||
static coord_t _align_to_grid(coord_t coord, coord_t spacing, coord_t base)
|
||||
{ return base + _align_to_grid(coord - base, spacing); }
|
||||
static Point _align_to_grid(Point coord, Point spacing, Point base)
|
||||
{ return Point(_align_to_grid(coord.x, spacing.x, base.x), _align_to_grid(coord.y, spacing.y, base.y)); }
|
||||
{ return Point(_align_to_grid(coord.x(), spacing.x(), base.x()), _align_to_grid(coord.y(), spacing.y(), base.y())); }
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ void FillConcentric::_fill_surface_single(
|
|||
coord_t distance = coord_t(min_spacing / params.density);
|
||||
|
||||
if (params.density > 0.9999f && !params.dont_adjust) {
|
||||
distance = this->_adjust_solid_spacing(bounding_box.size().x, distance);
|
||||
distance = this->_adjust_solid_spacing(bounding_box.size().x(), distance);
|
||||
this->spacing = unscale(distance);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,21 +34,21 @@ static inline Polyline make_wave(
|
|||
double z_cos, double z_sin, bool vertical)
|
||||
{
|
||||
std::vector<Pointf> points = one_period;
|
||||
double period = points.back().x;
|
||||
double period = points.back().x();
|
||||
points.pop_back();
|
||||
int n = points.size();
|
||||
do {
|
||||
points.emplace_back(Pointf(points[points.size()-n].x + period, points[points.size()-n].y));
|
||||
} while (points.back().x < width);
|
||||
points.back().x = width;
|
||||
points.emplace_back(Pointf(points[points.size()-n].x() + period, points[points.size()-n].y()));
|
||||
} while (points.back().x() < width);
|
||||
points.back().x() = width;
|
||||
|
||||
// and construct the final polyline to return:
|
||||
Polyline polyline;
|
||||
for (auto& point : points) {
|
||||
point.y += offset;
|
||||
point.y = clamp(0., height, double(point.y));
|
||||
point.y() += offset;
|
||||
point.y() = clamp(0., height, double(point.y()));
|
||||
if (vertical)
|
||||
std::swap(point.x, point.y);
|
||||
std::swap(point.x(), point.y());
|
||||
polyline.points.emplace_back(convert_to<Point>(point * scaleFactor));
|
||||
}
|
||||
|
||||
|
|
@ -73,12 +73,12 @@ static std::vector<Pointf> make_one_period(double width, double scaleFactor, dou
|
|||
auto& tp = points[i]; // this point
|
||||
auto& rp = points[i+1]; // right point
|
||||
// calculate distance of the point to the line:
|
||||
double dist_mm = unscale(scaleFactor * std::abs( (rp.y - lp.y)*tp.x + (lp.x - rp.x)*tp.y + (rp.x*lp.y - rp.y*lp.x) ) / std::hypot((rp.y - lp.y),(lp.x - rp.x)));
|
||||
double dist_mm = unscale(scaleFactor * std::abs( (rp.y() - lp.y())*tp.x() + (lp.x() - rp.x())*tp.y() + (rp.x()*lp.y() - rp.y()*lp.x()) ) / std::hypot((rp.y() - lp.y()),(lp.x() - rp.x())));
|
||||
|
||||
if (dist_mm > tolerance) { // if the difference from straight line is more than this
|
||||
double x = 0.5f * (points[i-1].x + points[i].x);
|
||||
double x = 0.5f * (points[i-1].x() + points[i].x());
|
||||
points.emplace_back(Pointf(x, f(x, z_sin, z_cos, vertical, flip)));
|
||||
x = 0.5f * (points[i+1].x + points[i].x);
|
||||
x = 0.5f * (points[i+1].x() + points[i].x());
|
||||
points.emplace_back(Pointf(x, f(x, z_sin, z_cos, vertical, flip)));
|
||||
std::sort(points.begin(), points.end()); // we added the points to the end, but need them all in order
|
||||
--i; // decrement i so we also check the first newly added point
|
||||
|
|
@ -143,12 +143,12 @@ void FillGyroid::_fill_surface_single(
|
|||
scale_(this->z),
|
||||
density_adjusted,
|
||||
this->spacing,
|
||||
ceil(bb.size().x / distance) + 1.,
|
||||
ceil(bb.size().y / distance) + 1.);
|
||||
ceil(bb.size().x() / distance) + 1.,
|
||||
ceil(bb.size().y() / distance) + 1.);
|
||||
|
||||
// move pattern in place
|
||||
for (Polyline &polyline : polylines)
|
||||
polyline.translate(bb.min.x, bb.min.y);
|
||||
polyline.translate(bb.min.x(), bb.min.y());
|
||||
|
||||
// clip pattern to boundaries
|
||||
polylines = intersection_pl(polylines, (Polygons)expolygon);
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ void FillHoneycomb::_fill_surface_single(
|
|||
bounding_box.merge(_align_to_grid(bounding_box.min, Point(m.hex_width, m.pattern_height)));
|
||||
}
|
||||
|
||||
coord_t x = bounding_box.min.x;
|
||||
while (x <= bounding_box.max.x) {
|
||||
coord_t x = bounding_box.min.x();
|
||||
while (x <= bounding_box.max.x()) {
|
||||
Polygon p;
|
||||
coord_t ax[2] = { x + m.x_offset, x + m.distance - m.x_offset };
|
||||
for (size_t i = 0; i < 2; ++ i) {
|
||||
std::reverse(p.points.begin(), p.points.end()); // turn first half upside down
|
||||
for (coord_t y = bounding_box.min.y; y <= bounding_box.max.y; y += m.y_short + m.hex_side + m.y_short + m.hex_side) {
|
||||
for (coord_t y = bounding_box.min.y(); y <= bounding_box.max.y(); y += m.y_short + m.hex_side + m.y_short + m.hex_side) {
|
||||
p.points.push_back(Point(ax[1], y + m.y_offset));
|
||||
p.points.push_back(Point(ax[0], y + m.y_short - m.y_offset));
|
||||
p.points.push_back(Point(ax[0], y + m.y_short + m.hex_side + m.y_offset));
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ void FillPlanePath::_fill_surface_single(
|
|||
Point shift = this->_centered() ?
|
||||
bounding_box.center() :
|
||||
bounding_box.min;
|
||||
expolygon.translate(-shift.x, -shift.y);
|
||||
bounding_box.translate(-shift.x, -shift.y);
|
||||
expolygon.translate(-shift.x(), -shift.y());
|
||||
bounding_box.translate(-shift.x(), -shift.y());
|
||||
|
||||
Pointfs pts = _generate(
|
||||
coord_t(ceil(coordf_t(bounding_box.min.x) / distance_between_lines)),
|
||||
coord_t(ceil(coordf_t(bounding_box.min.y) / distance_between_lines)),
|
||||
coord_t(ceil(coordf_t(bounding_box.max.x) / distance_between_lines)),
|
||||
coord_t(ceil(coordf_t(bounding_box.max.y) / distance_between_lines)));
|
||||
coord_t(ceil(coordf_t(bounding_box.min.x()) / distance_between_lines)),
|
||||
coord_t(ceil(coordf_t(bounding_box.min.y()) / distance_between_lines)),
|
||||
coord_t(ceil(coordf_t(bounding_box.max.x()) / distance_between_lines)),
|
||||
coord_t(ceil(coordf_t(bounding_box.max.y()) / distance_between_lines)));
|
||||
|
||||
Polylines polylines;
|
||||
if (pts.size() >= 2) {
|
||||
|
|
@ -41,8 +41,8 @@ void FillPlanePath::_fill_surface_single(
|
|||
polyline.points.reserve(pts.size());
|
||||
for (Pointfs::iterator it = pts.begin(); it != pts.end(); ++ it)
|
||||
polyline.points.push_back(Point(
|
||||
coord_t(floor(it->x * distance_between_lines + 0.5)),
|
||||
coord_t(floor(it->y * distance_between_lines + 0.5))));
|
||||
coord_t(floor(it->x() * distance_between_lines + 0.5)),
|
||||
coord_t(floor(it->y() * distance_between_lines + 0.5))));
|
||||
// intersection(polylines_src, offset((Polygons)expolygon, scale_(0.02)), &polylines);
|
||||
polylines = intersection_pl(polylines, to_polygons(expolygon));
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ void FillPlanePath::_fill_surface_single(
|
|||
|
||||
// paths must be repositioned and rotated back
|
||||
for (Polylines::iterator it = polylines.begin(); it != polylines.end(); ++ it) {
|
||||
it->translate(shift.x, shift.y);
|
||||
it->translate(shift.x(), shift.y());
|
||||
it->rotate(direction.first);
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ Pointfs FillHilbertCurve::_generate(coord_t min_x, coord_t min_y, coord_t max_x,
|
|||
line.reserve(sz2);
|
||||
for (size_t i = 0; i < sz2; ++ i) {
|
||||
Point p = hilbert_n_to_xy(i);
|
||||
line.push_back(Pointf(p.x + min_x, p.y + min_y));
|
||||
line.push_back(Pointf(p.x() + min_x, p.y() + min_y));
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void FillRectilinear::_fill_surface_single(
|
|||
|
||||
// define flow spacing according to requested density
|
||||
if (params.density > 0.9999f && !params.dont_adjust) {
|
||||
this->_line_spacing = this->_adjust_solid_spacing(bounding_box.size().x, this->_line_spacing);
|
||||
this->_line_spacing = this->_adjust_solid_spacing(bounding_box.size().x(), this->_line_spacing);
|
||||
this->spacing = unscale(this->_line_spacing);
|
||||
} else {
|
||||
// extend bounding box so that our pattern will be aligned with other layers
|
||||
|
|
@ -38,14 +38,14 @@ void FillRectilinear::_fill_surface_single(
|
|||
}
|
||||
|
||||
// generate the basic pattern
|
||||
coord_t x_max = bounding_box.max.x + SCALED_EPSILON;
|
||||
coord_t x_max = bounding_box.max.x() + SCALED_EPSILON;
|
||||
Lines lines;
|
||||
for (coord_t x = bounding_box.min.x; x <= x_max; x += this->_line_spacing)
|
||||
lines.push_back(this->_line(lines.size(), x, bounding_box.min.y, bounding_box.max.y));
|
||||
for (coord_t x = bounding_box.min.x(); x <= x_max; x += this->_line_spacing)
|
||||
lines.push_back(this->_line(lines.size(), x, bounding_box.min.y(), bounding_box.max.y()));
|
||||
if (this->_horizontal_lines()) {
|
||||
coord_t y_max = bounding_box.max.y + SCALED_EPSILON;
|
||||
for (coord_t y = bounding_box.min.y; y <= y_max; y += this->_line_spacing)
|
||||
lines.push_back(Line(Point(bounding_box.min.x, y), Point(bounding_box.max.x, y)));
|
||||
coord_t y_max = bounding_box.max.y() + SCALED_EPSILON;
|
||||
for (coord_t y = bounding_box.min.y(); y <= y_max; y += this->_line_spacing)
|
||||
lines.push_back(Line(Point(bounding_box.min.x(), y), Point(bounding_box.max.x(), y)));
|
||||
}
|
||||
|
||||
// clip paths against a slightly larger expolygon, so that the first and last paths
|
||||
|
|
@ -72,10 +72,10 @@ void FillRectilinear::_fill_surface_single(
|
|||
for (Polylines::iterator it_polyline = polylines.begin(); it_polyline != polylines.end(); ++ it_polyline) {
|
||||
Point *first_point = &it_polyline->points.front();
|
||||
Point *last_point = &it_polyline->points.back();
|
||||
if (first_point->y > last_point->y)
|
||||
if (first_point->y() > last_point->y())
|
||||
std::swap(first_point, last_point);
|
||||
first_point->y -= extra;
|
||||
last_point->y += extra;
|
||||
first_point->y() -= extra;
|
||||
last_point->y() += extra;
|
||||
}
|
||||
|
||||
size_t n_polylines_out_old = polylines_out.size();
|
||||
|
|
@ -106,7 +106,7 @@ void FillRectilinear::_fill_surface_single(
|
|||
const Vector distance = first_point.vector_to(last_point);
|
||||
// TODO: we should also check that both points are on a fill_boundary to avoid
|
||||
// connecting paths on the boundaries of internal regions
|
||||
if (this->_can_connect(std::abs(distance.x), std::abs(distance.y)) &&
|
||||
if (this->_can_connect(std::abs(distance.x()), std::abs(distance.y())) &&
|
||||
expolygon_off.contains(Line(last_point, first_point))) {
|
||||
// Append the polyline.
|
||||
pts_end.insert(pts_end.end(), it_polyline->points.begin(), it_polyline->points.end());
|
||||
|
|
@ -122,7 +122,7 @@ void FillRectilinear::_fill_surface_single(
|
|||
// paths must be rotated back
|
||||
for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_old; it != polylines_out.end(); ++ it) {
|
||||
// No need to translate, the absolute position is irrelevant.
|
||||
// it->translate(- direction.second.x, - direction.second.y);
|
||||
// it->translate(- direction.second.x(), - direction.second.y());
|
||||
it->rotate(direction.first);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ static inline coordf_t segment_length(const Polygon &poly, size_t seg1, const Po
|
|||
Point px = (i == 0) ? p1 : p2;
|
||||
Point pa = poly.points[((seg == 0) ? poly.points.size() : seg) - 1];
|
||||
Point pb = poly.points[seg];
|
||||
if (pa.x > pb.x)
|
||||
std::swap(pa.x, pb.x);
|
||||
if (pa.y > pb.y)
|
||||
std::swap(pa.y, pb.y);
|
||||
assert(px.x >= pa.x && px.x <= pb.x);
|
||||
assert(px.y >= pa.y && px.y <= pb.y);
|
||||
if (pa.x() > pb.x())
|
||||
std::swap(pa.x(), pb.x());
|
||||
if (pa.y() > pb.y())
|
||||
std::swap(pa.y(), pb.y());
|
||||
assert(px.x() >= pa.x() && px.x() <= pb.x());
|
||||
assert(px.y() >= pa.y() && px.y() <= pb.y());
|
||||
}
|
||||
#endif /* SLIC3R_DEBUG */
|
||||
const Point *pPrev = &p1;
|
||||
|
|
@ -791,7 +791,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
|
||||
// define flow spacing according to requested density
|
||||
if (params.full_infill() && !params.dont_adjust) {
|
||||
line_spacing = this->_adjust_solid_spacing(bounding_box.size().x, line_spacing);
|
||||
line_spacing = this->_adjust_solid_spacing(bounding_box.size().x(), line_spacing);
|
||||
this->spacing = unscale(line_spacing);
|
||||
} else {
|
||||
// extend bounding box so that our pattern will be aligned with other layers
|
||||
|
|
@ -799,7 +799,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
Point refpt = rotate_vector.second.rotated(- rotate_vector.first);
|
||||
// _align_to_grid will not work correctly with positive pattern_shift.
|
||||
coord_t pattern_shift_scaled = coord_t(scale_(pattern_shift)) % line_spacing;
|
||||
refpt.x -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled);
|
||||
refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled);
|
||||
bounding_box.merge(_align_to_grid(
|
||||
bounding_box.min,
|
||||
Point(line_spacing, line_spacing),
|
||||
|
|
@ -808,8 +808,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
|
||||
// Intersect a set of euqally spaced vertical lines wiht expolygon.
|
||||
// n_vlines = ceil(bbox_width / line_spacing)
|
||||
size_t n_vlines = (bounding_box.max.x - bounding_box.min.x + line_spacing - 1) / line_spacing;
|
||||
coord_t x0 = bounding_box.min.x;
|
||||
size_t n_vlines = (bounding_box.max.x() - bounding_box.min.x() + line_spacing - 1) / line_spacing;
|
||||
coord_t x0 = bounding_box.min.x();
|
||||
if (params.full_infill())
|
||||
x0 += (line_spacing + SCALED_EPSILON) / 2;
|
||||
|
||||
|
|
@ -842,8 +842,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
const Point &p1 = contour[iPrev];
|
||||
const Point &p2 = contour[iSegment];
|
||||
// Which of the equally spaced vertical lines is intersected by this segment?
|
||||
coord_t l = p1.x;
|
||||
coord_t r = p2.x;
|
||||
coord_t l = p1.x();
|
||||
coord_t r = p2.x();
|
||||
if (l > r)
|
||||
std::swap(l, r);
|
||||
// il, ir are the left / right indices of vertical lines intersecting a segment
|
||||
|
|
@ -869,33 +869,33 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
assert(l <= this_x);
|
||||
assert(r >= this_x);
|
||||
// Calculate the intersection position in y axis. x is known.
|
||||
if (p1.x == this_x) {
|
||||
if (p2.x == this_x) {
|
||||
if (p1.x() == this_x) {
|
||||
if (p2.x() == this_x) {
|
||||
// Ignore strictly vertical segments.
|
||||
continue;
|
||||
}
|
||||
is.pos_p = p1.y;
|
||||
is.pos_p = p1.y();
|
||||
is.pos_q = 1;
|
||||
} else if (p2.x == this_x) {
|
||||
is.pos_p = p2.y;
|
||||
} else if (p2.x() == this_x) {
|
||||
is.pos_p = p2.y();
|
||||
is.pos_q = 1;
|
||||
} else {
|
||||
// First calculate the intersection parameter 't' as a rational number with non negative denominator.
|
||||
if (p2.x > p1.x) {
|
||||
is.pos_p = this_x - p1.x;
|
||||
is.pos_q = p2.x - p1.x;
|
||||
if (p2.x() > p1.x()) {
|
||||
is.pos_p = this_x - p1.x();
|
||||
is.pos_q = p2.x() - p1.x();
|
||||
} else {
|
||||
is.pos_p = p1.x - this_x;
|
||||
is.pos_q = p1.x - p2.x;
|
||||
is.pos_p = p1.x() - this_x;
|
||||
is.pos_q = p1.x() - p2.x();
|
||||
}
|
||||
assert(is.pos_p >= 0 && is.pos_p <= is.pos_q);
|
||||
// Make an intersection point from the 't'.
|
||||
is.pos_p *= int64_t(p2.y - p1.y);
|
||||
is.pos_p += p1.y * int64_t(is.pos_q);
|
||||
is.pos_p *= int64_t(p2.y() - p1.y());
|
||||
is.pos_p += p1.y() * int64_t(is.pos_q);
|
||||
}
|
||||
// +-1 to take rounding into account.
|
||||
assert(is.pos() + 1 >= std::min(p1.y, p2.y));
|
||||
assert(is.pos() <= std::max(p1.y, p2.y) + 1);
|
||||
assert(is.pos() + 1 >= std::min(p1.y(), p2.y()));
|
||||
assert(is.pos() <= std::max(p1.y(), p2.y()) + 1);
|
||||
segs[i].intersections.push_back(is);
|
||||
}
|
||||
}
|
||||
|
|
@ -919,7 +919,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
const Points &contour = poly_with_offset.contour(iContour).points;
|
||||
size_t iSegment = sil.intersections[i].iSegment;
|
||||
size_t iPrev = ((iSegment == 0) ? contour.size() : iSegment) - 1;
|
||||
coord_t dir = contour[iSegment].x - contour[iPrev].x;
|
||||
coord_t dir = contour[iSegment].x() - contour[iPrev].x();
|
||||
bool low = dir > 0;
|
||||
sil.intersections[i].type = poly_with_offset.is_contour_outer(iContour) ?
|
||||
(low ? SegmentIntersection::OUTER_LOW : SegmentIntersection::OUTER_HIGH) :
|
||||
|
|
@ -1066,7 +1066,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
intrsctn.consumed_vertical_up :
|
||||
seg.intersections[i-1].consumed_vertical_up;
|
||||
if (! consumed) {
|
||||
coordf_t dist2 = sqr(coordf_t(pointLast.x - seg.pos)) + sqr(coordf_t(pointLast.y - intrsctn.pos()));
|
||||
coordf_t dist2 = sqr(coordf_t(pointLast.x() - seg.pos)) + sqr(coordf_t(pointLast.y() - intrsctn.pos()));
|
||||
if (dist2 < dist2min) {
|
||||
dist2min = dist2;
|
||||
i_vline = i_vline2;
|
||||
|
|
@ -1356,8 +1356,8 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
// Handle nearly zero length edges.
|
||||
if (polyline_current->points.size() <= 1 ||
|
||||
(polyline_current->points.size() == 2 &&
|
||||
std::abs(polyline_current->points.front().x - polyline_current->points.back().x) < SCALED_EPSILON &&
|
||||
std::abs(polyline_current->points.front().y - polyline_current->points.back().y) < SCALED_EPSILON))
|
||||
std::abs(polyline_current->points.front().x() - polyline_current->points.back().x()) < SCALED_EPSILON &&
|
||||
std::abs(polyline_current->points.front().y() - polyline_current->points.back().y()) < SCALED_EPSILON))
|
||||
polylines_out.pop_back();
|
||||
intrsctn = NULL;
|
||||
i_intersection = -1;
|
||||
|
|
@ -1383,7 +1383,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP
|
|||
// paths must be rotated back
|
||||
for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_initial; it != polylines_out.end(); ++ it) {
|
||||
// No need to translate, the absolute position is irrelevant.
|
||||
// it->translate(- rotate_vector.second.x, - rotate_vector.second.y);
|
||||
// it->translate(- rotate_vector.second.x(), - rotate_vector.second.y());
|
||||
assert(! it->has_duplicate_points());
|
||||
it->rotate(rotate_vector.first);
|
||||
//FIXME rather simplify the paths to avoid very short edges?
|
||||
|
|
|
|||
|
|
@ -223,24 +223,24 @@ Point SegmentIntersection::pos() const
|
|||
const Pointf p2 = convert_to<Pointf>(line->pos);
|
||||
const Pointf v2 = convert_to<Pointf>(line->dir);
|
||||
// Intersect the two rays.
|
||||
double denom = v1.x * v2.y - v2.x * v1.y;
|
||||
double denom = v1.x() * v2.y() - v2.x() * v1.y();
|
||||
Point out;
|
||||
if (denom == 0.) {
|
||||
// Lines are collinear. As the pos() method is not supposed to be called on collinear vectors,
|
||||
// the source vectors are not quite collinear. Return the center of the contour segment.
|
||||
out = seg_start + seg_end;
|
||||
out.x >>= 1;
|
||||
out.y >>= 1;
|
||||
out.x() >>= 1;
|
||||
out.y() >>= 1;
|
||||
} else {
|
||||
// Find the intersection point.
|
||||
double t = (v2.x * (p1.y - p2.y) - v2.y * (p1.x - p2.x)) / denom;
|
||||
double t = (v2.x() * (p1.y() - p2.y()) - v2.y() * (p1.x() - p2.x())) / denom;
|
||||
if (t < 0.)
|
||||
out = seg_start;
|
||||
else if (t > 1.)
|
||||
out = seg_end;
|
||||
else {
|
||||
out.x = coord_t(floor(p1.x + t * v1.x + 0.5));
|
||||
out.y = coord_t(floor(p1.y + t * v1.y + 0.5));
|
||||
out.x() = coord_t(floor(p1.x() + t * v1.x() + 0.5));
|
||||
out.y() = coord_t(floor(p1.y() + t * v1.y() + 0.5));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
|
@ -317,8 +317,8 @@ int SegmentIntersection::ordering_along_line(const SegmentIntersection &other) c
|
|||
int64_t denom2 = cross(this->line->dir, vec_b);
|
||||
Point vx_a = seg_start_a - this->line->pos;
|
||||
Point vx_b = seg_start_b - this->line->pos;
|
||||
int64_t t1_times_denom1 = int64_t(vx_a.x) * int64_t(vec_a.y) - int64_t(vx_a.y) * int64_t(vec_a.x);
|
||||
int64_t t2_times_denom2 = int64_t(vx_b.x) * int64_t(vec_b.y) - int64_t(vx_b.y) * int64_t(vec_b.x);
|
||||
int64_t t1_times_denom1 = int64_t(vx_a.x()) * int64_t(vec_a.y()) - int64_t(vx_a.y()) * int64_t(vec_a.x());
|
||||
int64_t t2_times_denom2 = int64_t(vx_b.x()) * int64_t(vec_b.y()) - int64_t(vx_b.y()) * int64_t(vec_b.x());
|
||||
assert(denom1 != 0);
|
||||
assert(denom2 != 0);
|
||||
return Int128::compare_rationals_filtered(t1_times_denom1, denom1, t2_times_denom2, denom2);
|
||||
|
|
@ -389,7 +389,7 @@ static bool prepare_infill_hatching_segments(
|
|||
// Define the flow spacing according to requested density.
|
||||
if (params.full_infill() && ! params.dont_adjust) {
|
||||
// Full infill, adjust the line spacing to fit an integer number of lines.
|
||||
out.line_spacing = Fill::_adjust_solid_spacing(bounding_box.size().x, line_spacing);
|
||||
out.line_spacing = Fill::_adjust_solid_spacing(bounding_box.size().x(), line_spacing);
|
||||
// Report back the adjusted line spacing.
|
||||
fill_dir_params.spacing = float(unscale(line_spacing));
|
||||
} else {
|
||||
|
|
@ -398,7 +398,7 @@ static bool prepare_infill_hatching_segments(
|
|||
Point refpt = rotate_vector.second.rotated(- out.angle);
|
||||
// _align_to_grid will not work correctly with positive pattern_shift.
|
||||
coord_t pattern_shift_scaled = coord_t(scale_(fill_dir_params.pattern_shift)) % line_spacing;
|
||||
refpt.x -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled);
|
||||
refpt.x() -= (pattern_shift_scaled >= 0) ? pattern_shift_scaled : (line_spacing + pattern_shift_scaled);
|
||||
bounding_box.merge(Fill::_align_to_grid(
|
||||
bounding_box.min,
|
||||
Point(line_spacing, line_spacing),
|
||||
|
|
@ -407,13 +407,13 @@ static bool prepare_infill_hatching_segments(
|
|||
|
||||
// Intersect a set of euqally spaced vertical lines wiht expolygon.
|
||||
// n_vlines = ceil(bbox_width / line_spacing)
|
||||
size_t n_vlines = (bounding_box.max.x - bounding_box.min.x + line_spacing - 1) / line_spacing;
|
||||
coord_t x0 = bounding_box.min.x;
|
||||
size_t n_vlines = (bounding_box.max.x() - bounding_box.min.x() + line_spacing - 1) / line_spacing;
|
||||
coord_t x0 = bounding_box.min.x();
|
||||
if (params.full_infill())
|
||||
x0 += coord_t((line_spacing + SCALED_EPSILON) / 2);
|
||||
|
||||
out.line_spacing = line_spacing;
|
||||
out.start_point = Point(x0, bounding_box.min.y);
|
||||
out.start_point = Point(x0, bounding_box.min.y());
|
||||
out.start_point.rotate(out.angle);
|
||||
|
||||
#ifdef SLIC3R_DEBUG
|
||||
|
|
@ -436,10 +436,10 @@ static bool prepare_infill_hatching_segments(
|
|||
for (size_t i = 0; i < n_vlines; ++ i) {
|
||||
auto &seg = out.segs[i];
|
||||
seg.idx = i;
|
||||
// seg.x = x0 + coord_t(i) * line_spacing;
|
||||
// seg.x() = x0 + coord_t(i) * line_spacing;
|
||||
coord_t x = x0 + coord_t(i) * line_spacing;
|
||||
seg.pos.x = coord_t(floor(cos_a * x - sin_a * bounding_box.min.y + 0.5));
|
||||
seg.pos.y = coord_t(floor(cos_a * bounding_box.min.y + sin_a * x + 0.5));
|
||||
seg.pos.x() = coord_t(floor(cos_a * x - sin_a * bounding_box.min.y() + 0.5));
|
||||
seg.pos.y() = coord_t(floor(cos_a * bounding_box.min.y() + sin_a * x + 0.5));
|
||||
seg.dir = out.direction;
|
||||
}
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ static bool prepare_infill_hatching_segments(
|
|||
const Point *pr = &contour[iSegment];
|
||||
// Orient the segment to the direction vector.
|
||||
const Point v = *pr - *pl;
|
||||
int orientation = Int128::sign_determinant_2x2_filtered(v.x, v.y, out.direction.x, out.direction.y);
|
||||
int orientation = Int128::sign_determinant_2x2_filtered(v.x(), v.y(), out.direction.x(), out.direction.y());
|
||||
if (orientation == 0)
|
||||
// Ignore strictly vertical segments.
|
||||
continue;
|
||||
|
|
@ -462,8 +462,8 @@ static bool prepare_infill_hatching_segments(
|
|||
// Always orient the input segment consistently towards the hatching direction.
|
||||
std::swap(pl, pr);
|
||||
// Which of the equally spaced vertical lines is intersected by this segment?
|
||||
coord_t l = (coord_t)floor(cos_a * pl->x + sin_a * pl->y - SCALED_EPSILON);
|
||||
coord_t r = (coord_t)ceil (cos_a * pr->x + sin_a * pr->y + SCALED_EPSILON);
|
||||
coord_t l = (coord_t)floor(cos_a * pl->x() + sin_a * pl->y() - SCALED_EPSILON);
|
||||
coord_t r = (coord_t)ceil (cos_a * pr->x() + sin_a * pr->y() + SCALED_EPSILON);
|
||||
assert(l < r - SCALED_EPSILON);
|
||||
// il, ir are the left / right indices of vertical lines intersecting a segment
|
||||
int il = std::max<int>(0, (l - x0 + line_spacing) / line_spacing);
|
||||
|
|
@ -479,9 +479,9 @@ static bool prepare_infill_hatching_segments(
|
|||
// 2) all lines from il to ir intersect <pl, pr>.
|
||||
assert(il >= 0 && ir < int(out.segs.size()));
|
||||
for (int i = il; i <= ir; ++ i) {
|
||||
// assert(out.segs[i].x == i * line_spacing + x0);
|
||||
// assert(l <= out.segs[i].x);
|
||||
// assert(r >= out.segs[i].x);
|
||||
// assert(out.segs[i].x() == i * line_spacing + x0);
|
||||
// assert(l <= out.segs[i].x());
|
||||
// assert(r >= out.segs[i].x());
|
||||
SegmentIntersection is;
|
||||
is.line = &out.segs[i];
|
||||
is.expoly_with_offset = &poly_with_offset;
|
||||
|
|
@ -491,10 +491,10 @@ static bool prepare_infill_hatching_segments(
|
|||
// +-1 to take rounding into account.
|
||||
assert(int128::orient(out.segs[i].pos, out.segs[i].pos + out.direction, *pl) >= 0);
|
||||
assert(int128::orient(out.segs[i].pos, out.segs[i].pos + out.direction, *pr) <= 0);
|
||||
assert(is.pos().x + 1 >= std::min(pl->x, pr->x));
|
||||
assert(is.pos().y + 1 >= std::min(pl->y, pr->y));
|
||||
assert(is.pos().x <= std::max(pl->x, pr->x) + 1);
|
||||
assert(is.pos().y <= std::max(pl->y, pr->y) + 1);
|
||||
assert(is.pos().x() + 1 >= std::min(pl->x(), pr->x()));
|
||||
assert(is.pos().y() + 1 >= std::min(pl->y(), pr->y()));
|
||||
assert(is.pos().x() <= std::max(pl->x(), pr->x()) + 1);
|
||||
assert(is.pos().y() <= std::max(pl->y(), pr->y()) + 1);
|
||||
out.segs[i].intersections.push_back(is);
|
||||
}
|
||||
}
|
||||
|
|
@ -659,12 +659,12 @@ static inline coordf_t segment_length(const Polygon &poly, size_t seg1, const Po
|
|||
Point px = (i == 0) ? p1 : p2;
|
||||
Point pa = poly.points[((seg == 0) ? poly.points.size() : seg) - 1];
|
||||
Point pb = poly.points[seg];
|
||||
if (pa.x > pb.x)
|
||||
std::swap(pa.x, pb.x);
|
||||
if (pa.y > pb.y)
|
||||
std::swap(pa.y, pb.y);
|
||||
assert(px.x >= pa.x && px.x <= pb.x);
|
||||
assert(px.y >= pa.y && px.y <= pb.y);
|
||||
if (pa.x() > pb.x())
|
||||
std::swap(pa.x(), pb.x());
|
||||
if (pa.y() > pb.y())
|
||||
std::swap(pa.y(), pb.y());
|
||||
assert(px.x() >= pa.x() && px.x() <= pb.x());
|
||||
assert(px.y() >= pa.y() && px.y() <= pb.y());
|
||||
}
|
||||
#endif /* SLIC3R_DEBUG */
|
||||
const Point *pPrev = &p1;
|
||||
|
|
@ -1481,8 +1481,8 @@ static bool fill_hatching_segments_legacy(
|
|||
// Handle nearly zero length edges.
|
||||
if (polyline_current->points.size() <= 1 ||
|
||||
(polyline_current->points.size() == 2 &&
|
||||
std::abs(polyline_current->points.front().x - polyline_current->points.back().x) < SCALED_EPSILON &&
|
||||
std::abs(polyline_current->points.front().y - polyline_current->points.back().y) < SCALED_EPSILON))
|
||||
std::abs(polyline_current->points.front().x() - polyline_current->points.back().x()) < SCALED_EPSILON &&
|
||||
std::abs(polyline_current->points.front().y() - polyline_current->points.back().y()) < SCALED_EPSILON))
|
||||
polylines_out.pop_back();
|
||||
intrsctn = NULL;
|
||||
i_intersection = -1;
|
||||
|
|
@ -1510,7 +1510,7 @@ static bool fill_hatching_segments_legacy(
|
|||
// paths must be rotated back
|
||||
for (Polylines::iterator it = polylines_out.begin() + n_polylines_out_initial; it != polylines_out.end(); ++ it) {
|
||||
// No need to translate, the absolute position is irrelevant.
|
||||
// it->translate(- rotate_vector.second.x, - rotate_vector.second.y);
|
||||
// it->translate(- rotate_vector.second.x(), - rotate_vector.second.y());
|
||||
assert(! it->has_duplicate_points());
|
||||
//it->rotate(rotate_vector.first);
|
||||
//FIXME rather simplify the paths to avoid very short edges?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue