Repository: godotengine/godot
File: core/math/aabb.h (C/C++)

Code before:
	AABB expand(const Vector3 &p_vector) const;
	_FORCE_INLINE_ void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
	_FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */

	_FORCE_INLINE_ AABB abs() const {
		return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs());
	}

	Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const;
	Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;

	_FORCE_INLINE_ void quantize(real_t p_unit);
	_FORCE_INLINE_ AABB quantized(real_t p_unit) const;

	_FORCE_INLINE_ void set_end(const Vector3 &p_end) {
		size = p_end - position;
	}

	_FORCE_INLINE_ Vector3 get_end() const {
		return position + size;
	}

	operator String() const;

	_FORCE_INLINE_ AABB() {}
	inline AABB(const Vector3 &p_pos, const Vector3 &p_size) :
			position(p_pos),
			size(p_size) {
	}
};

inline bool AABB::intersects(const AABB &p_aabb) const {
	if (position.x >= (p_aabb.position.x + p_aabb.size.x)) {
		return false;
	}
	if ((position.x + size.x) <= p_aabb.position.x) {
		return false;
	}
	if (position.y >= (p_aabb.position.y + p_aabb.size.y)) {
		return false;
	}
	if ((position.y + size.y) <= p_aabb.position.y) {
		return false;
	}
	if (position.z >= (p_aabb.position.z + p_aabb.size.z)) {
		return false;
	}
	if ((position.z + size.z) <= p_aabb.position.z) {
		return false;
	}


Review comment (bug):
```
position + (size * 0.5)
```
is better imo. In nearly all cases brackets are better for readability to show order of precedence (and to prevent future bugs).
See e.g.
https://softwareengineering.stackexchange.com/questions/201175/should-i-use-parentheses-in-logical-statements-even-where-not-necessary

Code after:
	AABB expand(const Vector3 &p_vector) const;
	_FORCE_INLINE_ void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
	_FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */

	_FORCE_INLINE_ AABB abs() const {
		return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs());
	}

	Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const;
	Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const;

	_FORCE_INLINE_ void quantize(real_t p_unit);
	_FORCE_INLINE_ AABB quantized(real_t p_unit) const;

	_FORCE_INLINE_ void set_end(const Vector3 &p_end) {
		size = p_end - position;
	}

	_FORCE_INLINE_ Vector3 get_end() const {
		return position + size;
	}

	_FORCE_INLINE_ Vector3 get_center() const {
		return position + (size * 0.5);
	}

	operator String() const;

	_FORCE_INLINE_ AABB() {}
	inline AABB(const Vector3 &p_pos, const Vector3 &p_size) :
			position(p_pos),
			size(p_size) {
	}
};

inline bool AABB::intersects(const AABB &p_aabb) const {
	if (position.x >= (p_aabb.position.x + p_aabb.size.x)) {
		return false;
	}
	if ((position.x + size.x) <= p_aabb.position.x) {
		return false;
	}
	if (position.y >= (p_aabb.position.y + p_aabb.size.y)) {
		return false;
	}
	if ((position.y + size.y) <= p_aabb.position.y) {
		return false;
	}
	if (position.z >= (p_aabb.position.z + p_aabb.size.z)) {
		return false;
	}