ronantakizawa/codereview-bench huggingface dataset:
Repository: godotengine/godot
File: core/object/object.h (C/C++)

Code before:
		spin_lock.lock();

		uint64_t validator = (id >> OBJECTDB_SLOT_MAX_COUNT_BITS) & OBJECTDB_VALIDATOR_MASK;

		if (unlikely(object_slots[slot].validator != validator)) {
			spin_lock.unlock();
			return nullptr;
		}

		Object *object = object_slots[slot].object;

		spin_lock.unlock();

		return object;
	}

public:
	typedef void (*DebugFunc)(Object *p_obj);

	_ALWAYS_INLINE_ static Object *get_instance(ObjectID p_instance_id) {
		return _get_instance(p_instance_id);
	}

	template <typename T>
	_ALWAYS_INLINE_ static T *get_instance(ObjectID p_instance_id) {
		return Object::cast_to<T>(_get_instance(p_instance_id));
	}

	template <typename T>
	_ALWAYS_INLINE_ static Ref<T> get_ref(ObjectID p_instance_id); // Defined in ref_counted.h

	static void debug_objects(DebugFunc p_func);
	static int get_object_count();
};


Review comment (suggestion):
This is pretty unusual (defining a function in another object file than the header itself), so I'm very grateful for your comment.

To me this screams defining `ObjectDB` outside `object.h` (into its own header), but this is definitely out of scope for this PR.
So I think your workaround is acceptable. I certainly can't think of a better solution 😅

Code after:

		ERR_FAIL_COND_V(slot >= slot_max, nullptr); // This should never happen unless RID is corrupted.

		spin_lock.lock();

		uint64_t validator = (id >> OBJECTDB_SLOT_MAX_COUNT_BITS) & OBJECTDB_VALIDATOR_MASK;

		if (unlikely(object_slots[slot].validator != validator)) {
			spin_lock.unlock();
			return nullptr;
		}

		Object *object = object_slots[slot].object;

		spin_lock.unlock();

		return object;
	}

	template <typename T>
	_ALWAYS_INLINE_ static T *get_instance(ObjectID p_instance_id) {
		return Object::cast_to<T>(get_instance(p_instance_id));
	}

	template <typename T>
	_ALWAYS_INLINE_ static Ref<T> get_ref(ObjectID p_instance_id); // Defined in ref_counted.h

	static void debug_objects(DebugFunc p_func);
	static int get_object_count();
};
Repository: godotengine/godot
File: scene/2d/camera_2d.cpp (C++)

Code before:
	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_limits"), "set_limit_drawing_enabled", "is_limit_drawing_enabled");
	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_drag_margin"), "set_margin_drawing_enabled", "is_margin_drawing_enabled");

	BIND_ENUM_CONSTANT(ANCHOR_MODE_FIXED_TOP_LEFT);
	BIND_ENUM_CONSTANT(ANCHOR_MODE_DRAG_CENTER);
	BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_PHYSICS);
	BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_IDLE);
}

Camera2D::Camera2D() {
	limit[SIDE_LEFT] = -10000000;
	limit[SIDE_TOP] = -10000000;
	limit[SIDE_RIGHT] = 10000000;
	limit[SIDE_BOTTOM] = 10000000;

	drag_margin[SIDE_LEFT] = 0.2;
	drag_margin[SIDE_TOP] = 0.2;
	drag_margin[SIDE_RIGHT] = 0.2;
	drag_margin[SIDE_BOTTOM] = 0.2;

	set_notify_transform(true);
	set_hide_clip_children(true);

	add_user_signal(MethodInfo("_camera_limit_enabled_updated")); // Camera2DEditorPlugin listens to this
}


Review comment (suggestion):
```suggestion
#idfef TOOLS_ENABLED
	add_user_signal(MethodInfo("_camera_limit_enabled_updated")); // Used by Camera2DEditorPlugin.
#endif
```

