本文整理汇总了C++中Polygons::inside方法的典型用法代码示例。如果您正苦于以下问题:C++ Polygons::inside方法的具体用法?C++ Polygons::inside怎么用?C++ Polygons::inside使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygons
的用法示例。
在下文中一共展示了Polygons::inside方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: normal
bool Comb::Crossing::findOutside(const Polygons& outside, const Point close_to, const bool fail_on_unavoidable_obstacles, Comb& comber)
{
out = in_or_mid;
if (dest_is_inside || outside.inside(in_or_mid, true)) // start in_between
{ // move outside
Point preferred_crossing_1_out = in_or_mid + normal(close_to - in_or_mid, comber.offset_from_inside_to_outside);
std::function<int(Point)> close_to_penalty_function([preferred_crossing_1_out](Point candidate){ return vSize2((candidate - preferred_crossing_1_out) / 2); });
std::optional<ClosestPolygonPoint> crossing_1_out_cpp = PolygonUtils::findClose(in_or_mid, outside, comber.getOutsideLocToLine(), close_to_penalty_function);
if (crossing_1_out_cpp)
{
out = PolygonUtils::moveOutside(*crossing_1_out_cpp, comber.offset_dist_to_get_from_on_the_polygon_to_outside);
}
else
{
PolygonUtils::moveOutside(outside, out, comber.offset_dist_to_get_from_on_the_polygon_to_outside);
}
}
int64_t in_out_dist2_1 = vSize2(out - in_or_mid);
if (dest_is_inside && in_out_dist2_1 > comber.max_crossing_dist2) // moveInside moved too far
{ // if move is too far over in_between
// find crossing closer by
assert(dest_crossing_poly && "destination crossing poly should have been instantiated!");
std::shared_ptr<std::pair<ClosestPolygonPoint, ClosestPolygonPoint>> best = findBestCrossing(outside, *dest_crossing_poly, dest_point, close_to, comber);
if (best)
{
in_or_mid = PolygonUtils::moveInside(best->first, comber.offset_dist_to_get_from_on_the_polygon_to_outside);
out = PolygonUtils::moveOutside(best->second, comber.offset_dist_to_get_from_on_the_polygon_to_outside);
}
if (fail_on_unavoidable_obstacles && vSize2(out - in_or_mid) > comber.max_crossing_dist2) // moveInside moved still too far
{
return false;
}
}
return true;
}
示例2: distanceFromPointToMesh
int SubDivCube::distanceFromPointToMesh(SliceMeshStorage& mesh, int layer_nr, Point& location, int64_t* distance2)
{
if (layer_nr < 0 || (unsigned int)layer_nr >= mesh.layers.size()) //!< this layer is outside of valid range
{
return 2;
*distance2 = 0;
}
Polygons collide;
mesh.layers[layer_nr].getSecondOrInnermostWalls(collide);
Point centerpoint = location;
bool inside = collide.inside(centerpoint);
ClosestPolygonPoint border_point = PolygonUtils::moveInside2(collide, centerpoint);
Point diff = border_point.location - location;
*distance2 = vSize2(diff);
if (inside)
{
return 1;
}
return 0;
}
示例3: generateTotalGyroidInfill
void GyroidInfill::generateTotalGyroidInfill(Polygons& result_lines, bool zig_zaggify, coord_t outline_offset, coord_t infill_line_width, coord_t line_distance, const Polygons& in_outline, coord_t z)
{
// generate infill based on the gyroid equation: sin_x * cos_y + sin_y * cos_z + sin_z * cos_x = 0
// kudos to the author of the Slic3r implementation equation code, the equation code here is based on that
if (zig_zaggify)
{
outline_offset -= infill_line_width / 2; // the infill line zig zag connections must lie next to the border, not on it
}
const Polygons outline = in_outline.offset(outline_offset);
const AABB aabb(outline);
int pitch = line_distance * 2.41; // this produces similar density to the "line" infill pattern
int num_steps = 4;
int step = pitch / num_steps;
while (step > 500 && num_steps < 16)
{
num_steps *= 2;
step = pitch / num_steps;
}
pitch = step * num_steps; // recalculate to avoid precision errors
const double z_rads = 2 * M_PI * z / pitch;
const double cos_z = std::cos(z_rads);
const double sin_z = std::sin(z_rads);
std::vector<coord_t> odd_line_coords;
std::vector<coord_t> even_line_coords;
Polygons result;
std::vector<Point> chains[2]; // [start_points[], end_points[]]
std::vector<unsigned> connected_to[2]; // [chain_indices[], chain_indices[]]
std::vector<int> line_numbers; // which row/column line a chain is part of
if (std::abs(sin_z) <= std::abs(cos_z))
{
// "vertical" lines
const double phase_offset = ((cos_z < 0) ? M_PI : 0) + M_PI;
for (coord_t y = 0; y < pitch; y += step)
{
const double y_rads = 2 * M_PI * y / pitch;
const double a = cos_z;
const double b = std::sin(y_rads + phase_offset);
const double odd_c = sin_z * std::cos(y_rads + phase_offset);
const double even_c = sin_z * std::cos(y_rads + phase_offset + M_PI);
const double h = std::sqrt(a * a + b * b);
const double odd_x_rads = ((h != 0) ? std::asin(odd_c / h) + std::asin(b / h) : 0) - M_PI/2;
const double even_x_rads = ((h != 0) ? std::asin(even_c / h) + std::asin(b / h) : 0) - M_PI/2;
odd_line_coords.push_back(odd_x_rads / M_PI * pitch);
even_line_coords.push_back(even_x_rads / M_PI * pitch);
}
const unsigned num_coords = odd_line_coords.size();
unsigned num_columns = 0;
for (coord_t x = (std::floor(aabb.min.X / pitch) - 2.25) * pitch; x <= aabb.max.X + pitch/2; x += pitch/2)
{
bool is_first_point = true;
Point last;
bool last_inside = false;
unsigned chain_end_index = 0;
Point chain_end[2];
for (coord_t y = (std::floor(aabb.min.Y / pitch) - 1) * pitch; y <= aabb.max.Y + pitch; y += pitch)
{
for (unsigned i = 0; i < num_coords; ++i)
{
Point current(x + ((num_columns & 1) ? odd_line_coords[i] : even_line_coords[i])/2 + pitch, y + (coord_t)(i * step));
bool current_inside = outline.inside(current, true);
if (!is_first_point)
{
if (last_inside && current_inside)
{
// line doesn't hit the boundary, add the whole line
result.addLine(last, current);
}
else if (last_inside != current_inside)
{
// line hits the boundary, add the part that's inside the boundary
Polygons line;
line.addLine(last, current);
line = outline.intersectionPolyLines(line);
if (line.size() > 0)
{
// some of the line is inside the boundary
result.addLine(line[0][0], line[0][1]);
if (zig_zaggify)
{
chain_end[chain_end_index] = line[0][(line[0][0] != last && line[0][0] != current) ? 0 : 1];
if (++chain_end_index == 2)
{
chains[0].push_back(chain_end[0]);
chains[1].push_back(chain_end[1]);
chain_end_index = 0;
connected_to[0].push_back(std::numeric_limits<unsigned>::max());
connected_to[1].push_back(std::numeric_limits<unsigned>::max());
line_numbers.push_back(num_columns);
}
}
}
else
{
// none of the line is inside the boundary so the point that's actually on the boundary
// is the chain end
if (zig_zaggify)
{
//.........这里部分代码省略.........