blob: 3df23ef3b1e5cf8d78f7238e65169207fb03e6e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* hyp2mat - convert hyperlynx files to matlab scripts
* Copyright 2012 Koen De Vleeschauwer.
*
* This file is part of hyp2mat.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef POLYGON_H
#define POLYGON_H
#include "clipper.hpp"
#include "hyp2mat.h"
namespace Hyp2Mat {
bool IsClockwise (FloatPolygon& poly);
void Reverse (FloatPolygon& poly);
class Polygon {
public:
Polygon();
static void SetGrid(double new_grid);
static double AlignToGrid(double x);
static void SetArcPrecision(double new_arc_precision);
void AddEdge(FloatPolygon edge);
void AddHole(FloatPolygon hole);
void Offset(double delta);
void Simplify();
void Intersection(Polygon clip);
void Union(Polygon clip);
void Difference(Polygon clip);
void Xor(Polygon clip);
bool IsEmpty();
FloatPolygons Result();
private:
/* convert Hyp2Mat to Clipper */
void _AddEdge(FloatPolygon edge, bool orientation);
ClipperLib::IntPoint _convert(FloatPoint p);
ClipperLib::Polygon _convert(FloatPolygon edge);
ClipperLib::Polygon _unique(ClipperLib::Polygon p);
/* Clipper polygon operations */
void _Execute(ClipperLib::ClipType op, Polygon clip);
ClipperLib::PolyFillType _filltype;
/* convert Clipper to Hyp2Mat */
void _AddToPolygonList(ClipperLib::PolyNode& polynode, FloatPolygons& polygons, int level);
FloatPolygon _convert (ClipperLib::Polygon clip_poly);
FloatPoint _convert (ClipperLib::IntPoint p);
/* data */
ClipperLib::Polygons _subject;
static double _grid; /* resolution of x and y coordinates, identical for all polygons. */
static double _arc_precision; /* maximum difference between perfect circle arc and polygonal approximation */
};
};
#endif
/* not truncated */
|