Cleanup: Use functional cast for enum in curves sculpt

Also remove unnecessary storage in classes when it can be a local variable.
This commit is contained in:
Hans Goudey 2024-01-12 18:03:21 -05:00
parent bb080140c0
commit 000e322ae5
10 changed files with 21 additions and 34 deletions

View File

@ -154,8 +154,7 @@ struct AddOperationExecutor {
brush_pos_re_ = stroke_extension.mouse_position;
use_front_face_ = brush_->flag & BRUSH_FRONTFACE;
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
add_amount_ = std::max(0, brush_settings_->add_amount);
if (add_amount_ == 0) {

View File

@ -91,8 +91,6 @@ struct CombOperationExecutor {
float brush_radius_factor_;
float brush_strength_;
eBrushFalloffShape falloff_shape_;
Object *curves_ob_orig_ = nullptr;
Curves *curves_id_orig_ = nullptr;
CurvesGeometry *curves_orig_ = nullptr;
@ -128,7 +126,7 @@ struct CombOperationExecutor {
brush_radius_factor_ = brush_radius_factor(*brush_, stroke_extension);
brush_strength_ = brush_strength_get(*ctx_.scene, *brush_, stroke_extension);
falloff_shape_ = static_cast<eBrushFalloffShape>(brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
transforms_ = CurvesSurfaceTransforms(*curves_ob_orig_, curves_id_orig_->surface);
@ -141,7 +139,7 @@ struct CombOperationExecutor {
brush_pos_diff_re_ = brush_pos_re_ - brush_pos_prev_re_;
if (stroke_extension.is_first) {
if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
this->initialize_spherical_brush_reference_point();
}
self_->constraint_solver_.initialize(
@ -163,10 +161,10 @@ struct CombOperationExecutor {
Array<bool> changed_curves(curves_orig_->curves_num(), false);
if (falloff_shape_ == PAINT_FALLOFF_SHAPE_TUBE) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
this->comb_projected_with_symmetry(changed_curves);
}
else if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) {
else if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
this->comb_spherical_with_symmetry(changed_curves);
}
else {

View File

@ -105,8 +105,7 @@ struct DeleteOperationExecutor {
transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface);
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
if (stroke_extension.is_first) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {

View File

@ -160,8 +160,7 @@ struct DensityAddOperationExecutor {
brush_radius_re_ = brush_radius_get(*ctx_.scene, *brush_, stroke_extension);
brush_pos_re_ = stroke_extension.mouse_position;
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
Vector<float3> new_positions_cu;
Vector<float2> new_uvs;
@ -565,8 +564,7 @@ struct DensitySubtractOperationExecutor {
curve_selection_ = curves::retrieve_selected_curves(*curves_id_, selected_curve_memory_);
transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface);
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
if (stroke_extension.is_first) {
const bke::crazyspace::GeometryDeformation deformation =
@ -802,7 +800,7 @@ static bool use_add_density_mode(const BrushStrokeMode brush_mode,
const ARegion &region = *CTX_wm_region(&C);
const View3D &v3d = *CTX_wm_view3d(&C);
const eBrushCurvesSculptDensityMode density_mode = static_cast<eBrushCurvesSculptDensityMode>(
const eBrushCurvesSculptDensityMode density_mode = eBrushCurvesSculptDensityMode(
brush.curves_sculpt_settings->density_mode);
const bool use_invert = brush_mode == BRUSH_STROKE_INVERT;

View File

@ -115,7 +115,7 @@ float brush_strength_get(const Scene &scene,
static std::unique_ptr<CurvesSculptStrokeOperation> start_brush_operation(
bContext &C, wmOperator &op, const StrokeExtension &stroke_start)
{
const BrushStrokeMode mode = static_cast<BrushStrokeMode>(RNA_enum_get(op.ptr, "mode"));
const BrushStrokeMode mode = BrushStrokeMode(RNA_enum_get(op.ptr, "mode"));
const Scene &scene = *CTX_data_scene(&C);
const CurvesSculpt &curves_sculpt = *scene.toolsettings->curves_sculpt;

View File

@ -111,8 +111,7 @@ struct PinchOperationExecutor {
curve_selection_ = curves::retrieve_selected_curves(*curves_id_, selected_curve_memory_);
brush_pos_re_ = stroke_extension.mouse_position;
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
if (stroke_extension.is_first) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {

View File

@ -67,8 +67,6 @@ struct PuffOperationExecutor {
float brush_strength_;
float2 brush_pos_re_;
eBrushFalloffShape falloff_shape_;
CurvesSurfaceTransforms transforms_;
const Object *surface_ob_ = nullptr;
@ -108,7 +106,7 @@ struct PuffOperationExecutor {
".selection", bke::AttrDomain::Point, 1.0f);
curve_selection_ = curves::retrieve_selected_curves(*curves_id_, selected_curve_memory_);
falloff_shape_ = static_cast<eBrushFalloffShape>(brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
surface_ob_ = curves_id_->surface;
surface_ = static_cast<const Mesh *>(surface_ob_->data);
@ -123,7 +121,7 @@ struct PuffOperationExecutor {
BLI_SCOPED_DEFER([&]() { free_bvhtree_from_mesh(&surface_bvh_); });
if (stroke_extension.is_first) {
if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
self.brush_3d_ = *sample_curves_3d_brush(*ctx_.depsgraph,
*ctx_.region,
*ctx_.v3d,
@ -139,10 +137,10 @@ struct PuffOperationExecutor {
Array<float> curve_weights(curves_->curves_num());
if (falloff_shape_ == PAINT_FALLOFF_SHAPE_TUBE) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
this->find_curve_weights_projected_with_symmetry(curve_weights);
}
else if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) {
else if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
this->find_curves_weights_spherical_with_symmetry(curve_weights);
}
else {

View File

@ -109,8 +109,7 @@ struct SelectionPaintOperationExecutor {
transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface);
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
selection_goal_ = self_->use_select_ ? 1.0f : 0.0f;

View File

@ -84,8 +84,7 @@ struct SmoothOperationExecutor {
curve_selection_ = curves::retrieve_selected_curves(*curves_id_, selected_curve_memory_);
transforms_ = CurvesSurfaceTransforms(*object_, curves_id_->surface);
const eBrushFalloffShape falloff_shape = static_cast<eBrushFalloffShape>(
brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
if (stroke_extension.is_first) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
self.brush_3d_ = *sample_curves_3d_brush(*ctx_.depsgraph,

View File

@ -80,8 +80,6 @@ struct SnakeHookOperatorExecutor {
float brush_radius_factor_;
float brush_strength_;
eBrushFalloffShape falloff_shape_;
Object *object_ = nullptr;
Curves *curves_id_ = nullptr;
CurvesGeometry *curves_ = nullptr;
@ -114,7 +112,7 @@ struct SnakeHookOperatorExecutor {
brush_radius_factor_ = brush_radius_factor(*brush_, stroke_extension);
brush_strength_ = brush_strength_get(*ctx_.scene, *brush_, stroke_extension);
falloff_shape_ = static_cast<eBrushFalloffShape>(brush_->falloff_shape);
const eBrushFalloffShape falloff_shape = eBrushFalloffShape(brush_->falloff_shape);
curves_id_ = static_cast<Curves *>(object_->data);
curves_ = &curves_id_->geometry.wrap();
@ -133,7 +131,7 @@ struct SnakeHookOperatorExecutor {
brush_pos_diff_re_ = brush_pos_re_ - brush_pos_prev_re_;
if (stroke_extension.is_first) {
if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
std::optional<CurvesBrush3D> brush_3d = sample_curves_3d_brush(*ctx_.depsgraph,
*ctx_.region,
*ctx_.v3d,
@ -148,10 +146,10 @@ struct SnakeHookOperatorExecutor {
return;
}
if (falloff_shape_ == PAINT_FALLOFF_SHAPE_SPHERE) {
if (falloff_shape == PAINT_FALLOFF_SHAPE_SPHERE) {
this->spherical_snake_hook_with_symmetry();
}
else if (falloff_shape_ == PAINT_FALLOFF_SHAPE_TUBE) {
else if (falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
this->projected_snake_hook_with_symmetry();
}
else {