@pie-element/graphing-solution-set 4.3.4-next.0 → 5.0.0-beta.0

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