-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCurve.cpp
88 lines (84 loc) · 2.07 KB
/
Curve.cpp
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
#include "Curve.h"
namespace nV {
namespace Graphics {
Curve::Curve() : spx(0),
spy(0),
xmin(0),
xmax(0),
ymin(0),
ymax(0),
dataNum(0)
{
lineStrips.clear();
isColorfulCurve = false;
singularity = false;
WithDomain = false;
uninitsingularityset();
uninitdomain();
}
Curve::Curve(ArrayList<Point2d*> v) {
lineStrips.clear();
LineStrip* lineStrip = new LineStrip;
for (unsigned int i = 0; i < v.size(); i++)
lineStrip->vert.add(v[i]);
lineStrips.add(lineStrip);
isColorfulCurve = false;
singularity = false;
WithDomain = false;
uninitsingularityset();
uninitdomain();
}
Curve::~Curve() {
for (unsigned int i = 0; i < lineStrips.size(); i++) {
for (unsigned int j = 0; j < lineStrips[i]->vert.size(); j++) {
delete lineStrips[i]->vert[j];
}
for (unsigned int j = 0; j < lineStrips[i]->color.size(); j++) {
delete lineStrips[i]->color[j];
}
delete lineStrips[i];
}
lineStrips.clear();
uninitsingularityset();
uninitdomain();
}
Color* Curve::getRainbowColor(double x) {
double red = 0;
double green = 0;
double blue = 0;
if (x <= 63.0 / 255) {
x = 4 * (x - 0);
blue = 1;
green = x;
} else if (x <= 127.0 / 255) {
x = 4 * (x - 64.0 / 255);
green = 1;
blue = 1 - x;
} else if (x <= 191.0 / 255) {
x = 4 * (x - 128.0 / 255);
green = 1;
red = x;
} else {
x = 4 * (x - 192.0 / 255);
red = 1;
green = 1 - x;
}
if (red > 1)
red = 1;
if (red < 0)
red = 0;
if (green > 1)
green = 1;
if (green < 0)
green = 0;
if (blue > 1)
blue = 1;
if (blue < 0)
blue = 0;
red *= 255;
green *= 255;
blue *= 255;
return new Color(static_cast<int>(red), static_cast<int>(green), static_cast<int>(blue));
}
}
}