Code after:
	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_screen"), "set_screen_drawing_enabled", "is_screen_drawing_enabled");
	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_limits"), "set_limit_drawing_enabled", "is_limit_drawing_enabled");
	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_draw_drag_margin"), "set_margin_drawing_enabled", "is_margin_drawing_enabled");

	BIND_ENUM_CONSTANT(ANCHOR_MODE_FIXED_TOP_LEFT);
	BIND_ENUM_CONSTANT(ANCHOR_MODE_DRAG_CENTER);
	BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_PHYSICS);
	BIND_ENUM_CONSTANT(CAMERA2D_PROCESS_IDLE);
}

Camera2D::Camera2D() {
	limit[SIDE_LEFT] = -10000000;
	limit[SIDE_TOP] = -10000000;
	limit[SIDE_RIGHT] = 10000000;
	limit[SIDE_BOTTOM] = 10000000;

	drag_margin[SIDE_LEFT] = 0.2;
	drag_margin[SIDE_TOP] = 0.2;
	drag_margin[SIDE_RIGHT] = 0.2;
	drag_margin[SIDE_BOTTOM] = 0.2;

	set_notify_transform(true);
	set_hide_clip_children(true);

#ifdef TOOLS_ENABLED
	add_user_signal(MethodInfo("_camera_limit_enabled_updated")); // Camera2DEditorPlugin listens to this
#endif
}
Repository: godotengine/godot
File: scene/2d/camera_2d.cpp (C++)

Code before:

Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
	return anchor_mode;
}

void Camera2D::set_ignore_rotation(bool p_ignore) {
	ignore_rotation = p_ignore;
	Point2 old_smoothed_camera_pos = smoothed_camera_pos;

	// Reset back to zero so it matches the camera rotation when ignore_rotation is enabled.
	if (ignore_rotation) {
		camera_angle = 0.0;
	}

	_update_scroll();
	smoothed_camera_pos = old_smoothed_camera_pos;
}

bool Camera2D::is_ignoring_rotation() const {
	return ignore_rotation;
}

void Camera2D::set_limit_enabled(bool p_limit_enabled) {
	limit_enabled = p_limit_enabled;
	_update_scroll();
	emit_signal("_camera_limit_enabled_updated"); // Used for Camera2DEditorPlugin
	notify_property_list_changed();
}

bool Camera2D::is_limit_enabled() const {
	return limit_enabled;
}

void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
	if (process_callback == p_mode) {
		return;
	}

	process_callback = p_mode;
	_update_process_callback();
}

void Camera2D::set_enabled(bool p_enabled) {
	enabled = p_enabled;

	if (!is_inside_tree()) {
		return;
	}

	if (enabled && !viewport->get_camera_2d()) {
		make_current();

Review comment (suggestion):
```suggestion
#ifdef TOOLS_ENABLED
	emit_signal("_camera_limit_enabled_updated");
#endif
```

Code after:

void Camera2D::set_ignore_rotation(bool p_ignore) {
	ignore_rotation = p_ignore;
	Point2 old_smoothed_camera_pos = smoothed_camera_pos;

	// Reset back to zero so it matches the camera rotation when ignore_rotation is enabled.
	if (ignore_rotation) {
		camera_angle = 0.0;
	}

	_update_scroll();
	smoothed_camera_pos = old_smoothed_camera_pos;
}

bool Camera2D::is_ignoring_rotation() const {
	return ignore_rotation;
}

void Camera2D::set_limit_enabled(bool p_limit_enabled) {
	if (p_limit_enabled == limit_enabled) {
		return;
	}
	limit_enabled = p_limit_enabled;
	_update_scroll();
#ifdef TOOLS_ENABLED
	emit_signal("_camera_limit_enabled_updated"); // Used for Camera2DEditorPlugin
#endif
	notify_property_list_changed();
}

bool Camera2D::is_limit_enabled() const {
	return limit_enabled;
}

void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
	if (process_callback == p_mode) {
		return;
	}

	process_callback = p_mode;
	_update_process_callback();
}

void Camera2D::set_enabled(bool p_enabled) {
	enabled = p_enabled;

	if (!is_inside_tree()) {
		return;
	}

	if (enabled && !viewport->get_camera_2d()) {
Repository: godotengine/godot
File: scene/2d/camera_2d.cpp (C++)

Code before:
	anchor_mode = p_anchor_mode;
	_update_scroll();
}

Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
	return anchor_mode;
}

void Camera2D::set_ignore_rotation(bool p_ignore) {
	ignore_rotation = p_ignore;
	Point2 old_smoothed_camera_pos = smoothed_camera_pos;

	// Reset back to zero so it matches the camera rotation when ignore_rotation is enabled.
	if (ignore_rotation) {
		camera_angle = 0.0;
	}

	_update_scroll();
	smoothed_camera_pos = old_smoothed_camera_pos;
}

bool Camera2D::is_ignoring_rotation() const {
	return ignore_rotation;
}

void Camera2D::set_limit_enabled(bool p_limit_enabled) {
	limit_enabled = p_limit_enabled;
	_update_scroll();
	emit_signal("_camera_limit_enabled_updated"); // Used for Camera2DEditorPlugin
	notify_property_list_changed();
}

bool Camera2D::is_limit_enabled() const {
	return limit_enabled;
}

void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
	if (process_callback == p_mode) {
		return;
	}

	process_callback = p_mode;
	_update_process_callback();
}

void Camera2D::set_enabled(bool p_enabled) {
	enabled = p_enabled;

	if (!is_inside_tree()) {
		return;
	}

Review comment (suggestion):
```suggestion
	if (p_limit_enabled == limit_enabled) {
		return;
	}
	limit_enabled = p_limit_enabled;
```

Code after:
Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
	return anchor_mode;
}

void Camera2D::set_ignore_rotation(bool p_ignore) {
	ignore_rotation = p_ignore;
	Point2 old_smoothed_camera_pos = smoothed_camera_pos;

	// Reset back to zero so it matches the camera rotation when ignore_rotation is enabled.
	if (ignore_rotation) {
		camera_angle = 0.0;
	}

	_update_scroll();
	smoothed_camera_pos = old_smoothed_camera_pos;
}

bool Camera2D::is_ignoring_rotation() const {
	return ignore_rotation;
}

void Camera2D::set_limit_enabled(bool p_limit_enabled) {
	if (p_limit_enabled == limit_enabled) {
		return;
	}
	limit_enabled = p_limit_enabled;
	_update_scroll();
#ifdef TOOLS_ENABLED
	emit_signal("_camera_limit_enabled_updated"); // Used for Camera2DEditorPlugin
#endif
	notify_property_list_changed();
}

bool Camera2D::is_limit_enabled() const {
	return limit_enabled;
}

void Camera2D::set_process_callback(Camera2DProcessCallback p_mode) {
	if (process_callback == p_mode) {
		return;
	}

	process_callback = p_mode;
	_update_process_callback();
}

void Camera2D::set_enabled(bool p_enabled) {
	enabled = p_enabled;

	if (!is_inside_tree()) {
		return;
Repository: godotengine/godot
File: editor/plugins/tiles/tile_map_layer_editor.h (C/C++)

Code before:
#include "scene/gui/tab_bar.h"
#include "scene/gui/tree.h"

class TileMapLayerEditor;

class TileMapLayerSubEditorPlugin : public Object {
protected:
	ObjectID edited_tile_map_layer_id;
	TileMapLayer *_get_edited_layer() const;

public:
	struct TabData {
		Control *toolbar = nullptr;
		Control *panel = nullptr;
	};

	virtual Vector<TabData> get_tabs() const {
		return Vector<TabData>();
	}

	virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return false; }
	virtual void forward_canvas_draw_over_viewport(Control *p_overlay) {}
	virtual void tile_set_changed() {}
	virtual void edit(ObjectID p_tile_map_layer_id) {}
};

class TileMapLayerEditorTilesPlugin : public TileMapLayerSubEditorPlugin {
	GDCLASS(TileMapLayerEditorTilesPlugin, TileMapLayerSubEditorPlugin);

public:
	enum {
		TRANSFORM_ROTATE_LEFT,
		TRANSFORM_ROTATE_RIGHT,
		TRANSFORM_FLIP_H,
		TRANSFORM_FLIP_V,
	};

private:
	///// Toolbar /////
	HBoxContainer *toolbar = nullptr;

	Ref<ButtonGroup> tool_buttons_group;
	Button *select_tool_button = nullptr;
	Button *paint_tool_button = nullptr;
	Button *line_tool_button = nullptr;
	Button *rect_tool_button = nullptr;
	Button *bucket_tool_button = nullptr;

	HBoxContainer *tools_settings = nullptr;

	VSeparator *tools_settings_vsep = nullptr;

Review comment (suggestion):
```suggestion
	virtual void draw_tile_coords_over_viewport(Control *p_overlay, const TileMapLayer *p_edited_layer, Ref<TileSet> p_tile_set, bool p_show_rectangle_size, Vector2i p_rectangle_origin);
```

Code after:
#include "scene/gui/tab_bar.h"
#include "scene/gui/tree.h"

class TileMapLayerEditor;

class TileMapLayerSubEditorPlugin : public Object {
protected:
	ObjectID edited_tile_map_layer_id;
	TileMapLayer *_get_edited_layer() const;

public:
	struct TabData {
		Control *toolbar = nullptr;
		Control *panel = nullptr;
	};

	virtual Vector<TabData> get_tabs() const {
		return Vector<TabData>();
	}

	virtual bool forward_canvas_gui_input(const Ref<InputEvent> &p_event) { return false; }
	virtual void forward_canvas_draw_over_viewport(Control *p_overlay) {}
	virtual void tile_set_changed() {}
	virtual void edit(ObjectID p_tile_map_layer_id) {}
	virtual void draw_tile_coords_over_viewport(Control *p_overlay, const TileMapLayer *p_edited_layer, Ref<TileSet> p_tile_set, bool p_show_rectangle_size, const Vector2i &p_rectangle_origin);
};

class TileMapLayerEditorTilesPlugin : public TileMapLayerSubEditorPlugin {
	GDCLASS(TileMapLayerEditorTilesPlugin, TileMapLayerSubEditorPlugin);

public:
	enum {
		TRANSFORM_ROTATE_LEFT,
		TRANSFORM_ROTATE_RIGHT,
		TRANSFORM_FLIP_H,
		TRANSFORM_FLIP_V,
	};

private:
	///// Toolbar /////
	HBoxContainer *toolbar = nullptr;

	Ref<ButtonGroup> tool_buttons_group;
	Button *select_tool_button = nullptr;
	Button *paint_tool_button = nullptr;
	Button *line_tool_button = nullptr;
	Button *rect_tool_button = nullptr;
	Button *bucket_tool_button = nullptr;

	HBoxContainer *tools_settings = nullptr;
Repository: godotengine/godot
File: core/templates/cowdata.h (C/C++)

Code before:
		}

		*_get_size() = p_size;
	}

	return OK;
}

template <typename T>
Error CowData<T>::_realloc(Size p_alloc_size) {
	uint8_t *mem_new = (uint8_t *)Memory::realloc_static(((uint8_t *)_ptr) - DATA_OFFSET, p_alloc_size + DATA_OFFSET, false);
	ERR_FAIL_NULL_V(mem_new, ERR_OUT_OF_MEMORY);

	SafeNumeric<USize> *_refc_ptr = _get_refcount_ptr(mem_new);
	T *_data_ptr = _get_data_ptr(mem_new);

	// If we realloc, we're guaranteed to be the only reference.
	new (_refc_ptr) SafeNumeric<USize>(1);
	_ptr = _data_ptr;

	return OK;
}

template <typename T>
typename CowData<T>::Size CowData<T>::find(const T &p_val, Size p_from) const {
	Size ret = -1;

	if (p_from < 0 || size() == 0) {
		return ret;
	}

	for (Size i = p_from; i < size(); i++) {
		if (get(i) == p_val) {
			ret = i;
			break;
		}
	}

	return ret;
}

template <typename T>
typename CowData<T>::Size CowData<T>::rfind(const T &p_val, Size p_from) const {
	const Size s = size();

	if (p_from < 0) {
		p_from = s + p_from;
	}
	if (p_from < 0 || p_from >= s) {
		p_from = s - 1;
	}

Review comment (performance):
The use of `ret` here should most likely be optimized out, but it's cleaner this way and also matches `rfind`

Code after:
		}

		*_get_size() = p_size;
	}

	return OK;
}

template <typename T>
Error CowData<T>::_realloc(Size p_alloc_size) {
	uint8_t *mem_new = (uint8_t *)Memory::realloc_static(((uint8_t *)_ptr) - DATA_OFFSET, p_alloc_size + DATA_OFFSET, false);
	ERR_FAIL_NULL_V(mem_new, ERR_OUT_OF_MEMORY);

	SafeNumeric<USize> *_refc_ptr = _get_refcount_ptr(mem_new);
	T *_data_ptr = _get_data_ptr(mem_new);

	// If we realloc, we're guaranteed to be the only reference.
	new (_refc_ptr) SafeNumeric<USize>(1);
	_ptr = _data_ptr;

	return OK;
}

template <typename T>
typename CowData<T>::Size CowData<T>::find(const T &p_val, Size p_from) const {
	if (p_from < 0) {
		return -1;
	}

	const Size s = size();

	for (Size i = p_from; i < s; i++) {
		if (_ptr[i] == p_val) {
			return i;
		}
	}

	return -1;
}

template <typename T>
typename CowData<T>::Size CowData<T>::rfind(const T &p_val, Size p_from) const {
	const Size s = size();

	if (p_from < 0) {
		p_from = s + p_from;
	}
	if (p_from < 0 || p_from >= s) {
		p_from = s - 1;
	}
Repository: godotengine/godot
File: core/templates/cowdata.h (C/C++)

Code before:
}

template <typename T>
Error CowData<T>::_realloc(Size p_alloc_size) {
	uint8_t *mem_new = (uint8_t *)Memory::realloc_static(((uint8_t *)_ptr) - DATA_OFFSET, p_alloc_size + DATA_OFFSET, false);
	ERR_FAIL_NULL_V(mem_new, ERR_OUT_OF_MEMORY);

	SafeNumeric<USize> *_refc_ptr = _get_refcount_ptr(mem_new);
	T *_data_ptr = _get_data_ptr(mem_new);

	// If we realloc, we're guaranteed to be the only reference.
	new (_refc_ptr) SafeNumeric<USize>(1);
	_ptr = _data_ptr;

	return OK;
}

template <typename T>
typename CowData<T>::Size CowData<T>::find(const T &p_val, Size p_from) const {
	Size ret = -1;

	if (p_from < 0 || size() == 0) {
		return ret;
	}

	for (Size i = p_from; i < size(); i++) {
		if (get(i) == p_val) {
			ret = i;
			break;
		}
	}

	return ret;
}

template <typename T>
typename CowData<T>::Size CowData<T>::rfind(const T &p_val, Size p_from) const {
	const Size s = size();

	if (p_from < 0) {
		p_from = s + p_from;
	}
	if (p_from < 0 || p_from >= s) {
		p_from = s - 1;
	}

	for (Size i = p_from; i >= 0; i--) {
		if (get(i) == p_val) {
			return i;
		}
	}

Review comment (suggestion):
Maybe do this ? 

```
if (p_from < 0) {
return -1;
}

const Size s = size();
```
As getting the size is not free, and if it's 0, it will go over the loop anyway. 
Not sure it will make any difference.

Code after:
}

template <typename T>
Error CowData<T>::_realloc(Size p_alloc_size) {
	uint8_t *mem_new = (uint8_t *)Memory::realloc_static(((uint8_t *)_ptr) - DATA_OFFSET, p_alloc_size + DATA_OFFSET, false);
	ERR_FAIL_NULL_V(mem_new, ERR_OUT_OF_MEMORY);

	SafeNumeric<USize> *_refc_ptr = _get_refcount_ptr(mem_new);
	T *_data_ptr = _get_data_ptr(mem_new);

	// If we realloc, we're guaranteed to be the only reference.
	new (_refc_ptr) SafeNumeric<USize>(1);
	_ptr = _data_ptr;

	return OK;
}

template <typename T>
typename CowData<T>::Size CowData<T>::find(const T &p_val, Size p_from) const {
	if (p_from < 0) {
		return -1;
	}

	const Size s = size();

	for (Size i = p_from; i < s; i++) {
		if (_ptr[i] == p_val) {
			return i;
		}
	}

	return -1;
}

template <typename T>
typename CowData<T>::Size CowData<T>::rfind(const T &p_val, Size p_from) const {
	const Size s = size();

	if (p_from < 0) {
		p_from = s + p_from;
	}
	if (p_from < 0 || p_from >= s) {
		p_from = s - 1;
	}

	for (Size i = p_from; i >= 0; i--) {
		if (_ptr[i] == p_val) {
			return i;
		}
	}
	return -1;
Repository: godotengine/godot
File: editor/scene/3d/path_3d_editor_plugin.h (C/C++)

Code before:
		ACTION_CLOSE
	};

	Path3D *path = nullptr;

	void _update_theme();
	void _update_toolbar();

	void _mode_changed(int p_mode);
	void _toggle_closed_curve();
	void _handle_option_pressed(int p_option);
	bool handle_clicked = false;
	bool mirror_handle_angle = true;
	bool mirror_handle_length = true;
	bool snap_to_collider = true;

	void _create_curve();
	void _confirm_clear_points();
	void _clear_points();
	void _clear_curve_points();
	void _restore_curve_points(const PackedVector3Array &p_points);

	enum HandleOption {
		HANDLE_OPTION_ANGLE,
		HANDLE_OPTION_LENGTH,
		HANDLE_OPTION_SNAP_COLLIDER
	};

protected:
	static void _bind_methods();

public:
	Path3D *get_edited_path() { return path; }

	inline static Path3DEditorPlugin *singleton = nullptr;
	virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;

	virtual String get_plugin_name() const override { return "Path3D"; }
	bool has_main_screen() const override { return false; }
	virtual void edit(Object *p_object) override;
	virtual bool handles(Object *p_object) const override;
	virtual void make_visible(bool p_visible) override;

	bool mirror_angle_enabled() { return mirror_handle_angle; }
	bool mirror_length_enabled() { return mirror_handle_length; }
	bool is_handle_clicked() { return handle_clicked; }
	void set_handle_clicked(bool clicked) { handle_clicked = clicked; }

	Path3DEditorPlugin();
};


Review comment (suggestion):
```suggestion
		HANDLE_OPTION_SNAP_COLLIDER,
```

Code after:
	void _update_theme();
	void _update_toolbar();

	void _mode_changed(int p_mode);
	void _toggle_closed_curve();
	void _handle_option_pressed(int p_option);
	bool handle_clicked = false;
	bool mirror_handle_angle = true;
	bool mirror_handle_length = true;
	bool snap_to_collider = true;

	void _create_curve();
	void _confirm_clear_points();
	void _clear_points();
	void _clear_curve_points();
	void _restore_curve_points(const PackedVector3Array &p_points);

	enum HandleOption {
		HANDLE_OPTION_ANGLE,
		HANDLE_OPTION_LENGTH,
		HANDLE_OPTION_SNAP_COLLIDER,
	};

protected:
	virtual void _notification(int p_what);
	static void _bind_methods();

public:
	Path3D *get_edited_path() { return path; }

	inline static Path3DEditorPlugin *singleton = nullptr;
	virtual EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override;

	virtual String get_plugin_name() const override { return "Path3D"; }
	bool has_main_screen() const override { return false; }
	virtual void edit(Object *p_object) override;
	virtual bool handles(Object *p_object) const override;
	virtual void make_visible(bool p_visible) override;

	bool mirror_angle_enabled() { return mirror_handle_angle; }
	bool mirror_length_enabled() { return mirror_handle_length; }
	bool is_handle_clicked() { return handle_clicked; }
	void set_handle_clicked(bool clicked) { handle_clicked = clicked; }

	Path3DEditorPlugin();

private:
	struct EditData {
		Vector3 click_ray_dir;
		Vector3 click_ray_pos;
		Vector3 origin;
Repository: godotengine/godot
File: editor/plugins/node_3d_editor_plugin.cpp (C++)

Code before:
		}

		center += sp->get_global_gizmo_transform().origin;
		count++;
	}

	if (count != 0) {
		center /= count;
	}

	cursor.pos = center;
}

void Node3DEditorViewport::assign_pending_data_pointers(Node3D *p_preview_node, AABB *p_preview_bounds, AcceptDialog *p_accept) {
	preview_node = p_preview_node;
	preview_bounds = p_preview_bounds;
	accept = p_accept;
}

void _insert_rid_recursive(Node *node, HashSet<RID> &rids) {
	CollisionObject3D *co = Object::cast_to<CollisionObject3D>(node);
	if (co) {
		rids.insert(co->get_rid());
	}

	if (node->is_class("CSGShape3D")) {
		rids.insert(node->call("_get_root_collision_instance"));
	}

	for (int i = 0; i < node->get_child_count(); i++) {
		Node *child = node->get_child(i);
		_insert_rid_recursive(child, rids);
	}
}

Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos, Node3D *p_node) const {
	const float MAX_DISTANCE = 50.0;
	const float FALLBACK_DISTANCE = 5.0;

	Vector3 world_ray = get_ray(p_pos);
	Vector3 world_pos = get_ray_pos(p_pos);

	PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();

	HashSet<RID> rids;

	if (!preview_node->is_inside_tree() && !ruler->is_inside_tree()) {
		List<Node *> &selection = editor_selection->get_selected_node_list();

		Node3D *first_selected_node = Object::cast_to<Node3D>(selection.front()->get());


Review comment (suggestion):
```suggestion
	} else if (node->is_class("CSGShape3D")) {
```
These conditions are mutually exclusive, so no reason to check both.

Code after:
		}

		center += sp->get_global_gizmo_transform().origin;
		count++;
	}

	if (count != 0) {
		center /= count;
	}

	cursor.pos = center;
}

void Node3DEditorViewport::assign_pending_data_pointers(Node3D *p_preview_node, AABB *p_preview_bounds, AcceptDialog *p_accept) {
	preview_node = p_preview_node;
	preview_bounds = p_preview_bounds;
	accept = p_accept;
}

void _insert_rid_recursive(Node *node, HashSet<RID> &rids) {
	CollisionObject3D *co = Object::cast_to<CollisionObject3D>(node);

	if (co) {
		rids.insert(co->get_rid());
	} else if (node->is_class("CSGShape3D")) { // HACK: We should avoid referencing module logic.
		rids.insert(node->call("_get_root_collision_instance"));
	}

	for (int i = 0; i < node->get_child_count(); i++) {
		Node *child = node->get_child(i);
		_insert_rid_recursive(child, rids);
	}
}

Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos, Node3D *p_node) const {
	const float MAX_DISTANCE = 50.0;
	const float FALLBACK_DISTANCE = 5.0;

	Vector3 world_ray = get_ray(p_pos);
	Vector3 world_pos = get_ray_pos(p_pos);

	PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();

	HashSet<RID> rids;

	if (!preview_node->is_inside_tree() && !ruler->is_inside_tree()) {
		List<Node *> &selection = editor_selection->get_selected_node_list();

		Node3D *first_selected_node = Object::cast_to<Node3D>(selection.front()->get());

		Array children = first_selected_node->get_children();