@pie-element/graphing-solution-set 1.8.1-next.0 → 1.8.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configure/package.json +1 -1
- package/controller/package.json +1 -1
- package/package.json +3 -3
- package/configure/lib/configure.js +0 -398
- package/configure/lib/configure.js.map +0 -1
- package/configure/lib/correct-response.js +0 -601
- package/configure/lib/correct-response.js.map +0 -1
- package/configure/lib/defaults.js +0 -359
- package/configure/lib/defaults.js.map +0 -1
- package/configure/lib/graphing-config.js +0 -435
- package/configure/lib/graphing-config.js.map +0 -1
- package/configure/lib/index.js +0 -218
- package/configure/lib/index.js.map +0 -1
- package/configure/lib/utils.js +0 -754
- package/configure/lib/utils.js.map +0 -1
- package/controller/lib/defaults.js +0 -71
- package/controller/lib/defaults.js.map +0 -1
- package/controller/lib/index.js +0 -423
- package/controller/lib/index.js.map +0 -1
- package/controller/lib/utils.js +0 -273
- package/controller/lib/utils.js.map +0 -1
- package/lib/index.js +0 -214
- package/lib/index.js.map +0 -1
- package/lib/main.js +0 -440
- package/lib/main.js.map +0 -1
- package/lib/utils.js +0 -604
- package/lib/utils.js.map +0 -1
package/configure/lib/utils.js
DELETED
|
@@ -1,754 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.pointInsidePolygon = exports.getLabelValues = exports.getGridValues = exports.findSectionsInSolutionSet = exports.filterPlotableMarks = exports.checkIfLinesAreAdded = exports.applyConstraints = exports.VALID_LABEL_VALUES = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
-
|
|
12
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
-
|
|
18
|
-
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
19
|
-
|
|
20
|
-
var _excluded = ["angle"];
|
|
21
|
-
|
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
|
|
26
|
-
/*Valid grid values*/
|
|
27
|
-
var VALID_GRID_VALUES = [0.01, 0.02, 0.04, 0.05, 0.0625, 0.1, 0.125, 0.2, 0.25, 0.5, 1, 2, 3, 4, 5, 8, 10, 12, 15, 20, 40, 50, 64, 100, 500, 1000]; // same as VALID_GRID_VALUES but next values are excluded: 0.04, 0.0625, 0.125, 3, 4, 8, 12, 15, 40, 64
|
|
28
|
-
|
|
29
|
-
var PREFERRED_VALID_GRID_VALUES = [0.01, 0.02, 0.05, 0.1, 0.2, 0.25, 0.5, 1, 2, 5, 10, 20, 50, 100, 500, 1000];
|
|
30
|
-
/*Valid label values*/
|
|
31
|
-
|
|
32
|
-
var VALID_LABEL_VALUES = {
|
|
33
|
-
0.01: [0, 0.01, 0.02, 0.04, 0.05, 0.1],
|
|
34
|
-
0.02: [0, 0.02, 0.04, 0.1],
|
|
35
|
-
0.04: [0, 0.04, 0.08, 0.16, 0.2],
|
|
36
|
-
0.05: [0, 0.05, 0.1, 0.2, 0.25],
|
|
37
|
-
0.0625: [0, 0.0625, 0.125, 0.25, 0.5],
|
|
38
|
-
0.1: [0, 0.1, 0.2, 0.4, 0.5, 1],
|
|
39
|
-
0.125: [0, 0.125, 0.25, 0.5, 1],
|
|
40
|
-
0.2: [0, 0.2, 0.5, 0.1],
|
|
41
|
-
0.25: [0, 0.25, 0.5, 1, 2],
|
|
42
|
-
0.5: [0, 0.5, 1, 2],
|
|
43
|
-
1: [0, 1, 2, 4, 5, 10],
|
|
44
|
-
2: [0, 2, 4, 8, 10],
|
|
45
|
-
3: [0, 3, 6, 12, 15],
|
|
46
|
-
4: [0, 4, 8, 16, 20],
|
|
47
|
-
5: [0, 5, 10, 20, 25],
|
|
48
|
-
8: [0, 8, 16, 32, 40, 64],
|
|
49
|
-
10: [0, 10, 20, 40, 50, 100],
|
|
50
|
-
12: [0, 12, 24],
|
|
51
|
-
15: [0, 15, 30, 60],
|
|
52
|
-
20: [0, 20, 40, 80, 100],
|
|
53
|
-
40: [0, 40, 80, 160, 200],
|
|
54
|
-
50: [0, 50, 100, 200, 250],
|
|
55
|
-
64: [0, 64, 128],
|
|
56
|
-
100: [0, 100, 200, 400, 500],
|
|
57
|
-
500: [0, 500, 1000, 2500],
|
|
58
|
-
1000: [0, 1000, 2000, 4000, 5000]
|
|
59
|
-
};
|
|
60
|
-
/*
|
|
61
|
-
* Function to get grid values
|
|
62
|
-
* @param {Object} axis - axis object
|
|
63
|
-
* @param {Number} size - size of the axis
|
|
64
|
-
* @param {Boolean} prefferedValues - flag to get preffered values
|
|
65
|
-
* */
|
|
66
|
-
|
|
67
|
-
exports.VALID_LABEL_VALUES = VALID_LABEL_VALUES;
|
|
68
|
-
|
|
69
|
-
var getGridValues = function getGridValues(axis, size) {
|
|
70
|
-
var prefferedValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
71
|
-
var minValue = 10 * (axis.max - axis.min) / size;
|
|
72
|
-
var maxValue = minValue * 10;
|
|
73
|
-
var values = prefferedValues ? PREFERRED_VALID_GRID_VALUES : VALID_GRID_VALUES;
|
|
74
|
-
return values.filter(function (value) {
|
|
75
|
-
return value >= minValue && value <= maxValue;
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
/*
|
|
79
|
-
* Function to get label values
|
|
80
|
-
* @param {Number} value - value of the axis step
|
|
81
|
-
* */
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
exports.getGridValues = getGridValues;
|
|
85
|
-
|
|
86
|
-
var getLabelValues = function getLabelValues(value) {
|
|
87
|
-
return VALID_LABEL_VALUES[value] || [];
|
|
88
|
-
};
|
|
89
|
-
/*
|
|
90
|
-
* Function to apply constraints
|
|
91
|
-
* @param {Object} axis - axis object
|
|
92
|
-
* @param {Number} size - size of the axis
|
|
93
|
-
* @param {Array} oldGridValues - old grid values
|
|
94
|
-
* @param {Array} oldLabelValues - old label values
|
|
95
|
-
* */
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
exports.getLabelValues = getLabelValues;
|
|
99
|
-
|
|
100
|
-
var applyConstraints = function applyConstraints(axis, size, oldGridValues, oldLabelValues) {
|
|
101
|
-
var gridValues = getGridValues(axis, size);
|
|
102
|
-
var labelValues = getLabelValues(axis.step);
|
|
103
|
-
|
|
104
|
-
if (!(0, _isEqual["default"])(oldGridValues, gridValues) && !gridValues.includes(axis.step)) {
|
|
105
|
-
var preferredValues = getGridValues(axis, size, true);
|
|
106
|
-
var lowestValue = preferredValues[0] || 1;
|
|
107
|
-
axis.step = lowestValue;
|
|
108
|
-
labelValues = getLabelValues(lowestValue);
|
|
109
|
-
|
|
110
|
-
if (!labelValues.includes(axis.labelStep)) {
|
|
111
|
-
axis.labelStep = lowestValue;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
gridValues: gridValues,
|
|
116
|
-
labelValues: labelValues
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (!(0, _isEqual["default"])(oldLabelValues, labelValues) && !labelValues.includes(axis.labelStep)) {
|
|
121
|
-
axis.labelStep = axis.step;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
gridValues: gridValues,
|
|
126
|
-
labelValues: labelValues
|
|
127
|
-
};
|
|
128
|
-
}; // also used in pie-lib/graphing/utils as 'getTickValues'
|
|
129
|
-
|
|
130
|
-
/*
|
|
131
|
-
* Function to get plotable points
|
|
132
|
-
* @param {Object} prop - axis object
|
|
133
|
-
* */
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
exports.applyConstraints = applyConstraints;
|
|
137
|
-
|
|
138
|
-
var getPlotablePoints = function getPlotablePoints(prop) {
|
|
139
|
-
var tickValues = [];
|
|
140
|
-
var tickVal = 0;
|
|
141
|
-
|
|
142
|
-
while (tickVal >= prop.min && tickValues.indexOf(tickVal) < 0) {
|
|
143
|
-
tickValues.push(tickVal);
|
|
144
|
-
tickVal = Math.round((tickVal - prop.step) * 10000) / 10000;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
tickVal = Math.round(prop.step * 10000) / 10000;
|
|
148
|
-
|
|
149
|
-
while (tickVal <= prop.max && tickValues.indexOf(tickVal) < 0) {
|
|
150
|
-
tickValues.push(tickVal);
|
|
151
|
-
tickVal = Math.round((tickVal + prop.step) * 10000) / 10000;
|
|
152
|
-
} // return only ticks that are inside the min-max interval
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (tickValues) {
|
|
156
|
-
return tickValues.filter(function (tV) {
|
|
157
|
-
return tV >= prop.min && tV <= prop.max;
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return [];
|
|
162
|
-
};
|
|
163
|
-
/*
|
|
164
|
-
* Function to get plotable marks
|
|
165
|
-
* @param {Object} domain - domain object
|
|
166
|
-
* @param {Object} range - range object
|
|
167
|
-
* @param {Object} answers - answers object
|
|
168
|
-
* */
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var filterPlotableMarks = function filterPlotableMarks(domain, range, answers) {
|
|
172
|
-
var domainValues = getPlotablePoints(domain);
|
|
173
|
-
var rangeValues = getPlotablePoints(range);
|
|
174
|
-
|
|
175
|
-
var isPointPlotable = function isPointPlotable(x, y) {
|
|
176
|
-
return domainValues.includes(x) && rangeValues.includes(y);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
return Object.entries(answers || {}).reduce(function (newAnswers, _ref) {
|
|
180
|
-
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
181
|
-
key = _ref2[0],
|
|
182
|
-
answer = _ref2[1];
|
|
183
|
-
|
|
184
|
-
newAnswers[key] = _objectSpread(_objectSpread({}, answer), {}, {
|
|
185
|
-
marks: (answer.marks || []).filter(function (mark) {
|
|
186
|
-
if (mark.type === 'point') {
|
|
187
|
-
return isPointPlotable(mark.x, mark.y);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (mark.type === 'polygon') {
|
|
191
|
-
return !mark.points.find(function (point) {
|
|
192
|
-
return !isPointPlotable(point.x, point.y);
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
var from = mark.from || mark.root;
|
|
197
|
-
var to = mark.to || mark.edge;
|
|
198
|
-
return mark.building ? isPointPlotable(from.x, from.y) : isPointPlotable(from.x, from.y) && isPointPlotable(to.x, to.y);
|
|
199
|
-
})
|
|
200
|
-
});
|
|
201
|
-
return newAnswers;
|
|
202
|
-
}, {});
|
|
203
|
-
}; //////////////////////////////////////////////////////////////////////////////////
|
|
204
|
-
// BELOW FUNCTIONS ARE USED IN src/utils as well
|
|
205
|
-
//////////////////////////////////////////////////////////////////////////////////
|
|
206
|
-
|
|
207
|
-
/*
|
|
208
|
-
* Function to calculate the distance between two points
|
|
209
|
-
* @param {Object} a - point a
|
|
210
|
-
* @param {Object} b - point b
|
|
211
|
-
* */
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
exports.filterPlotableMarks = filterPlotableMarks;
|
|
215
|
-
|
|
216
|
-
var distance = function distance(a, b) {
|
|
217
|
-
return Number(Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)).toFixed(3));
|
|
218
|
-
};
|
|
219
|
-
/*
|
|
220
|
-
* Function to check if a point lies on edges of a polygon
|
|
221
|
-
* @param {Object} point - point object
|
|
222
|
-
* @param {Array} polygon - polygon points array
|
|
223
|
-
* */
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
var pointInPolygon = function pointInPolygon(point, polygon) {
|
|
227
|
-
var c = point;
|
|
228
|
-
var inside = false;
|
|
229
|
-
var clonePolygon = (0, _toConsumableArray2["default"])(polygon);
|
|
230
|
-
clonePolygon.push(polygon[0]);
|
|
231
|
-
|
|
232
|
-
for (var i = 0; i < clonePolygon.length - 1; i++) {
|
|
233
|
-
var a = clonePolygon[i];
|
|
234
|
-
var b = clonePolygon[i + 1]; // check if point is on the edge
|
|
235
|
-
|
|
236
|
-
if (distance(a, c) + distance(c, b) === distance(a, b)) {
|
|
237
|
-
inside = true;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return inside;
|
|
243
|
-
};
|
|
244
|
-
/*
|
|
245
|
-
* Function to get the intersection point of two lines
|
|
246
|
-
* @param {Number} x1 - x coordinate of point 1 of line 1
|
|
247
|
-
* @param {Number} y1 - y coordinate of point 1 of line 1
|
|
248
|
-
* @param {Number} x2 - x coordinate of point 2 of line 1
|
|
249
|
-
* @param {Number} y2 - y coordinate of point 2 of line 1
|
|
250
|
-
* @param {Number} x3 - x coordinate of point 1 of line 2
|
|
251
|
-
* @param {Number} y3 - y coordinate of point 1 of line 2
|
|
252
|
-
* @param {Number} x4 - x coordinate of point 2 of line 2
|
|
253
|
-
* @param {Number} y4 - y coordinate of point 2 of line 2
|
|
254
|
-
* */
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var lineIntersect = function lineIntersect(x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
258
|
-
var ua,
|
|
259
|
-
denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
|
260
|
-
|
|
261
|
-
if (denominator === 0) {
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denominator;
|
|
266
|
-
return {
|
|
267
|
-
x: Number((x1 + ua * (x2 - x1)).toFixed(3)),
|
|
268
|
-
y: Number((y1 + ua * (y2 - y1)).toFixed(3))
|
|
269
|
-
};
|
|
270
|
-
};
|
|
271
|
-
/*
|
|
272
|
-
* Check if a point is inside the graph
|
|
273
|
-
* @param {Object} point - point object
|
|
274
|
-
* @param {Object} domain - domain object
|
|
275
|
-
* @param {Object} range - range object
|
|
276
|
-
* */
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
var isPointInsideGraph = function isPointInsideGraph(point, domain, range) {
|
|
280
|
-
return point.x > domain.min && point.x < domain.max && point.y > range.min && point.y < range.max;
|
|
281
|
-
};
|
|
282
|
-
/*
|
|
283
|
-
* Check if a point is on or inside the graph
|
|
284
|
-
* @param {Object} point - point object
|
|
285
|
-
* @param {Object} domain - domain object
|
|
286
|
-
* @param {Object} range - range object
|
|
287
|
-
* */
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
var isPointOnOrInsideGraph = function isPointOnOrInsideGraph(point, domain, range) {
|
|
291
|
-
return point.x >= domain.min && point.x <= domain.max && point.y >= range.min && point.y <= range.max;
|
|
292
|
-
};
|
|
293
|
-
/*
|
|
294
|
-
* Find the intersection point of a mark with the graph
|
|
295
|
-
* @param {Object} mark - mark object
|
|
296
|
-
* @param {Object} domain - domain object
|
|
297
|
-
* @param {Object} range - range object
|
|
298
|
-
* */
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
var findIntersectionPointForMark = function findIntersectionPointForMark(mark, domain, range) {
|
|
302
|
-
var intersectionPoint = [];
|
|
303
|
-
var tempData = [[domain.max, range.max, domain.max, range.min], [domain.min, range.max, domain.min, range.min], [domain.min, range.max, domain.max, range.max], [domain.min, range.min, domain.max, range.min]];
|
|
304
|
-
|
|
305
|
-
for (var i = 0; i < tempData.length; i++) {
|
|
306
|
-
var intersection = lineIntersect(mark.from.x, mark.from.y, mark.to.x, mark.to.y, tempData[i][0], tempData[i][1], tempData[i][2], tempData[i][3]);
|
|
307
|
-
|
|
308
|
-
if (intersection && isPointOnOrInsideGraph(intersection, domain, range)) {
|
|
309
|
-
intersectionPoint.push(intersection);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return intersectionPoint;
|
|
314
|
-
};
|
|
315
|
-
/*
|
|
316
|
-
* Sort points in clockwise direction for a polygon
|
|
317
|
-
* @param {Array} points - points array
|
|
318
|
-
* */
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
var sortPointsClockWise = function sortPointsClockWise(points) {
|
|
322
|
-
// Find min max to get center and Sort from top to bottom
|
|
323
|
-
points.sort(function (a, b) {
|
|
324
|
-
return a.y - b.y;
|
|
325
|
-
}); // Get center y
|
|
326
|
-
|
|
327
|
-
var cy = (points[0].y + points[points.length - 1].y) / 2; // Sort from right to left
|
|
328
|
-
|
|
329
|
-
points.sort(function (a, b) {
|
|
330
|
-
return b.x - a.x;
|
|
331
|
-
}); // Get center x
|
|
332
|
-
|
|
333
|
-
var cx = (points[0].x + points[points.length - 1].x) / 2; // Center point
|
|
334
|
-
|
|
335
|
-
var center = {
|
|
336
|
-
x: cx,
|
|
337
|
-
y: cy
|
|
338
|
-
}; // As the points are sorted from right to left the first point is the rightmost Starting angle used to reference other angles
|
|
339
|
-
|
|
340
|
-
var startAng;
|
|
341
|
-
points.forEach(function (point) {
|
|
342
|
-
var ang = Math.atan2(point.y - center.y, point.x - center.x);
|
|
343
|
-
|
|
344
|
-
if (!startAng) {
|
|
345
|
-
startAng = ang;
|
|
346
|
-
} else {
|
|
347
|
-
if (ang < startAng) {
|
|
348
|
-
// ensure that all points are clockwise of the start point
|
|
349
|
-
ang += Math.PI * 2;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
point.angle = ang; // add the angle to the point
|
|
354
|
-
}); // first sort clockwise
|
|
355
|
-
|
|
356
|
-
points.sort(function (a, b) {
|
|
357
|
-
return a.angle - b.angle;
|
|
358
|
-
}); // then reverse the order
|
|
359
|
-
|
|
360
|
-
var ccwPoints = points.reverse(); // move the last point back to the start
|
|
361
|
-
|
|
362
|
-
ccwPoints.unshift(ccwPoints.pop());
|
|
363
|
-
return ccwPoints.map(function (_ref3) {
|
|
364
|
-
var angle = _ref3.angle,
|
|
365
|
-
attr = (0, _objectWithoutProperties2["default"])(_ref3, _excluded);
|
|
366
|
-
return attr;
|
|
367
|
-
});
|
|
368
|
-
};
|
|
369
|
-
/*
|
|
370
|
-
* Function to calculate the dot product of two vectors
|
|
371
|
-
* @param {Object} v1 - point 1
|
|
372
|
-
* @param {Object} v2 - point 2
|
|
373
|
-
* */
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
var dotProduct = function dotProduct(v1, v2) {
|
|
377
|
-
return v1.x * v2.x + v1.y * v2.y;
|
|
378
|
-
};
|
|
379
|
-
/*
|
|
380
|
-
* Function to calculate the magnitude of a vector
|
|
381
|
-
* @param {Object} v - point object
|
|
382
|
-
* */
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
var magnitude = function magnitude(v) {
|
|
386
|
-
return Math.sqrt(v.x * v.x + v.y * v.y);
|
|
387
|
-
};
|
|
388
|
-
/*
|
|
389
|
-
* Function to calculate the angle between two vectors in radians
|
|
390
|
-
* @param {Object} v1 - point 1
|
|
391
|
-
* @param {Object} v2 - point 2
|
|
392
|
-
* */
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
var angleBetweenVectors = function angleBetweenVectors(v1, v2) {
|
|
396
|
-
var dot = dotProduct(v1, v2);
|
|
397
|
-
var magV1 = magnitude(v1);
|
|
398
|
-
var magV2 = magnitude(v2); // Ensure the dot product is within the domain of the acos function
|
|
399
|
-
|
|
400
|
-
return Math.acos(dot / (magV1 * magV2));
|
|
401
|
-
};
|
|
402
|
-
/*
|
|
403
|
-
* Function to check if a point lies between the angle formed by two lines
|
|
404
|
-
* @param {Object} commonPoint - common point of the two lines
|
|
405
|
-
* @param {Object} point1 - point 1 of cone
|
|
406
|
-
* @param {Object} point2 - point 2 of cone
|
|
407
|
-
* @param {Object} testPoint - point to be tested
|
|
408
|
-
* */
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
var pointInAngle = function pointInAngle(commonPoint, point1, point2, testPoint) {
|
|
412
|
-
var vector1 = {
|
|
413
|
-
x: point1.x - commonPoint.x,
|
|
414
|
-
y: point1.y - commonPoint.y
|
|
415
|
-
};
|
|
416
|
-
var vector2 = {
|
|
417
|
-
x: point2.x - commonPoint.x,
|
|
418
|
-
y: point2.y - commonPoint.y
|
|
419
|
-
};
|
|
420
|
-
var testVector = {
|
|
421
|
-
x: testPoint.x - commonPoint.x,
|
|
422
|
-
y: testPoint.y - commonPoint.y
|
|
423
|
-
};
|
|
424
|
-
var angle1 = angleBetweenVectors(vector1, testVector);
|
|
425
|
-
var angle2 = angleBetweenVectors(vector2, testVector);
|
|
426
|
-
var angleSum = angle1 + angle2; // Check if the sum of angles is approximately equal to the angle between the two lines
|
|
427
|
-
// You may need to adjust the tolerance (e.g., 0.0001) based on your specific requirements
|
|
428
|
-
|
|
429
|
-
var tolerance = 0.0001;
|
|
430
|
-
return Math.abs(angleSum - angleBetweenVectors(vector1, vector2)) < tolerance;
|
|
431
|
-
};
|
|
432
|
-
/*
|
|
433
|
-
* Function to remove duplicate points from an array
|
|
434
|
-
* @param {Array} array - array of points
|
|
435
|
-
* */
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
var removeDuplicatesFromArray = function removeDuplicatesFromArray(array) {
|
|
439
|
-
return array.filter(function (obj, index) {
|
|
440
|
-
return index === array.findIndex(function (o) {
|
|
441
|
-
return obj.x === o.x && obj.y === o.y;
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
};
|
|
445
|
-
/*
|
|
446
|
-
* Function to remove duplicate points and filter sections
|
|
447
|
-
* @param {Array} sections - array of sections
|
|
448
|
-
* */
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
var removeDuplicateAndFilterSections = function removeDuplicateAndFilterSections(sections) {
|
|
452
|
-
var _loop = function _loop(i) {
|
|
453
|
-
sections[i] = sections[i].filter(function (obj, index) {
|
|
454
|
-
return index === sections[i].findIndex(function (o) {
|
|
455
|
-
return obj.x === o.x && obj.y === o.y;
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
//removing duplicate points.
|
|
461
|
-
for (var i = 0; i < sections.length; i++) {
|
|
462
|
-
_loop(i);
|
|
463
|
-
} //removing arrays with two points
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
sections = sections.filter(function (section) {
|
|
467
|
-
return section.length > 2;
|
|
468
|
-
}); //sorting the points in clockwise direction
|
|
469
|
-
|
|
470
|
-
for (var _i = 0; _i < sections.length; _i++) {
|
|
471
|
-
sections[_i] = sortPointsClockWise(sections[_i]);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
return sections;
|
|
475
|
-
};
|
|
476
|
-
/*
|
|
477
|
-
* Function to find sections in solution set for one line
|
|
478
|
-
* @param {Array} intersectionPoint - intersection point
|
|
479
|
-
* @param {Object} domain - domain object
|
|
480
|
-
* @param {Object} range - range object
|
|
481
|
-
* */
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
var findSectionsInSolutionSetForOneLine = function findSectionsInSolutionSetForOneLine(intersectionPoint, domain, range) {
|
|
485
|
-
var sections = [];
|
|
486
|
-
sections.push([].concat(intersectionPoint));
|
|
487
|
-
sections.push([].concat(intersectionPoint));
|
|
488
|
-
|
|
489
|
-
if (intersectionPoint[0].x === domain.max && intersectionPoint[1].y === range.max || intersectionPoint[1].x === domain.max && intersectionPoint[0].y === range.max) {
|
|
490
|
-
sections[0].push({
|
|
491
|
-
x: domain.max,
|
|
492
|
-
y: range.max
|
|
493
|
-
});
|
|
494
|
-
sections[1].push({
|
|
495
|
-
x: domain.min,
|
|
496
|
-
y: range.max
|
|
497
|
-
}, {
|
|
498
|
-
x: domain.min,
|
|
499
|
-
y: range.min
|
|
500
|
-
}, {
|
|
501
|
-
x: domain.max,
|
|
502
|
-
y: range.min
|
|
503
|
-
});
|
|
504
|
-
} else if (intersectionPoint[0].x === domain.min && intersectionPoint[1].y === range.max || intersectionPoint[1].x === domain.min && intersectionPoint[0].y === range.max) {
|
|
505
|
-
sections[0].push({
|
|
506
|
-
x: domain.min,
|
|
507
|
-
y: range.max
|
|
508
|
-
});
|
|
509
|
-
sections[1].push({
|
|
510
|
-
x: domain.max,
|
|
511
|
-
y: range.max
|
|
512
|
-
}, {
|
|
513
|
-
x: domain.max,
|
|
514
|
-
y: range.min
|
|
515
|
-
}, {
|
|
516
|
-
x: domain.min,
|
|
517
|
-
y: range.min
|
|
518
|
-
});
|
|
519
|
-
} else if (intersectionPoint[0].x === domain.min && intersectionPoint[1].y === range.min || intersectionPoint[1].x === domain.min && intersectionPoint[0].y === range.min) {
|
|
520
|
-
sections[0].push({
|
|
521
|
-
x: domain.min,
|
|
522
|
-
y: range.min
|
|
523
|
-
});
|
|
524
|
-
sections[1].push({
|
|
525
|
-
x: domain.max,
|
|
526
|
-
y: range.min
|
|
527
|
-
}, {
|
|
528
|
-
x: domain.max,
|
|
529
|
-
y: range.max
|
|
530
|
-
}, {
|
|
531
|
-
x: domain.min,
|
|
532
|
-
y: range.max
|
|
533
|
-
});
|
|
534
|
-
} else if (intersectionPoint[0].x === domain.max && intersectionPoint[1].y === range.min || intersectionPoint[1].x === domain.max && intersectionPoint[0].y === range.min) {
|
|
535
|
-
sections[0].push({
|
|
536
|
-
x: domain.max,
|
|
537
|
-
y: range.min
|
|
538
|
-
});
|
|
539
|
-
sections[1].push({
|
|
540
|
-
x: domain.min,
|
|
541
|
-
y: range.min
|
|
542
|
-
}, {
|
|
543
|
-
x: domain.min,
|
|
544
|
-
y: range.max
|
|
545
|
-
}, {
|
|
546
|
-
x: domain.max,
|
|
547
|
-
y: range.max
|
|
548
|
-
});
|
|
549
|
-
} else if (intersectionPoint[0].x === domain.min && intersectionPoint[1].x === domain.max || intersectionPoint[0].x === domain.max && intersectionPoint[1].x === domain.min) {
|
|
550
|
-
sections[0].push({
|
|
551
|
-
x: domain.min,
|
|
552
|
-
y: range.max
|
|
553
|
-
}, {
|
|
554
|
-
x: domain.max,
|
|
555
|
-
y: range.max
|
|
556
|
-
});
|
|
557
|
-
sections[1].push({
|
|
558
|
-
x: domain.min,
|
|
559
|
-
y: range.min
|
|
560
|
-
}, {
|
|
561
|
-
x: domain.max,
|
|
562
|
-
y: range.min
|
|
563
|
-
});
|
|
564
|
-
} else if (intersectionPoint[0].y === range.min && intersectionPoint[1].y === range.max || intersectionPoint[0].y === range.max && intersectionPoint[1].y === range.min) {
|
|
565
|
-
sections[0].push({
|
|
566
|
-
x: domain.min,
|
|
567
|
-
y: range.min
|
|
568
|
-
}, {
|
|
569
|
-
x: domain.min,
|
|
570
|
-
y: range.max
|
|
571
|
-
});
|
|
572
|
-
sections[1].push({
|
|
573
|
-
x: domain.max,
|
|
574
|
-
y: range.min
|
|
575
|
-
}, {
|
|
576
|
-
x: domain.max,
|
|
577
|
-
y: range.max
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
return removeDuplicateAndFilterSections(sections);
|
|
582
|
-
};
|
|
583
|
-
/*
|
|
584
|
-
* Function to find sections in solution set for two lines
|
|
585
|
-
* @param {Object} gssLineData - graphing solution set line data
|
|
586
|
-
* @param {Array} answers - answers array
|
|
587
|
-
* @param {Object} domain - domain object
|
|
588
|
-
* @param {Object} range - range object
|
|
589
|
-
* */
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
var findSectionsInSolutionSetForTwoLines = function findSectionsInSolutionSetForTwoLines(gssLineData, answers, domain, range) {
|
|
593
|
-
var mark1 = answers[0];
|
|
594
|
-
var mark2 = answers[1];
|
|
595
|
-
var cornerPoints = [{
|
|
596
|
-
x: domain.min,
|
|
597
|
-
y: range.min
|
|
598
|
-
}, {
|
|
599
|
-
x: domain.min,
|
|
600
|
-
y: range.max
|
|
601
|
-
}, {
|
|
602
|
-
x: domain.max,
|
|
603
|
-
y: range.min
|
|
604
|
-
}, {
|
|
605
|
-
x: domain.max,
|
|
606
|
-
y: range.max
|
|
607
|
-
}];
|
|
608
|
-
var intersectPoint = lineIntersect(mark1.from.x, mark1.from.y, mark1.to.x, mark1.to.y, mark2.from.x, mark2.from.y, mark2.to.x, mark2.to.y);
|
|
609
|
-
var sections = [];
|
|
610
|
-
var intersectionPoint1 = findIntersectionPointForMark(mark1, domain, range);
|
|
611
|
-
intersectionPoint1 = removeDuplicatesFromArray(intersectionPoint1);
|
|
612
|
-
var intersectionPoint2 = findIntersectionPointForMark(mark2, domain, range);
|
|
613
|
-
intersectionPoint2 = removeDuplicatesFromArray(intersectionPoint2);
|
|
614
|
-
|
|
615
|
-
if (intersectPoint && isPointInsideGraph(intersectPoint, domain, range)) {
|
|
616
|
-
for (var i = 0; i < intersectionPoint1.length; i++) {
|
|
617
|
-
for (var j = 0; j < intersectionPoint2.length; j++) {
|
|
618
|
-
var bucket = [];
|
|
619
|
-
var newCornerPoints = [];
|
|
620
|
-
bucket.push(intersectPoint);
|
|
621
|
-
bucket.push(intersectionPoint1[i]);
|
|
622
|
-
bucket.push(intersectionPoint2[j]);
|
|
623
|
-
|
|
624
|
-
for (var k = 0; k < cornerPoints.length; k++) {
|
|
625
|
-
if (pointInAngle(intersectPoint, intersectionPoint1[i], intersectionPoint2[j], cornerPoints[k])) {
|
|
626
|
-
bucket.push(cornerPoints[k]);
|
|
627
|
-
} else {
|
|
628
|
-
newCornerPoints.push(cornerPoints[k]);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
cornerPoints = newCornerPoints;
|
|
633
|
-
sections.push(bucket);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
} else {
|
|
637
|
-
var sections1 = findSectionsInSolutionSetForOneLine(intersectionPoint1, domain, range);
|
|
638
|
-
var sections2 = findSectionsInSolutionSetForOneLine(intersectionPoint2, domain, range);
|
|
639
|
-
|
|
640
|
-
for (var _i2 = 0; _i2 < sections1.length; _i2++) {
|
|
641
|
-
if (!(pointInPolygon(intersectionPoint2[0], sections1[_i2]) && pointInPolygon(intersectionPoint2[1], sections1[_i2]))) {
|
|
642
|
-
sections.push(sections1[_i2]);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
for (var _i3 = 0; _i3 < sections2.length; _i3++) {
|
|
647
|
-
if (!(pointInPolygon(intersectionPoint1[0], sections2[_i3]) && pointInPolygon(intersectionPoint1[1], sections2[_i3]))) {
|
|
648
|
-
sections.push(sections2[_i3]);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
var _loop2 = function _loop2(_i4) {
|
|
653
|
-
cornerPoints = cornerPoints.filter(function (o1) {
|
|
654
|
-
return !sections[_i4].some(function (o2) {
|
|
655
|
-
return o1.x === o2.x && o1.y === o2.y;
|
|
656
|
-
});
|
|
657
|
-
});
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
for (var _i4 = 0; _i4 < sections.length; _i4++) {
|
|
661
|
-
_loop2(_i4);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
var sections3 = cornerPoints.concat(intersectionPoint1, intersectionPoint2);
|
|
665
|
-
sections.push(sections3);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
return removeDuplicateAndFilterSections(sections);
|
|
669
|
-
};
|
|
670
|
-
/*
|
|
671
|
-
* Function to find sections in solution set
|
|
672
|
-
* @param {Object} gssLineData - graphing solution set line data
|
|
673
|
-
* @param {Array} answers - answers array
|
|
674
|
-
* @param {Object} domain - domain object
|
|
675
|
-
* @param {Object} range - range object
|
|
676
|
-
* */
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
var findSectionsInSolutionSet = function findSectionsInSolutionSet(gssLineData, answers, domain, range) {
|
|
680
|
-
if (gssLineData.numberOfLines === 1) {
|
|
681
|
-
var intersectionPoint = findIntersectionPointForMark(answers[0], domain, range);
|
|
682
|
-
gssLineData.sections = findSectionsInSolutionSetForOneLine(intersectionPoint, domain, range);
|
|
683
|
-
} else {
|
|
684
|
-
gssLineData.sections = findSectionsInSolutionSetForTwoLines(gssLineData, answers, domain, range);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
return gssLineData;
|
|
688
|
-
};
|
|
689
|
-
/*
|
|
690
|
-
* Function to check if a point is inside a polygon
|
|
691
|
-
* @param {Object} point - point to be checked
|
|
692
|
-
* @param {Array} polygon - polygon points array
|
|
693
|
-
* */
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
exports.findSectionsInSolutionSet = findSectionsInSolutionSet;
|
|
697
|
-
|
|
698
|
-
var pointInsidePolygon = function pointInsidePolygon(point, polygon) {
|
|
699
|
-
var num_vertices = polygon.length;
|
|
700
|
-
var x = point.x;
|
|
701
|
-
var y = point.y;
|
|
702
|
-
var inside = false;
|
|
703
|
-
var p1 = polygon[0];
|
|
704
|
-
var p2;
|
|
705
|
-
|
|
706
|
-
for (var i = 1; i <= num_vertices; i++) {
|
|
707
|
-
p2 = polygon[i % num_vertices];
|
|
708
|
-
|
|
709
|
-
if (y > Math.min(p1.y, p2.y)) {
|
|
710
|
-
if (y <= Math.max(p1.y, p2.y)) {
|
|
711
|
-
if (x <= Math.max(p1.x, p2.x)) {
|
|
712
|
-
var x_intersection = (y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
|
|
713
|
-
|
|
714
|
-
if (p1.x === p2.x || x <= x_intersection) {
|
|
715
|
-
inside = !inside;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
p1 = p2;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
return inside;
|
|
725
|
-
};
|
|
726
|
-
/*
|
|
727
|
-
* Function to check if lines are added in the graph
|
|
728
|
-
* @param {Object} gssLineData - graphing solution set line data
|
|
729
|
-
* @param {Array} answer - answer array
|
|
730
|
-
* */
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
exports.pointInsidePolygon = pointInsidePolygon;
|
|
734
|
-
|
|
735
|
-
var checkIfLinesAreAdded = function checkIfLinesAreAdded(gssLineData, answer) {
|
|
736
|
-
if (answer.length === 0) {
|
|
737
|
-
return false;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (gssLineData.numberOfLines === 1) {
|
|
741
|
-
if (answer.length === 1) {
|
|
742
|
-
return !answer[0].building;
|
|
743
|
-
}
|
|
744
|
-
} else {
|
|
745
|
-
if (answer.length !== 2) {
|
|
746
|
-
return false;
|
|
747
|
-
} else {
|
|
748
|
-
return !answer[1].building;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
exports.checkIfLinesAreAdded = checkIfLinesAreAdded;
|
|
754
|
-
//# sourceMappingURL=utils.js.map
|