first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / graphiq / library / geometric / circle.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : circle                                                            *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include "circle.h"
16 #include "cartesian_objects.h"
17 #include "line.h"
18 #include "rectangle.h"
19
20 #include <basis/functions.h>
21
22 #include <math.h>
23
24 using namespace basis;
25
26 namespace geometric {
27
28 circle::circle() : _radius(1), _center(cartesian_point::origin()) {}
29
30 circle::circle(double a_radius, const cartesian_point &a_center)
31 : _radius(a_radius), _center(a_center) {}
32
33 circle::~circle() {}
34
35 double circle::area() const { return PI_APPROX * square(_radius); }
36
37 double circle::diameter() const { return 2.0 * _radius; }
38
39 double circle::circumference() const { return 2.0 * PI_APPROX * _radius; }
40
41 cartesian_point circle::location(const double_angle &where) const
42 {
43   double rotation = where.get(RADIANS);
44   cartesian_point second(cos(rotation) * _radius, sin(rotation) * _radius);
45   return _center + second;
46 }
47
48 bool circle::inside(const cartesian_point &where) const
49 {
50   double dist = where.distance(_center);
51   return dist <= _radius? true : false;
52 }
53
54 cartesian_rectangle circle::dimensions() const
55 {
56   const double deg0 = 0;
57   const double deg90 = 0.5 * PI_APPROX;
58   const double deg180 = PI_APPROX;
59   const double deg270 = 1.5 * PI_APPROX;
60
61   cartesian_point right(location(deg0));
62   cartesian_point top(location(deg90));
63   cartesian_point left(location(deg180));
64   cartesian_point bottom(location(deg270));
65   return cartesian_rectangle(left.x(), bottom.y(), right.x(), top.y());
66 }
67
68 double circle::radius() const { return _radius; }
69
70 void circle::radius(double to_set) { _radius = to_set; }
71
72 cartesian_point circle::center() const { return _center; }
73
74 void circle::center(const cartesian_point &to_set) { _center = to_set; }
75
76 } // namespace.
77