#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GEOMETRY_AREAS_DISC2_H #define NUCLEX_GEOMETRY_AREAS_DISC2_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Point2.h" #include "Nuclex/Geometry/Math.h" #include "Rectangle2.h" namespace Nuclex { namespace Geometry { namespace Areas { // ------------------------------------------------------------------------------------------- // /// Disc in 2D space stored as a position and a radius template struct Disc2 { /// A unit circle disc located at the center of the coordinate system public: static const Disc2 Unit; /// Constructs an uninitialized disc public: Disc2() {} /// Initializes a disc using the specified position and radius /// Position of the disc's center point /// Radius of the disc public: Disc2(const Point2 ¢er, TScalar radius) : Center(center), Radius(radius) {} /// Initializes a disc using the specified position and radius /// X coordinate of the disc's center point /// Y coordinate of the disc's center point /// Radius of the disc public: Disc2(TScalar centerX, TScalar centerY, TScalar radius) : Center(centerX, centerY), Radius(radius) {} /// Returns the center point of the disc /// The center of the disc public: Point2 GetCenter() const { return this->Center; } /// Calculates the area of the disc /// The area of the disc public: TScalar GetArea() const { return Math::Pi * (this->Radius * this->Radius); } /// Calculates the perimeter of the disc /// The disc's perimeter public: TScalar GetPerimeter() const { return Math::Perigon * this->Radius; } /// Offsets the entire disc by the specified amount /// Amount the disc will be offset on the X axis /// Amount the disc will be offset on the Y axis public: void ShiftBy(TScalar amountX, TScalar amountY) { this->Center.X += amountX; this->Center.Y += amountY; } /// Offsets the entire disc by the specified amount /// Amount the disc will be offset public: void ShiftBy(const Vector2 &amount) { this->Center += amount; } /// Coordinates of the disc's center public: Point2 Center; /// Radius of the disc public: TScalar Radius; }; // ------------------------------------------------------------------------------------------- // template const Disc2 Disc2::Unit(Point2::Zero, 1); // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Areas #endif // NUCLEX_GEOMETRY_AREAS_DISC2_H