Esempio 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;
}
Esempio 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
		);
}
Esempio n. 3
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()
					);
			}
		);
}
Esempio n. 4
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
			)
		);
}
Esempio n. 5
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()
					);
			}
		);
}