-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeometri.cpp
More file actions
68 lines (58 loc) · 1.4 KB
/
geometri.cpp
File metadata and controls
68 lines (58 loc) · 1.4 KB
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
#include "geometri.h"
// POINTARRAY 4.2
PointArray :: PointArray (){
size = 0;
points = new Point [0]; //Permite borrar más tarde
}
PointArray :: PointArray(const Point ptsToCopy[], const int toCopySize) {
{
size = toCopySize;
points = new Point[toCopySize];
for(int i = 0; i < toCopySize; ++i){
points[i] = ptsToCopy[i];
}
}
PointArray :: PointArray(const PointArray &other){
size = other.size;
points = new Point[size];
for(int i = 0; i < size; i++){
points[i]=other.points[i];
}
}
void PointArray :: resize(int newSize){
Point *pts = new Point[newSize];
int minSize = (newSize > size ? size : newSize);
for(int i = 0; i < minSize; i++)
pts[i] = points[i];
delete[] points;
size = newSize;
points = pts;
}
void PointArray ::clear(){
resize(0);
}
void PointArray :: push_back(const Point &p){
resize(size+1);
points[size-1] = p;
}
void PointArray :: insert(const int pos, const Point &p){
resize(size + 1);
for(int i = size - 1; i > pos; i--){
points[i] = points[i-1];
}
points[pos] = p;
}
void PointArray :: remove(const int pos){
if(pos >= 0 && pos < size){ // desplazar a la izquierda
for(int i = pos; i < size - 2; i++){
points[i] = points[i+1];
}
resize(size - 1);
}
}
Point *PointArray ::get(const int pos){
return pos >= 0 && pos < size ? points + pos : NULL;
}
const Point *PointArray ::get(const int pos)cons {
return pos >= 0 && pos < size ? points + pos : NULL;
}