<commit_before>/*
 * Copyright (c) 2012-2015 <NAME> and individual contributors.
 * License: https://github.com/taylor001/crown/blob/master/LICENSE
 */

#pragma once

#include "error.h"
#include "math_types.h"
#include "matrix4x4.h"
#include "sphere.h"
#include "types.h"
#include "vector3.h"

namespace crown
{

/// Functions to manipulate AABB.
///
/// @ingroup Math
namespace aabb
{
	void reset(AABB& b);

	/// Returns the center of the box @a b.
	Vector3 center(const AABB& b);

	/// Returns the radius of the box @a b.
	float radius(const AABB& b);

	/// Returns the volume of the box @a b.
	float volume(const AABB& b);

	/// Adds @a num @a points to the box @a b, expanding its bounds if necessary.
	void add_points(AABB& b, uint32_t num, const Vector3* points);

	/// Adds @a num @a boxes to the box @a b, expanding its bounds if necessary.
	void add_boxes(AABB& b, uint32_t num, const AABB* boxes);

	/// Returns whether point @a p is contained in the box @a b.
	bool contains_point(const AABB& b, const Vector3& p);

	/// Returns the @a index -th vertex of the box.
	Vector3 vertex(const AABB& b, uint32_t index);

	/// Returns the box enclosing @a b transformed by @a m.
	AABB transformed(const AABB& b, const Matrix4x4& m);

	/// Returns the eight vertices of the box @a b.
	void to_vertices(const AABB& b, Vector3 v[8]);

	/// Returns the sphere enclosing the box @a b.
	Sphere to_sphere(const AABB& b);
}

namespace aabb
{
	inline void reset(AABB& b)
	{
		b.min = vector3::ZERO;
		b.max = vector3::ZERO;
	}

	inline Vector3 center(const AABB& b)
	{
		return (b.min + b.max) * 0.5;
	}

	inline float radius(const AABB& b)
	{
		return vector3::length(b.max - (b.min + b.max) * 0.5);
	}
	inline float volume(const AABB& b)
	{
		return (b.max.x - b.min.x) * (b.max.y - b.min.y) * (b.max.z - b.min.z);
	}

	inline void add_points(AABB& b, uint32_t num, const Vector3* points)
	{
		for (uint32_t i = 0; i < num; i++)
		{
			const Vector3& p = points[i];

			if (p.x < b.min.x) b.min.x = p.x;
			if (p.y < b.min.y) b.min.y = p.y;
			if (p.z < b.min.z) b.min.z = p.z;
			if (p.x > b.max.x) b.max.x = p.x;
			if (p.y > b.max.y) b.max.y = p.y;
			if (p.z > b.max.z) b.max.z = p.z;
		}
	}

	inline void add_boxes(AABB& b, uint32_t num, const AABB* boxes)
	{
		for (uint32_t i = 0; i < num; i++)
		{
			const AABB& box = boxes[i];

			if (box.min.x < b.min.x) b.min.x = box.min.x;
			if (box.min.y < b.min.y) b.min.y = box.min.y;
			if (box.min.z < b.min.z) b.min.z = box.min.z;
			if (box.max.x > b.max.x) b.max.x = box.max.x;
			if (box.max.y > b.max.y) b.max.y = box.max.y;
			if (box.max.z > b.max.z) b.max.z = box.max.z;
		}
	}

	inline bool contains_point(const AABB& b, const Vector3& p)
	{
		return (p.x > b.min.x &&
				p.y > b.min.y &&
				p.z > b.min.z &&
				p.x < b.max.x &&
				p.y < b.max.y &&
				p.z < b.max.z);
	}

	inline Vector3 vertex(const AABB& b, uint32_t index)
	{
		switch (index)
		{
			case 0: return Vector3(b.min.x, b.min.y, b.min.z);
			case 1: return Vector3(b.max.x, b.min.y, b.min.z);
			case 2: return Vector3(b.max.x, b.min.y, b.max.z);
			case 3: return Vector3(b.min.x, b.min.y, b.max.z);
			case 4: return Vector3(b.min.x, b.max.y, b.min.z);
			case 5: return Vector3(b.max.x, b.max.y, b.min.z);
			case 6: return Vector3(b.max.x, b.max.y, b.max.z);
			case 7: return Vector3(b.min.x, b.max.y, b.max.z);
			default: CE_FATAL("Bad index"); return Vector3(0.0f, 0.0f, 0.0f);
		}
	}

