-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
185 lines (170 loc) · 5.94 KB
/
Copy pathutils.js
File metadata and controls
185 lines (170 loc) · 5.94 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
function nmToRGB(wavelength){
var Gamma = 0.80,
IntensityMax = 255,
factor, red, green, blue;
if((wavelength >= 380) && (wavelength<440)){
red = -(wavelength - 440) / (440 - 380);
green = 0.0;
blue = 1.0;
}else if((wavelength >= 440) && (wavelength<490)){
red = 0.0;
green = (wavelength - 440) / (490 - 440);
blue = 1.0;
}else if((wavelength >= 490) && (wavelength<510)){
red = 0.0;
green = 1.0;
blue = -(wavelength - 510) / (510 - 490);
}else if((wavelength >= 510) && (wavelength<580)){
red = (wavelength - 510) / (580 - 510);
green = 1.0;
blue = 0.0;
}else if((wavelength >= 580) && (wavelength<645)){
red = 1.0;
green = -(wavelength - 645) / (645 - 580);
blue = 0.0;
}else if((wavelength >= 645) && (wavelength<781)){
red = 1.0;
green = 0.0;
blue = 0.0;
}else{
red = 0.0;
green = 0.0;
blue = 0.0;
}
// Let the intensity fall off near the vision limits
if((wavelength >= 380) && (wavelength<420)){
factor = 0.3 + 0.7*(wavelength - 380) / (420 - 380);
}else if((wavelength >= 420) && (wavelength<701)){
factor = 1.0;
}else if((wavelength >= 701) && (wavelength<781)){
factor = 0.3 + 0.7*(780 - wavelength) / (780 - 700);
}else{
factor = 0.0;
}
if (red !== 0){
red = Math.round(IntensityMax * Math.pow(red * factor, Gamma));
}
if (green !== 0){
green = Math.round(IntensityMax * Math.pow(green * factor, Gamma));
}
if (blue !== 0){
blue = Math.round(IntensityMax * Math.pow(blue * factor, Gamma));
}
return [red,green,blue];
}
function RGBToHex(rgb){
var hex = "#";
for (var i = 0; i < 3; i++){
var h = rgb[i].toString(16);
if (h.length < 2){
h = "0" + h;
}
hex += h;
}
return hex;
}
function rotatePointsAroundCenter(points, angle){
//angle is in degrees
var angleRadians = angle * Math.PI / 180;
//get the center of the points (average of all points)
var centerX = 0;
var centerY = 0;
points.forEach(function(point){
centerX += point.x;
centerY += point.y;
});
centerX /= points.length;
centerY /= points.length;
//rotate the points around the center
var newPoints = [];
points.forEach(function(point){
var x = centerX + (point.x - centerX) * Math.cos(angleRadians) - (point.y - centerY) * Math.sin(angleRadians);
var y = centerY + (point.x - centerX) * Math.sin(angleRadians) + (point.y - centerY) * Math.cos(angleRadians);
newPoints.push({x: x, y: y});
});
return newPoints;
}
function rotatePoints(points, angleInDegrees) {
const angleInRadians = DegreesToRadians(angleInDegrees);
// Calculate the center of the points
const centerX = points.reduce((sum, point) => sum + point.x, 0) / points.length;
const centerY = points.reduce((sum, point) => sum + point.y, 0) / points.length;
// Iterate through each point and apply rotation
return points.map(point => {
const x = centerX + (point.x - centerX) * Math.cos(angleInRadians) - (point.y - centerY) * Math.sin(angleInRadians);
const y = centerY + (point.x - centerX) * Math.sin(angleInRadians) + (point.y - centerY) * Math.cos(angleInRadians);
return {x, y};
});
}
function rotatePointsXY(points, angleInRadians, x, y) {
// Calculate the center of the points
const centerX = x;
const centerY = y;
// Iterate through each point and apply rotation
return points.map(point => {
const x = centerX + (point.x - centerX) * Math.cos(angleInRadians) - (point.y - centerY) * Math.sin(angleInRadians);
const y = centerY + (point.x - centerX) * Math.sin(angleInRadians) + (point.y - centerY) * Math.cos(angleInRadians);
return {x, y};
});
}
//==============================================================================
function DegreesToRadians(degrees){
return degrees * Math.PI / 180;
}
function RadiansToDegrees(radians){
return radians * 180 / Math.PI;
}
//==============================================================================
function dotProduct(a, b){
return a.x * b.x + a.y * b.y;
}
//==============================================================================
const delay = ms => new Promise(res => setTimeout(res, ms));
//==============================================================================
function normalizeDegreeAngle(angle){
//make angle between 0 and 360 (-45 would be 315)
while(angle <= 0){
angle += 360;
}
while(angle >= 360){
angle -= 360;
}
return angle;
}
//==============================================================================
function calculateTotalCalulations(){
//shapes * user.maxLightBounces * rays
var shapes = s.shapes.length;
var rays = s.rays.length;
var totalCalculations = user.maxLightBounces;
return shapes * totalCalculations * rays;
}
//==============================================================================
function getClosestNumber(number, array) {
var closest = array[0];
var closestDiff = Math.abs(number - closest);
for(var i = 1; i < array.length; i++){
var diff = Math.abs(number - array[i]);
if(diff < closestDiff){
closest = array[i];
closestDiff = diff;
}
}
return closest;
}
//==============================================================================
//get the how good the pc is (0-100) based the speed it can calculate some obscure math function
function getPcSpeed(){
var start = new Date().getTime();
let x = 0;
for(var i = 0; i < 1000; i++){
for(var j = 0; j < 1000; j++) {
x += Math.pow(i, j);
}
}
console.log(x);
var end = new Date().getTime();
var time = end - start;
var speed = 100 - Math.min(100, time / 100);
return speed;
}