-
Notifications
You must be signed in to change notification settings - Fork 5
/
polyline.h
161 lines (154 loc) · 5.08 KB
/
polyline.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/******************************************************/
/* */
/* polyline.h - polylines */
/* */
/******************************************************/
/* Copyright 2020,2021 Pierre Abbat.
* This file is part of PerfectTIN.
*
* PerfectTIN is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* PerfectTIN 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 and Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and Lesser General Public License along with PerfectTIN. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef POLYLINE_H
#define POLYLINE_H
#include <vector>
#include <fstream>
#include "point.h"
#include "point.h"
#include "arc.h"
#include "bezier3d.h"
#include "spiral.h"
extern int bendlimit;
/* The maximum angle through which a segment of polyspiral can bend. If the bend
* is greater, it will be replaced with a straight line segment. If angles in
* contours have extra bulbs, it is too high; if smooth curves in contours have
* straight line segments, it is too low. Default value is 180°. Setting it to
* DEG360 will not work; set it to DEG360-1 instead.
*/
/* Polylines and alignments are very similar. The differences are:
* polylines are in a horizontal plane, whereas alignments have vertical curves;
* polylines have derived classes with arcs and spirals, whereas alignments
* always have complete spiral data.
*/
int midarcdir(xy a,xy b,xy c);
class polyline
{
protected:
double elevation;
std::vector<xy> endpoints;
std::vector<double> lengths,cumLengths;
public:
friend class polyarc;
friend class polyspiral;
polyline();
virtual ~polyline()
{}
explicit polyline(double e);
double getElevation()
{
return elevation;
}
virtual void clear();
virtual void shrink_to_fit();
bool isopen();
int size();
segment getsegment(int i);
xyz getEndpoint(int i);
xyz getstart();
xyz getend();
void dedup();
virtual bezier3d approx3d(double precision);
virtual void insert(xy newpoint,int pos=-1);
virtual void replace(xy newpoint,int pos);
virtual void erase(int pos);
virtual void setlengths();
virtual void open();
virtual void close();
virtual double in(xy point);
double length();
double getCumLength(int i);
int stationSegment(double along);
virtual xyz station(double along);
virtual double area();
virtual void _roscat(xy tfrom,int ro,double sca,xy cis,xy tto);
virtual unsigned int checksum();
virtual void write(std::ostream &file);
virtual void read(std::istream &file);
};
class polyarc: public polyline
{
protected:
std::vector<int> deltas;
public:
friend class polyspiral;
polyarc();
explicit polyarc(double e);
polyarc(polyline &p);
virtual void clear() override;
virtual void shrink_to_fit() override;
arc getarc(int i);
virtual bezier3d approx3d(double precision) override;
virtual void insert(xy newpoint,int pos=-1) override;
virtual void replace(xy newpoint,int pos) override;
virtual void erase(int pos) override;
void setdelta(int i,int delta);
virtual void setlengths() override;
virtual void open() override;
virtual void close() override;
virtual double in(xy point) override;
virtual xyz station(double along) override;
virtual double area() override;
virtual unsigned int checksum() override;
virtual void write(std::ostream &file) override;
virtual void read(std::istream &file) override;
};
class polyspiral: public polyarc
{
protected:
std::vector<int> bearings; // correspond to endpoints
std::vector<int> delta2s;
std::vector<int> midbearings;
std::vector<xy> midpoints;
std::vector<double> clothances,curvatures;
bool curvy;
public:
polyspiral();
explicit polyspiral(double e);
polyspiral(polyline &p);
virtual void clear() override;
virtual void shrink_to_fit() override;
spiralarc getspiralarc(int i);
virtual bezier3d approx3d(double precision) override;
virtual void insert(xy newpoint,int pos=-1) override;
virtual void replace(xy newpoint,int pos) override;
virtual void erase(int pos) override;
void setbear(int i);
void setbear(int i,int bear);
void setspiral(int i);
void setreadspiral(int i);
void smooth();
//void setdelta(int i,int delta);
virtual void setlengths() override;
virtual void open() override;
virtual void close() override;
virtual double in(xy point) override;
virtual xyz station(double along) override;
virtual double area() override;
virtual void _roscat(xy tfrom,int ro,double sca,xy cis,xy tto) override;
virtual unsigned int checksum() override;
virtual void write(std::ostream &file) override;
virtual void read(std::istream &file) override;
};
#endif