Exemplo n.º 1
0
fcppt::math::box::object<
	T,
	N
> const
intersection(
	fcppt::math::box::object<
		T,
		N
	> const &_a,
	fcppt::math::box::object<
		T,
		N
	> const &_b
)
{
	typedef
	fcppt::math::box::object<
		T,
		N
	> result_type;

	if(
		!fcppt::math::box::intersects(
			_a,
			_b
		)
	)
		return result_type::null();

	result_type ret{
		fcppt::no_init()
	};

	for(
		size_type i = 0;
		i < N;
		++i
	)
	{
		ret.pos(
			i,
			std::max(
				_a.pos(i),
				_b.pos(i)
			)
		);

		ret.size(
			i,
			std::min(
				_a.max(i),
				_b.max(i)
			)
			- ret.pos(i)
		);
	}

	return ret;
}
Exemplo n.º 2
0
fcppt::math::box::object<
	T,
	N
>
stretch_absolute(
	fcppt::math::box::object<
		T,
		N
	> const &_box,
	typename
	fcppt::math::box::object<
		T,
		N
	>::vector const &_absolute_values
)
{
	return
		fcppt::math::box::object<
			T,
			N
		>(
			_box.pos()
			-
			_absolute_values
			,
			_box.max()
			+
			_absolute_values
		);
}
Exemplo n.º 3
0
Dest
structure_cast(
	fcppt::math::box::object<
		T,
		N
	> const &_src
)
{
	static_assert(
		fcppt::math::box::is_box<
			Dest
		>::value,
		"Dest must be a box"
	);

	return
		Dest(
			fcppt::math::vector::structure_cast<
				typename Dest::vector,
				Conv
			>(
				_src.pos()
			),
			fcppt::math::dim::structure_cast<
				typename Dest::dim,
				Conv
			>(
				_src.size()
			)
		);
}
Exemplo n.º 4
0
typename
fcppt::math::box::object<
	T,
	N
>::vector
center(
	fcppt::math::box::object<
		T,
		N
	> const &_box
)
{
	return
		_box.pos()
		+
		fcppt::math::dim::to_vector(
			_box.size()
		)
		/
		fcppt::literal<
			T
		>(
			2
		);
}
Exemplo n.º 5
0
inline
bool
contains_point(
	fcppt::math::box::object<
		T,
		N
	> const &_box,
	fcppt::math::vector::object<
		T,
		N,
		S
	> const &_point
)
{
	return
		fcppt::algorithm::all_of(
			fcppt::math::int_range_count<
				N
			>{},
			[
				&_box,
				&_point
			](
				auto const _index
			)
			{
				auto const index(
					fcppt::tag_value(
						_index
					)
				);

				return
					fcppt::math::at_c<
						index
					>(
						_point
					)
					>=
					fcppt::math::at_c<
						index
					>(
						_box.pos()
					)
					&&
					fcppt::math::at_c<
						index
					>(
						_point
					)
					<
					fcppt::math::at_c<
						index
					>(
						_box.max()
					);
			}
		);
}
Exemplo n.º 6
0
inline
fcppt::homogenous_pair<
	T
>
interval(
	fcppt::math::box::object<
		T,
		N
	> const &_box,
	fcppt::math::size_type const _index
)
{
	return
		fcppt::make_homogenous_pair(
			_box.pos(
				_index
			),
			_box.max(
				_index
			)
		);
}
Exemplo n.º 7
0
fcppt::math::box::object<
	T,
	N
>
shrink(
	fcppt::math::box::object<
		T,
		N
	> const &_box,
	typename
	fcppt::math::box::object<
		T,
		N
	>::vector const &_absolute_values
)
{
	return
		fcppt::math::box::object<
			T,
			N
		>(
			_box.pos()
			+
			_absolute_values
			,
			_box.size()
			-
			fcppt::literal<
				T
			>(
				2
			)
			*
			fcppt::math::vector::to_dim(
				_absolute_values
			)
		);
}
Exemplo n.º 8
0
fcppt::math::vector::object
<
	T,
	VN,
	S
> const
wrap_point_in_torus(
	fcppt::math::vector::object
	<
		T,
		VN,
		S
	> _p,
	fcppt::math::box::object
	<
		T,
		N
	> const &_b
)
{
	typedef
	fcppt::math::vector::object
	<
		T,
		VN,
		S
	>
	vector;

	typedef typename
	vector::size_type
	size_type;

	for(
		size_type i = 0;
		i < _p.size();
		++i
	)
	{
		T const
			left =
				_b.pos()[i],
			right =
				left + _b.size()[i];

		if(
			_p[i] > right
		)
			_p[i] =
				static_cast<T>(
					left + (_p[i] - right)
				);
		else if(
			_p[i] < left
		)
			_p[i] =
				static_cast<T>(
					right - (left - _p[i])
				);
	}

	return _p;
}
Exemplo n.º 9
0
std::array<
	fcppt::math::vector::static_<
		T,
		N
	>,
	fcppt::literal<
		std::size_t
	>(
		1u
	) << N
>
corner_points(
	fcppt::math::box::object<
		T,
		N
	> const &_box
)
{
	typedef
	fcppt::math::vector::static_<
		T,
		N
	>
	vector_type;

	typedef
	std::array<
		vector_type,
		fcppt::literal<
			std::size_t
		>(
			1u
		)
		<< N
	>
	result_type;

	result_type const corners(
		fcppt::math::generate_binary_vectors<
			T,
			N
		>()
	);

	return
		fcppt::algorithm::array_init<
			result_type
		>(
			[
				&_box,
				&corners
			](
				auto const _index
			)
			{
				return
					_box.pos()
					+
					std::get<
						_index
					>(
						corners
					)
					*
					fcppt::math::dim::to_vector(
						_box.size()
					);
			}
		);
}
Exemplo n.º 10
0
inline
bool
contains(
	fcppt::math::box::object<
		T,
		N
	> const &_outer,
	fcppt::math::box::object<
		T,
		N
	> const &_inner
)
{
	return
		fcppt::algorithm::all_of(
			fcppt::math::int_range_count<
				N
			>{},
			[
				&_outer,
				&_inner
			](
				auto const _index
			)
			{
				FCPPT_USE(
					_index
				);

				typedef
				fcppt::tag_type<
					decltype(
						_index
					)
				>
				index;

				return
					fcppt::math::at_c<
						index::value
					>(
						_inner.pos()
					)
					>=
					fcppt::math::at_c<
						index::value
					>(
						_outer.pos()
					)
					&&
					fcppt::math::at_c<
						index::value
					>(
						_inner.max()
					)
					<=
					fcppt::math::at_c<
						index::value
					>(
						_outer.max()
					);
			}
		);
}