Magic_Game/core/base/Geometry.h

189 lines
3.4 KiB
C++

// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "base.hpp"
#include "Unit.h"
namespace easy2d
{
// 섯부暠近쇌宮슥밑溝
enum class GeometryRelation : int
{
Unknown,
Disjoin, // 轟슥섞
IsContained, // 굳관벵
Contains, // 관벵
Overlap // 路딸
};
// 섯부녜蹶
class Geometry
: public Unit
{
public:
Geometry();
virtual ~Geometry();
cpGeometry const& GetD2DGeometry() const { return geo_; }
float GetLength();
bool ComputePointAt(
float length,
Point* point,
Point* tangent
);
// 털뙤暠近角뤠관벵듐
bool ContainsPoint(
Point const& point
);
// 털뙤좃暠近宮슥榴檄
GeometryRelation GetRelationWith(
spGeometry const& other
);
protected:
cpGeometry geo_;
};
// 섯부앤近
class RectangleGeometry
: public Geometry
{
public:
RectangleGeometry();
RectangleGeometry(
Size const& rect_size
);
virtual ~RectangleGeometry();
Size const& GetSize() const { return size_; }
void SetSize(Size const& rect_size);
protected:
Size size_;
};
// 섯부途近
class CircleGeometry
: public Geometry
{
public:
CircleGeometry();
CircleGeometry(
float radius
);
virtual ~CircleGeometry();
float GetRadius() const { return radius_; }
void SetRadius(
float radius
);
protected:
float radius_;
};
// 섯부哭途
class EllipseGeometry
: public Geometry
{
public:
EllipseGeometry();
EllipseGeometry(
float radius_x,
float radius_y
);
virtual ~EllipseGeometry();
float GetRadiusX() const { return radius_x_; }
float GetRadiusY() const { return radius_y_; }
void SetRadius(
float radius_x,
float radius_y
);
protected:
float radius_x_;
float radius_y_;
};
// 섯부쨌쓺
class PathGeometry
: public Geometry
{
public:
PathGeometry();
virtual ~PathGeometry();
// 역迦警속쨌쓺
void BeginPath();
// 써監쨌쓺
void EndPath(
bool closed = true /* 쨌쓺角뤠균북 */
);
// 警속寧係窟뙈
void AddLine(
Point const& point /* 똥듐 */
);
// 警속뜩係窟뙈
void AddLines(
std::vector<Point> const& points
);
// 警속寧係힛늴렘굔힘랑혓窟
void AddBezier(
Point const& point1, /* 굔힘랑혓窟돨뒤寧몸왠齡듐 */
Point const& point2, /* 굔힘랑혓窟돨뒤랗몸왠齡듐 */
Point const& point3 /* 굔힘랑혓窟돨老듐 */
);
// 헌뇜쨌쓺
void ClearPath();
protected:
cpPathGeometry current_geometry_;
cpGeometrySink current_sink_;
};
}