mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 09:42:09 +08:00
Use max value of double instead of std::optional in get_first_crossed_line_distance() and get_obstacle_adjusted_slope_end().
This commit is contained in:
parent
dbd0369767
commit
2fc9299c65
@ -114,13 +114,12 @@ Points3 generate_elevated_travel(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<double> get_first_crossed_line_distance(
|
double get_first_crossed_line_distance(
|
||||||
tcb::span<const Line> xy_path, const AABBTreeLines::LinesDistancer<Linef> &distancer
|
tcb::span<const Line> xy_path, const AABBTreeLines::LinesDistancer<Linef> &distancer
|
||||||
) {
|
) {
|
||||||
assert(!xy_path.empty());
|
assert(!xy_path.empty());
|
||||||
if (xy_path.empty()) {
|
if (xy_path.empty())
|
||||||
return {};
|
return std::numeric_limits<double>::max();
|
||||||
}
|
|
||||||
|
|
||||||
double traversed_distance = 0;
|
double traversed_distance = 0;
|
||||||
for (const Line &line : xy_path) {
|
for (const Line &line : xy_path) {
|
||||||
@ -139,7 +138,7 @@ std::optional<double> get_first_crossed_line_distance(
|
|||||||
traversed_distance += (unscaled_line.a - unscaled_line.b).norm();
|
traversed_distance += (unscaled_line.a - unscaled_line.b).norm();
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return std::numeric_limits<double>::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SmoothingParams
|
struct SmoothingParams
|
||||||
@ -222,15 +221,14 @@ ElevatedTravelParams get_elevated_traval_params(
|
|||||||
elevation_params.slope_end = elevation_params.lift_height / std::tan(slope_rad);
|
elevation_params.slope_end = elevation_params.lift_height / std::tan(slope_rad);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<double> obstacle_adjusted_slope_end{
|
const double obstacle_adjusted_slope_end{
|
||||||
previous_layer_distancer ?
|
previous_layer_distancer ?
|
||||||
get_first_crossed_line_distance(xy_path.lines(), *previous_layer_distancer) :
|
get_first_crossed_line_distance(xy_path.lines(), *previous_layer_distancer) :
|
||||||
std::nullopt
|
std::numeric_limits<double>::max()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (obstacle_adjusted_slope_end && obstacle_adjusted_slope_end < elevation_params.slope_end) {
|
if (obstacle_adjusted_slope_end < elevation_params.slope_end)
|
||||||
elevation_params.slope_end = *obstacle_adjusted_slope_end;
|
elevation_params.slope_end = obstacle_adjusted_slope_end;
|
||||||
}
|
|
||||||
|
|
||||||
SmoothingParams smoothing_params{get_smoothing_params(
|
SmoothingParams smoothing_params{get_smoothing_params(
|
||||||
elevation_params.lift_height, elevation_params.slope_end, extruder_id,
|
elevation_params.lift_height, elevation_params.slope_end, extruder_id,
|
||||||
|
@ -141,7 +141,7 @@ Points3 generate_elevated_travel(
|
|||||||
*
|
*
|
||||||
* **Ignores intersection with xy_path starting point.**
|
* **Ignores intersection with xy_path starting point.**
|
||||||
*/
|
*/
|
||||||
std::optional<double> get_first_crossed_line_distance(
|
double get_first_crossed_line_distance(
|
||||||
tcb::span<const Line> xy_path, const AABBTreeLines::LinesDistancer<Linef> &distancer
|
tcb::span<const Line> xy_path, const AABBTreeLines::LinesDistancer<Linef> &distancer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -171,13 +171,13 @@ TEST_CASE("Get first crossed line distance", "[GCode]") {
|
|||||||
// Try different cases by skipping lines in the travel.
|
// Try different cases by skipping lines in the travel.
|
||||||
AABBTreeLines::LinesDistancer<Linef> distancer{std::move(lines)};
|
AABBTreeLines::LinesDistancer<Linef> distancer{std::move(lines)};
|
||||||
|
|
||||||
CHECK(*get_first_crossed_line_distance(travel, distancer) == Approx(1));
|
CHECK(get_first_crossed_line_distance(travel, distancer) == Approx(1));
|
||||||
CHECK(*get_first_crossed_line_distance(tcb::span{travel}.subspan(1), distancer) == Approx(0.2));
|
CHECK(get_first_crossed_line_distance(tcb::span{travel}.subspan(1), distancer) == Approx(0.2));
|
||||||
CHECK(*get_first_crossed_line_distance(tcb::span{travel}.subspan(2), distancer) == Approx(0.5));
|
CHECK(get_first_crossed_line_distance(tcb::span{travel}.subspan(2), distancer) == Approx(0.5));
|
||||||
CHECK(*get_first_crossed_line_distance(tcb::span{travel}.subspan(3), distancer) == Approx(1.0)); //Edge case
|
CHECK(get_first_crossed_line_distance(tcb::span{travel}.subspan(3), distancer) == Approx(1.0)); //Edge case
|
||||||
CHECK(*get_first_crossed_line_distance(tcb::span{travel}.subspan(4), distancer) == Approx(0.7));
|
CHECK(get_first_crossed_line_distance(tcb::span{travel}.subspan(4), distancer) == Approx(0.7));
|
||||||
CHECK(*get_first_crossed_line_distance(tcb::span{travel}.subspan(5), distancer) == Approx(1.6));
|
CHECK(get_first_crossed_line_distance(tcb::span{travel}.subspan(5), distancer) == Approx(1.6));
|
||||||
CHECK_FALSE(get_first_crossed_line_distance(tcb::span{travel}.subspan(6), distancer));
|
CHECK(get_first_crossed_line_distance(tcb::span{travel}.subspan(6), distancer) == std::numeric_limits<double>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user