2#include <boost/math/constants/constants.hpp>
3#include <boost/units/cmath.hpp>
15 if (c.r.value() != 0.0) {
16 const double x_over_r = p.x / c.r;
17 const double y_over_r = p.y / c.r;
18 return 1.0 - (x_over_r * x_over_r) - (y_over_r * y_over_r);
20 return -std::numeric_limits<
double>::infinity();
26 if (r.a.value() != 0.0 && r.b.value() != 0.0) {
27 const double x_over_a = p.x / r.a;
28 const double y_over_b = p.y / r.b;
29 return std::min(1.0 - x_over_a * x_over_a, 1.0 - y_over_b * y_over_b);
31 return -std::numeric_limits<
double>::infinity();
37 if (e.a.value() != 0.0 && e.b.value() != 0.0) {
38 const double x_over_a = p.x / e.a;
39 const double y_over_b = p.y / e.b;
40 return 1.0 - (x_over_a * x_over_a) - (y_over_b * y_over_b);
42 return -std::numeric_limits<
double>::infinity();
46struct geometric_function_visitor :
public boost::static_visitor<
double>
51 double operator()(
const SHAPE& s)
const
53 return geometric_function(s, point);
59double geometric_function(
const decltype(Area::shape)& shape,
const CartesianPosition& p)
61 geometric_function_visitor visitor(p);
62 return boost::apply_visitor(visitor, shape);
67 using namespace boost::math::double_constants;
69 const units::Angle zenith = half_pi * units::si::radian - azimuth;
70 const double sin_z = sin(zenith);
71 const double cos_z = cos(zenith);
75 canonical.x = cos_z * point.x + sin_z * point.y;
76 canonical.y = -sin_z * point.x + cos_z * point.y;
80struct area_size_visitor :
public boost::static_visitor<units::Area>
82 units::Area operator()(
const Circle& circle)
const
84 using namespace boost::math::double_constants;
85 return pi * circle.r * circle.r;
88 units::Area operator()(
const Rectangle& rectangle)
const
90 using namespace boost::math::double_constants;
91 return 4.0 * rectangle.a * rectangle.b;
94 units::Area operator()(
const Ellipse& ellipse)
const
96 using namespace boost::math::double_constants;
97 return pi * ellipse.a * ellipse.b;
101units::Area area_size(
const Area& area)
103 return boost::apply_visitor(area_size_visitor(), area.shape);
110 return !outside_shape(area.shape, canonical);