Repository: godotengine/godot
File: editor/plugins/gizmos/gizmo_3d_helper.cpp (C++)

Code before:
	float d = ra[p_id / 2] * sign;

	Vector3 he = r_box_size;
	he[p_id / 2] = d * 2;
	if (Node3DEditor::get_singleton()->is_snap_enabled()) {
		he[p_id / 2] = Math::snapped(he[p_id / 2], Node3DEditor::get_singleton()->get_translate_snap());
	}

	if (Input::get_singleton()->is_key_pressed(Key::ALT)) {
		he[p_id / 2] = MAX(he[p_id / 2], 0.001);
		r_box_size = he;
		r_box_position = initial_transform.get_origin();
	} else {
		he[p_id / 2] = MAX(he[p_id / 2], -initial_size[p_id / 2] + 0.002);
		r_box_size = (initial_size + (he - initial_size) * 0.5).abs();
		Vector3 pos = initial_transform.affine_inverse().xform(initial_transform.get_origin());
		pos += (r_box_size - initial_size) * 0.5 * sign;
		r_box_position = initial_transform.xform(pos);
	}
}

void Gizmo3DHelper::box_commit_handle(const String &p_action_name, bool p_cancel, Object *p_position_object, Object *p_size_object, const StringName &p_position_property, const StringName &p_size_property) {
	if (!p_size_object) {
		p_size_object = p_position_object;
	}

	if (p_cancel) {
		p_size_object->set(p_size_property, initial_value);
		p_position_object->set(p_position_property, initial_transform.get_origin());
		return;
	}

	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
	ur->create_action(p_action_name);
	ur->add_do_property(p_size_object, p_size_property, p_size_object->get(p_size_property));
	ur->add_do_property(p_position_object, p_position_property, p_position_object->get(p_position_property));
	ur->add_undo_property(p_size_object, p_size_property, initial_value);
	ur->add_undo_property(p_position_object, p_position_property, initial_transform.get_origin());
	ur->commit_action();
}


Review comment (suggestion):
Vectors are default initialized to zero already.
```suggestion
		Vector3 offset;
```

Code after:

	// Calculate new size.
	r_box_size = initial_size;
	if (Input::get_singleton()->is_key_pressed(Key::ALT)) {
		r_box_size[axis] = ra[axis] * sign * 2;
	} else {
		r_box_size[axis] = sign > 0 ? ra[axis] - neg_end : pos_end - ra[axis];
	}

	// Snap to grid.
	if (Node3DEditor::get_singleton()->is_snap_enabled()) {
		r_box_size[axis] = Math::snapped(r_box_size[axis], Node3DEditor::get_singleton()->get_translate_snap());
	}
	r_box_size[axis] = MAX(r_box_size[axis], 0.001);

	// Adjust position.
	if (Input::get_singleton()->is_key_pressed(Key::ALT)) {
		r_box_position = initial_transform.get_origin();
	} else {
		if (sign > 0) {
			pos_end = neg_end + r_box_size[axis];
		} else {
			neg_end = pos_end - r_box_size[axis];
		}

		Vector3 offset;
		offset[axis] = (pos_end + neg_end) * 0.5;
		r_box_position = initial_transform.xform(offset);
	}
}

void Gizmo3DHelper::box_commit_handle(const String &p_action_name, bool p_cancel, Object *p_position_object, Object *p_size_object, const StringName &p_position_property, const StringName &p_size_property) {
	if (!p_size_object) {
		p_size_object = p_position_object;
	}

	if (p_cancel) {
		p_size_object->set(p_size_property, initial_value);
		p_position_object->set(p_position_property, initial_transform.get_origin());
		return;
	}

	EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton();
	ur->create_action(p_action_name);
	ur->add_do_property(p_size_object, p_size_property, p_size_object->get(p_size_property));
	ur->add_do_property(p_position_object, p_position_property, p_position_object->get(p_position_property));
	ur->add_undo_property(p_size_object, p_size_property, initial_value);
	ur->add_undo_property(p_position_object, p_position_property, initial_transform.get_origin());
	ur->commit_action();
}