	inline AABB transformed(const AABB& b, const Matrix4x4& m)
	{<commit_msg>Cleanup<commit_after>/*
 * Copyright (c) 2012-2015 <NAME> and individual contributors.
 * License: https://github.com/taylor001/crown/blob/master/LICENSE
 */

#pragma once

#include "error.h"
#include "math_types.h"
#include "matrix4x4.h"
#include "sphere.h"
#include "types.h"
#include "vector3.h"

namespace crown
{

/// Functions to manipulate AABB.
///
/// @ingroup Math
namespace aabb
{
	void reset(AABB& b);

	/// Returns the center of the box @a b.
	Vector3 center(const AABB& b);

	/// Returns the radius of the box @a b.
	float radius(const AABB& b);

	/// Returns the volume of the box @a b.
	float volume(const AABB& b);

	/// Adds @a num @a points to the box @a b, expanding its bounds if necessary.
	void add_points(AABB& b, uint32_t num, const Vector3* points);

	/// Adds @a num @a boxes to the box @a b, expanding its bounds if necessary.
	void add_boxes(AABB& b, uint32_t num, const AABB* boxes);

	/// Returns whether point @a p is contained in the box @a b.
	bool contains_point(const AABB& b, const Vector3& p);

	/// Returns the @a index -th vertex of the box.
	Vector3 vertex(const AABB& b, uint32_t index);

	/// Returns the box enclosing @a b transformed by @a m.
	AABB transformed(const AABB& b, const Matrix4x4& m);

	/// Returns the eight vertices of the box @a b.
	void to_vertices(const AABB& b, Vector3 v[8]);

	/// Returns the sphere enclosing the box @a b.
	Sphere to_sphere(const AABB& b);
}

namespace aabb
{
	inline void reset(AABB& b)
	{
		b.min = vector3::ZERO;
		b.max = vector3::ZERO;
	}

	inline Vector3 center(const AABB& b)
	{
		return (b.min + b.max) * 0.5f;
	}

	inline float radius(const AABB& b)
	{
		return vector3::length(b.max - (b.min + b.max) * 0.5f);
	}
	inline float volume(const AABB& b)
	{
		return (b.max.x - b.min.x) * (b.max.y - b.min.y) * (b.max.z - b.min.z);
	}

	inline void add_points(AABB& b, uint32_t num, const Vector3* points)
	{
		for (uint32_t i = 0; i < num; ++i)
		{
			const Vector3& p = points[i];

			if (p.x < b.min.x) b.min.x = p.x;
			if (p.y < b.min.y) b.min.y = p.y;
			if (p.z < b.min.z) b.min.z = p.z;
			if (p.x > b.max.x) b.max.x = p.x;
			if (p.y > b.max.y) b.max.y = p.y;
			if (p.z > b.max.z) b.max.z = p.z;
		}
	}

	inline void add_boxes(AABB& b, uint32_t num, const AABB* boxes)
	{
		for (uint32_t i = 0; i < num; ++i)
		{
			const AABB& box = boxes[i];

			if (box.min.x < b.min.x) b.min.x = box.min.x;
			if (box.min.y < b.min.y) b.min.y = box.min.y;
			if (box.min.z < b.min.z) b.min.z = box.min.z;
			if (box.max.x > b.max.x) b.max.x = box.max.x;
			if (box.max.y > b.max.y) b.max.y = box.max.y;
			if (box.max.z > b.max.z) b.max.z = box.max.z;
		}
	}

	inline bool contains_point(const AABB& b, const Vector3& p)
	{
		return (p.x > b.min.x
			&& p.y > b.min.y
			&& p.z > b.min.z
			&& p.x < b.max.x
			&& p.y < b.max.y
			&& p.z < b.max.z
		);
	}

	inline Vector3 vertex(const AABB& b, uint32_t index)
	{
		switch (index)
		{
			case 0: return Vector3(b.min.x, b.min.y, b.min.z);
			case 1: return Vector3(b.max.x, b.min.y, b.min.z);
			case 2: return Vector3(b.max.x, b.min.y, b.max.z);
			case 3: return Vector3(b.min.x, b.min.y, b.max.z);
			case 4: return Vector3(b.min.x, b.max.y, b.min.z);
			case 5: return Vector3(b.max.x, b.max.y, b.min.z);
			case 6: return Vector3(b.max.x, b.max.y, b.max.z);
			case 7: return Vector3(b.min.x, b.max.y, b.max.z);
			default: CE_FATAL("Bad index"); return Vector3(0.0f, 0.0f, 0.0f);
		}
	}

	inline AABB transformed(const AABB& b, const Matrix4x4& m)
	{
{'fraction_non_alphanumeric': 0.17692527912968795, 'fraction_numerical': 0.022044088176352707, 'mean_word_length': 2.6183324702226827, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5246520', 'n_tokens_mistral': 3384, 'n_tokens_neox': 3111, 'n_words': 862}