OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::RasterizationImpl Namespace Reference

Typedefs

using IndexPair = std::pair<int64_t, int64_t>
using Grids = std::vector<IndexPair>

Functions

IndexPair point_map_grid_index (const Point &pt, int64_t xdist, int64_t ydist)
bool nearly_equal (const Point &p1, const Point &p2)
Grids line_rasterization (const Line &line, int64_t xdist=scale_(1), int64_t ydist=scale_(1))

Typedef Documentation

◆ Grids

◆ IndexPair

using Slic3r::RasterizationImpl::IndexPair = std::pair<int64_t, int64_t>

Function Documentation

◆ line_rasterization()

Grids Slic3r::RasterizationImpl::line_rasterization ( const Line & line,
int64_t xdist = scale_(1),
int64_t ydist = scale_(1) )
inline
44{
45 Grids res;
46 Point rayStart = line.a;
47 Point rayEnd = line.b;
48 IndexPair currentVoxel = point_map_grid_index(rayStart, xdist, ydist);
49 IndexPair firstVoxel = currentVoxel;
50 IndexPair lastVoxel = point_map_grid_index(rayEnd, xdist, ydist);
51
52 Point ray = rayEnd - rayStart;
53
54 double stepX = ray.x() >= 0 ? 1 : -1;
55 double stepY = ray.y() >= 0 ? 1 : -1;
56
57 double nextVoxelBoundaryX = (currentVoxel.first + stepX) * xdist;
58 double nextVoxelBoundaryY = (currentVoxel.second + stepY) * ydist;
59
60 if (stepX < 0) { nextVoxelBoundaryX += xdist; }
61 if (stepY < 0) { nextVoxelBoundaryY += ydist; }
62
63 double tMaxX = ray.x() != 0 ? (nextVoxelBoundaryX - rayStart.x()) / ray.x() : DBL_MAX;
64 double tMaxY = ray.y() != 0 ? (nextVoxelBoundaryY - rayStart.y()) / ray.y() : DBL_MAX;
65
66 double tDeltaX = ray.x() != 0 ? static_cast<double>(xdist) / ray.x() * stepX : DBL_MAX;
67 double tDeltaY = ray.y() != 0 ? static_cast<double>(ydist) / ray.y() * stepY : DBL_MAX;
68
69 res.push_back(currentVoxel);
70
71 double tx = tMaxX;
72 double ty = tMaxY;
73
74 while (lastVoxel != currentVoxel) {
75 if (lastVoxel.first == currentVoxel.first) {
76 for (int64_t i = currentVoxel.second; i != lastVoxel.second; i += (int64_t) stepY) {
77 currentVoxel.second += (int64_t) stepY;
78 res.push_back(currentVoxel);
79 }
80 break;
81 }
82 if (lastVoxel.second == currentVoxel.second) {
83 for (int64_t i = currentVoxel.first; i != lastVoxel.first; i += (int64_t) stepX) {
84 currentVoxel.first += (int64_t) stepX;
85 res.push_back(currentVoxel);
86 }
87 break;
88 }
89
90 if (tx < ty) {
91 currentVoxel.first += (int64_t) stepX;
92 tx += tDeltaX;
93 } else {
94 currentVoxel.second += (int64_t) stepY;
95 ty += tDeltaY;
96 }
97 res.push_back(currentVoxel);
98 if (res.size() >= 100000) { // bug
99 assert(0);
100 }
101 }
102
103 return res;
104}
Point b
Definition Line.hpp:199
Point a
Definition Line.hpp:198
Definition Point.hpp:199
std::pair< int64_t, int64_t > IndexPair
Definition ConflictChecker.cpp:31
IndexPair point_map_grid_index(const Point &pt, int64_t xdist, int64_t ydist)
Definition ConflictChecker.cpp:34
std::vector< IndexPair > Grids
Definition ConflictChecker.cpp:32

References Slic3r::Line::a, Slic3r::Line::b, and point_map_grid_index().

Here is the call graph for this function:

◆ nearly_equal()

bool Slic3r::RasterizationImpl::nearly_equal ( const Point & p1,
const Point & p2 )
inline
41{ return std::abs(p1.x() - p2.x()) < SCALED_EPSILON && std::abs(p1.y() - p2.y()) < SCALED_EPSILON; }
#define SCALED_EPSILON
Definition libslic3r.h:109

References SCALED_EPSILON.

◆ point_map_grid_index()

IndexPair Slic3r::RasterizationImpl::point_map_grid_index ( const Point & pt,
int64_t xdist,
int64_t ydist )
inline
35{
36 auto x = pt.x() / xdist;
37 auto y = pt.y() / ydist;
38 return std::make_pair(x, y);
39}

Referenced by line_rasterization().

Here is the caller graph for this function: