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

Code before:
		Vector<Vector3> lines;
		AABB aabb;
		aabb.position = -bs->get_size() / 2;
		aabb.size = bs->get_size();

		for (int i = 0; i < 12; i++) {
			Vector3 a, b;
			aabb.get_edge(i, a, b);
			lines.push_back(a);
			lines.push_back(b);
		}

		const Vector<Vector3> handles = helper->box_get_handles(bs->get_size());

		p_gizmo->add_lines(lines, material, false, collision_color);
		p_gizmo->add_collision_segments(lines);
		p_gizmo->add_handles(handles, handles_material);
	}

	if (Object::cast_to<CapsuleShape3D>(*s)) {
		Ref<CapsuleShape3D> cs2 = s;
		float radius = cs2->get_radius();
		float height = cs2->get_height();

		// Number of points in an octant. So there ill be 8 * points_in_octant points in total.
		// Correspond to the smoothness of the circle.
		const uint32_t points_in_octant = 45;
		const real_t inc = (Math_PI / (4 * points_in_octant));
		const real_t radius_squared = radius * radius;
		real_t r = 0;

		Vector<Vector3> points;
		//  4 verticalLines and 4 fullCircles.
		points.resize(4 * 2 + 4 * 8 * points_in_octant * 2);
		Vector3 *points_ptrw = points.ptrw();

		uint32_t index = 0;
		float y_value = height * 0.5 - radius;

		// Vertical Lines.
		points_ptrw[index++] = Vector3(0.f, y_value, radius);
		points_ptrw[index++] = Vector3(0.f, -y_value, radius);
		points_ptrw[index++] = Vector3(0.f, y_value, -radius);
		points_ptrw[index++] = Vector3(0.f, -y_value, -radius);
		points_ptrw[index++] = Vector3(radius, y_value, 0.f);
		points_ptrw[index++] = Vector3(radius, -y_value, 0.f);
		points_ptrw[index++] = Vector3(-radius, y_value, 0.f);
		points_ptrw[index++] = Vector3(-radius, -y_value, 0.f);

#define PUSH_QUARTER(from_x, from_y, to_x, to_y, y)      \
	points_ptrw[index++] = Vector3(from_x, y, from_y);   \

Review comment (suggestion):
```suggestion
		// Number of points in an octant. So there will be 8 * points_in_octant points in total.
		// Correspond to the smoothness of the circle.
```

Code after:
		Vector3 *points_ptrw = points.ptrw();

		float previous_x = radius;
		float previous_y = 0.f;

		for (uint32_t i = 0; i < points_in_octant; ++i) {
			r += inc;
			real_t x = Math::cos(r) * radius;
			real_t y = Math::sqrt(radius_squared - (x * x));

			PUSH_QUARTER(previous_x, previous_y, x, y, 0);
			PUSH_QUARTER(previous_y, previous_x, y, x, 0);

			PUSH_QUARTER_XY(previous_x, previous_y, x, y, 0);
			PUSH_QUARTER_XY(previous_y, previous_x, y, x, 0);

			PUSH_QUARTER_YZ(previous_x, previous_y, x, y, 0);
			PUSH_QUARTER_YZ(previous_y, previous_x, y, x, 0)

			previous_x = x;
			previous_y = y;
		}
#undef PUSH_QUARTER
#undef PUSH_QUARTER_XY
#undef PUSH_QUARTER_YZ

		p_gizmo->add_lines(points, material, false, collision_color);
		p_gizmo->add_collision_segments(points);
		Vector<Vector3> handles;
		handles.push_back(Vector3(r, 0, 0));
		p_gizmo->add_handles(handles, handles_material);
	}

	if (Object::cast_to<BoxShape3D>(*s)) {
		Ref<BoxShape3D> bs = s;
		Vector<Vector3> lines;
		AABB aabb;
		aabb.position = -bs->get_size() / 2;
		aabb.size = bs->get_size();

		for (int i = 0; i < 12; i++) {
			Vector3 a, b;
			aabb.get_edge(i, a, b);
			lines.push_back(a);
			lines.push_back(b);
		}

		const Vector<Vector3> handles = helper->box_get_handles(bs->get_size());

		p_gizmo->add_lines(lines, material, false, collision_color);
		p_gizmo->add_collision_segments(lines);