2015-10-14 15:32:53 +11:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
2017-08-29 12:21:03 +10:00
|
|
|
* Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
|
2015-10-14 15:32:53 +11:00
|
|
|
*/
|
|
|
|
|
2017-08-29 12:21:03 +10:00
|
|
|
#include "./ellipse.hpp"
|
2015-10-14 15:32:53 +11:00
|
|
|
|
2017-08-29 12:21:03 +10:00
|
|
|
#include "./ops.hpp"
|
|
|
|
#include "./aabb.hpp"
|
2015-10-14 15:32:53 +11:00
|
|
|
|
|
|
|
using util::geom::ellipse;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <size_t S, typename T>
|
|
|
|
static bool
|
|
|
|
intersects (ellipse<S,T> e, util::point<S,T> p)
|
|
|
|
{
|
|
|
|
auto mag = (p - e.origin) * (p - e.origin) / (e.radius * e.radius);
|
|
|
|
return std::accumulate (mag.begin (), mag.end (), 0) <= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <size_t S, typename T, template <size_t,typename> class A, template <size_t,typename> class B>
|
|
|
|
bool
|
|
|
|
util::geom::intersects (A<S,T> a, B<S,T> b)
|
|
|
|
{
|
|
|
|
return ::intersects (a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template bool util::geom::intersects (ellipse<2,float>, util::point<2,float>);
|
|
|
|
template bool util::geom::intersects (ellipse<3,float>, util::point<3,float>);
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <size_t S, typename T>
|
2017-08-24 16:43:54 +10:00
|
|
|
static util::geom::aabb<S,T>
|
2015-10-14 15:32:53 +11:00
|
|
|
bounds (ellipse<S,T> e)
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
e.origin - e.radius,
|
|
|
|
e.origin + e.radius
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template <size_t S, typename T, template <size_t,typename> class K>
|
2017-08-24 16:43:54 +10:00
|
|
|
util::geom::aabb<S,T>
|
2015-10-14 15:32:53 +11:00
|
|
|
util::geom::bounds (K<S,T> k)
|
|
|
|
{
|
|
|
|
return ::bounds (k);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-08-24 16:43:54 +10:00
|
|
|
template util::geom::aabb<2,float> util::geom::bounds (ellipse<2,float>);
|
|
|
|
template util::geom::aabb<3,float> util::geom::bounds (ellipse<3,float>);
|