@pie-element/graphing-solution-set 4.3.4-next.3 → 5.0.0-beta.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/CHANGELOG.md +0 -11
- package/configure/CHANGELOG.md +0 -11
- package/configure/lib/configure.js +289 -377
- package/configure/lib/configure.js.map +1 -1
- package/configure/lib/correct-response.js +309 -475
- package/configure/lib/correct-response.js.map +1 -1
- package/configure/lib/defaults.js +2 -4
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/graphing-config.js +329 -363
- package/configure/lib/graphing-config.js.map +1 -1
- package/configure/lib/index.js +126 -181
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +178 -301
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +12 -8
- package/controller/lib/defaults.js +2 -4
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +146 -218
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +85 -142
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +3 -3
- package/lib/index.js +120 -170
- package/lib/index.js.map +1 -1
- package/lib/main.js +261 -350
- package/lib/main.js.map +1 -1
- package/lib/utils.js +142 -231
- package/lib/utils.js.map +1 -1
- package/package.json +14 -10
- package/esm/configure.js +0 -43958
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -22735
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -26572
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
package/lib/utils.js
CHANGED
|
@@ -1,44 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.removeInvalidAnswers = exports.pointInsidePolygon = exports.findSectionsInSolutionSet = exports.checkIfLinesAreAdded = 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 _excluded = ["angle"],
|
|
15
|
-
_excluded2 = ["type"];
|
|
16
|
-
|
|
17
7
|
/*
|
|
18
8
|
* Check if a line is complete
|
|
19
9
|
* @param {Object} item - mark object
|
|
20
10
|
* */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
11
|
+
const completeFromTo = item => item && completeMark.point(item.from) && completeMark.point(item.to);
|
|
12
|
+
|
|
24
13
|
/*
|
|
25
14
|
* Check if a point is correct and complete
|
|
26
15
|
* @param {Object} point - point object
|
|
27
16
|
* */
|
|
17
|
+
const completePoint = point => point && Number.isFinite(point.x) && Number.isFinite(point.y);
|
|
28
18
|
|
|
29
|
-
|
|
30
|
-
var completePoint = function completePoint(point) {
|
|
31
|
-
return point && Number.isFinite(point.x) && Number.isFinite(point.y);
|
|
32
|
-
};
|
|
33
19
|
/*
|
|
34
20
|
* Complete mark object for line and point
|
|
35
21
|
* */
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var completeMark = {
|
|
22
|
+
const completeMark = {
|
|
39
23
|
line: completeFromTo,
|
|
40
24
|
point: completePoint
|
|
41
|
-
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//////////////////////////////////////////////////////////////////////////////////
|
|
42
28
|
// BELOW FUNCTIONS ARE USED IN configure/src/utils as well
|
|
43
29
|
//////////////////////////////////////////////////////////////////////////////////
|
|
44
30
|
|
|
@@ -47,35 +33,32 @@ var completeMark = {
|
|
|
47
33
|
* @param {Object} a - point a
|
|
48
34
|
* @param {Object} b - point b
|
|
49
35
|
* */
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return Number(Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)).toFixed(3));
|
|
36
|
+
const distance = (a, b) => {
|
|
37
|
+
return Number(Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2).toFixed(3));
|
|
53
38
|
};
|
|
39
|
+
|
|
54
40
|
/*
|
|
55
41
|
* Function to check if a point lies on edges of a polygon
|
|
56
42
|
* @param {Object} point - point object
|
|
57
43
|
* @param {Array} polygon - polygon points array
|
|
58
44
|
* */
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var inside = false;
|
|
64
|
-
var clonePolygon = (0, _toConsumableArray2["default"])(polygon);
|
|
45
|
+
const pointInPolygon = (point, polygon) => {
|
|
46
|
+
let c = point;
|
|
47
|
+
let inside = false;
|
|
48
|
+
let clonePolygon = [...polygon];
|
|
65
49
|
clonePolygon.push(polygon[0]);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
for (let i = 0; i < clonePolygon.length - 1; i++) {
|
|
51
|
+
let a = clonePolygon[i];
|
|
52
|
+
let b = clonePolygon[i + 1];
|
|
53
|
+
// check if point is on the edge
|
|
71
54
|
if (distance(a, c) + distance(c, b) === distance(a, b)) {
|
|
72
55
|
inside = true;
|
|
73
56
|
break;
|
|
74
57
|
}
|
|
75
58
|
}
|
|
76
|
-
|
|
77
59
|
return inside;
|
|
78
60
|
};
|
|
61
|
+
|
|
79
62
|
/*
|
|
80
63
|
* Function to get the intersection point of two lines
|
|
81
64
|
* @param {Number} x1 - x coordinate of point 1 of line 1
|
|
@@ -87,95 +70,79 @@ var pointInPolygon = function pointInPolygon(point, polygon) {
|
|
|
87
70
|
* @param {Number} x4 - x coordinate of point 2 of line 2
|
|
88
71
|
* @param {Number} y4 - y coordinate of point 2 of line 2
|
|
89
72
|
* */
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var ua,
|
|
94
|
-
denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
|
95
|
-
|
|
73
|
+
const lineIntersect = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
74
|
+
let ua,
|
|
75
|
+
denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
|
|
96
76
|
if (denominator === 0) {
|
|
97
77
|
return null;
|
|
98
78
|
}
|
|
99
|
-
|
|
100
79
|
ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denominator;
|
|
101
80
|
return {
|
|
102
81
|
x: Number((x1 + ua * (x2 - x1)).toFixed(3)),
|
|
103
82
|
y: Number((y1 + ua * (y2 - y1)).toFixed(3))
|
|
104
83
|
};
|
|
105
84
|
};
|
|
85
|
+
|
|
106
86
|
/*
|
|
107
87
|
* Check if a point is inside the graph
|
|
108
88
|
* @param {Object} point - point object
|
|
109
89
|
* @param {Object} domain - domain object
|
|
110
90
|
* @param {Object} range - range object
|
|
111
91
|
* */
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
var isPointInsideGraph = function isPointInsideGraph(point, domain, range) {
|
|
92
|
+
const isPointInsideGraph = (point, domain, range) => {
|
|
115
93
|
return point.x > domain.min && point.x < domain.max && point.y > range.min && point.y < range.max;
|
|
116
94
|
};
|
|
95
|
+
|
|
117
96
|
/*
|
|
118
97
|
* Check if a point is on or inside the graph
|
|
119
98
|
* @param {Object} point - point object
|
|
120
99
|
* @param {Object} domain - domain object
|
|
121
100
|
* @param {Object} range - range object
|
|
122
101
|
* */
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var isPointOnOrInsideGraph = function isPointOnOrInsideGraph(point, domain, range) {
|
|
102
|
+
const isPointOnOrInsideGraph = (point, domain, range) => {
|
|
126
103
|
return point.x >= domain.min && point.x <= domain.max && point.y >= range.min && point.y <= range.max;
|
|
127
104
|
};
|
|
105
|
+
|
|
128
106
|
/*
|
|
129
107
|
* Find the intersection point of a mark with the graph
|
|
130
108
|
* @param {Object} mark - mark object
|
|
131
109
|
* @param {Object} domain - domain object
|
|
132
110
|
* @param {Object} range - range object
|
|
133
111
|
* */
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
for (var i = 0; i < tempData.length; i++) {
|
|
141
|
-
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]);
|
|
142
|
-
|
|
112
|
+
const findIntersectionPointForMark = (mark, domain, range) => {
|
|
113
|
+
let intersectionPoint = [];
|
|
114
|
+
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]];
|
|
115
|
+
for (let i = 0; i < tempData.length; i++) {
|
|
116
|
+
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]);
|
|
143
117
|
if (intersection && isPointOnOrInsideGraph(intersection, domain, range)) {
|
|
144
118
|
intersectionPoint.push(intersection);
|
|
145
119
|
}
|
|
146
120
|
}
|
|
147
|
-
|
|
148
121
|
return intersectionPoint;
|
|
149
122
|
};
|
|
123
|
+
|
|
150
124
|
/*
|
|
151
125
|
* Sort points in clockwise direction for a polygon
|
|
152
126
|
* @param {Array} points - points array
|
|
153
127
|
* */
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
var sortPointsClockWise = function sortPointsClockWise(points) {
|
|
128
|
+
const sortPointsClockWise = points => {
|
|
157
129
|
// Find min max to get center and Sort from top to bottom
|
|
158
|
-
points.sort(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
points.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
var cx = (points[0].x + points[points.length - 1].x) / 2; // Center point
|
|
169
|
-
|
|
170
|
-
var center = {
|
|
130
|
+
points.sort((a, b) => a.y - b.y);
|
|
131
|
+
// Get center y
|
|
132
|
+
const cy = (points[0].y + points[points.length - 1].y) / 2;
|
|
133
|
+
// Sort from right to left
|
|
134
|
+
points.sort((a, b) => b.x - a.x);
|
|
135
|
+
// Get center x
|
|
136
|
+
const cx = (points[0].x + points[points.length - 1].x) / 2;
|
|
137
|
+
// Center point
|
|
138
|
+
const center = {
|
|
171
139
|
x: cx,
|
|
172
140
|
y: cy
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
points.forEach(
|
|
177
|
-
|
|
178
|
-
|
|
141
|
+
};
|
|
142
|
+
// As the points are sorted from right to left the first point is the rightmost Starting angle used to reference other angles
|
|
143
|
+
let startAng;
|
|
144
|
+
points.forEach(point => {
|
|
145
|
+
let ang = Math.atan2(point.y - center.y, point.x - center.x);
|
|
179
146
|
if (!startAng) {
|
|
180
147
|
startAng = ang;
|
|
181
148
|
} else {
|
|
@@ -184,56 +151,50 @@ var sortPointsClockWise = function sortPointsClockWise(points) {
|
|
|
184
151
|
ang += Math.PI * 2;
|
|
185
152
|
}
|
|
186
153
|
}
|
|
187
|
-
|
|
188
154
|
point.angle = ang; // add the angle to the point
|
|
189
|
-
}); // first sort clockwise
|
|
190
|
-
|
|
191
|
-
points.sort(function (a, b) {
|
|
192
|
-
return a.angle - b.angle;
|
|
193
|
-
}); // then reverse the order
|
|
194
|
-
|
|
195
|
-
var ccwPoints = points.reverse(); // move the last point back to the start
|
|
196
|
-
|
|
197
|
-
ccwPoints.unshift(ccwPoints.pop());
|
|
198
|
-
return ccwPoints.map(function (_ref) {
|
|
199
|
-
var angle = _ref.angle,
|
|
200
|
-
attr = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
201
|
-
return attr;
|
|
202
155
|
});
|
|
156
|
+
// first sort clockwise
|
|
157
|
+
points.sort((a, b) => a.angle - b.angle);
|
|
158
|
+
// then reverse the order
|
|
159
|
+
const ccwPoints = points.reverse();
|
|
160
|
+
// move the last point back to the start
|
|
161
|
+
ccwPoints.unshift(ccwPoints.pop());
|
|
162
|
+
return ccwPoints.map(({
|
|
163
|
+
angle,
|
|
164
|
+
...attr
|
|
165
|
+
}) => attr);
|
|
203
166
|
};
|
|
167
|
+
|
|
204
168
|
/*
|
|
205
169
|
* Function to calculate the dot product of two vectors
|
|
206
170
|
* @param {Object} v1 - point 1
|
|
207
171
|
* @param {Object} v2 - point 2
|
|
208
172
|
* */
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
var dotProduct = function dotProduct(v1, v2) {
|
|
173
|
+
const dotProduct = (v1, v2) => {
|
|
212
174
|
return v1.x * v2.x + v1.y * v2.y;
|
|
213
175
|
};
|
|
176
|
+
|
|
214
177
|
/*
|
|
215
178
|
* Function to calculate the magnitude of a vector
|
|
216
179
|
* @param {Object} v - point object
|
|
217
180
|
* */
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
var magnitude = function magnitude(v) {
|
|
181
|
+
const magnitude = v => {
|
|
221
182
|
return Math.sqrt(v.x * v.x + v.y * v.y);
|
|
222
183
|
};
|
|
184
|
+
|
|
223
185
|
/*
|
|
224
186
|
* Function to calculate the angle between two vectors in radians
|
|
225
187
|
* @param {Object} v1 - point 1
|
|
226
188
|
* @param {Object} v2 - point 2
|
|
227
189
|
* */
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
var magV2 = magnitude(v2); // Ensure the dot product is within the domain of the acos function
|
|
234
|
-
|
|
190
|
+
const angleBetweenVectors = (v1, v2) => {
|
|
191
|
+
const dot = dotProduct(v1, v2);
|
|
192
|
+
const magV1 = magnitude(v1);
|
|
193
|
+
const magV2 = magnitude(v2);
|
|
194
|
+
// Ensure the dot product is within the domain of the acos function
|
|
235
195
|
return Math.acos(dot / (magV1 * magV2));
|
|
236
196
|
};
|
|
197
|
+
|
|
237
198
|
/*
|
|
238
199
|
* Function to check if a point lies between the angle formed by two lines
|
|
239
200
|
* @param {Object} commonPoint - common point of the two lines
|
|
@@ -241,86 +202,68 @@ var angleBetweenVectors = function angleBetweenVectors(v1, v2) {
|
|
|
241
202
|
* @param {Object} point2 - point 2 of cone
|
|
242
203
|
* @param {Object} testPoint - point to be tested
|
|
243
204
|
* */
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
var pointInAngle = function pointInAngle(commonPoint, point1, point2, testPoint) {
|
|
247
|
-
var vector1 = {
|
|
205
|
+
const pointInAngle = (commonPoint, point1, point2, testPoint) => {
|
|
206
|
+
const vector1 = {
|
|
248
207
|
x: point1.x - commonPoint.x,
|
|
249
208
|
y: point1.y - commonPoint.y
|
|
250
209
|
};
|
|
251
|
-
|
|
210
|
+
const vector2 = {
|
|
252
211
|
x: point2.x - commonPoint.x,
|
|
253
212
|
y: point2.y - commonPoint.y
|
|
254
213
|
};
|
|
255
|
-
|
|
214
|
+
const testVector = {
|
|
256
215
|
x: testPoint.x - commonPoint.x,
|
|
257
216
|
y: testPoint.y - commonPoint.y
|
|
258
217
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
218
|
+
const angle1 = angleBetweenVectors(vector1, testVector);
|
|
219
|
+
const angle2 = angleBetweenVectors(vector2, testVector);
|
|
220
|
+
const angleSum = angle1 + angle2;
|
|
221
|
+
// Check if the sum of angles is approximately equal to the angle between the two lines
|
|
262
222
|
// You may need to adjust the tolerance (e.g., 0.0001) based on your specific requirements
|
|
263
|
-
|
|
264
|
-
var tolerance = 0.0001;
|
|
223
|
+
const tolerance = 0.0001;
|
|
265
224
|
return Math.abs(angleSum - angleBetweenVectors(vector1, vector2)) < tolerance;
|
|
266
225
|
};
|
|
226
|
+
|
|
267
227
|
/*
|
|
268
228
|
* Function to remove duplicate points from an array
|
|
269
229
|
* @param {Array} array - array of points
|
|
270
230
|
* */
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return array.filter(function (obj, index) {
|
|
275
|
-
return index === array.findIndex(function (o) {
|
|
276
|
-
return obj.x === o.x && obj.y === o.y;
|
|
277
|
-
});
|
|
231
|
+
const removeDuplicatesFromArray = array => {
|
|
232
|
+
return array.filter((obj, index) => {
|
|
233
|
+
return index === array.findIndex(o => obj.x === o.x && obj.y === o.y);
|
|
278
234
|
});
|
|
279
235
|
};
|
|
236
|
+
|
|
280
237
|
/*
|
|
281
238
|
* Function to remove duplicate points and filter sections
|
|
282
239
|
* @param {Array} sections - array of sections
|
|
283
240
|
* */
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
var removeDuplicateAndFilterSections = function removeDuplicateAndFilterSections(sections) {
|
|
287
|
-
var _loop = function _loop(i) {
|
|
288
|
-
sections[i] = sections[i].filter(function (obj, index) {
|
|
289
|
-
return index === sections[i].findIndex(function (o) {
|
|
290
|
-
return obj.x === o.x && obj.y === o.y;
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
|
|
241
|
+
const removeDuplicateAndFilterSections = sections => {
|
|
295
242
|
//removing duplicate points.
|
|
296
|
-
for (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
sections[_i] = sortPointsClockWise(sections[_i]);
|
|
243
|
+
for (let i = 0; i < sections.length; i++) {
|
|
244
|
+
sections[i] = sections[i].filter((obj, index) => {
|
|
245
|
+
return index === sections[i].findIndex(o => obj.x === o.x && obj.y === o.y);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
//removing arrays with two points
|
|
249
|
+
sections = sections.filter(section => section.length > 2);
|
|
250
|
+
//sorting the points in clockwise direction
|
|
251
|
+
for (let i = 0; i < sections.length; i++) {
|
|
252
|
+
sections[i] = sortPointsClockWise(sections[i]);
|
|
307
253
|
}
|
|
308
|
-
|
|
309
254
|
return sections;
|
|
310
255
|
};
|
|
256
|
+
|
|
311
257
|
/*
|
|
312
258
|
* Function to find sections in solution set for one line
|
|
313
259
|
* @param {Array} intersectionPoint - intersection point
|
|
314
260
|
* @param {Object} domain - domain object
|
|
315
261
|
* @param {Object} range - range object
|
|
316
262
|
* */
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
var findSectionsInSolutionSetForOneLine = function findSectionsInSolutionSetForOneLine(intersectionPoint, domain, range) {
|
|
320
|
-
var sections = [];
|
|
263
|
+
const findSectionsInSolutionSetForOneLine = (intersectionPoint, domain, range) => {
|
|
264
|
+
let sections = [];
|
|
321
265
|
sections.push([].concat(intersectionPoint));
|
|
322
266
|
sections.push([].concat(intersectionPoint));
|
|
323
|
-
|
|
324
267
|
if (intersectionPoint[0].x === domain.max && intersectionPoint[1].y === range.max || intersectionPoint[1].x === domain.max && intersectionPoint[0].y === range.max) {
|
|
325
268
|
sections[0].push({
|
|
326
269
|
x: domain.max,
|
|
@@ -412,9 +355,9 @@ var findSectionsInSolutionSetForOneLine = function findSectionsInSolutionSetForO
|
|
|
412
355
|
y: range.max
|
|
413
356
|
});
|
|
414
357
|
}
|
|
415
|
-
|
|
416
358
|
return removeDuplicateAndFilterSections(sections);
|
|
417
359
|
};
|
|
360
|
+
|
|
418
361
|
/*
|
|
419
362
|
* Function to find sections in solution set for two lines
|
|
420
363
|
* @param {Object} gssLineData - graphing solution set line data
|
|
@@ -422,12 +365,10 @@ var findSectionsInSolutionSetForOneLine = function findSectionsInSolutionSetForO
|
|
|
422
365
|
* @param {Object} domain - domain object
|
|
423
366
|
* @param {Object} range - range object
|
|
424
367
|
* */
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
var mark2 = answers[1];
|
|
430
|
-
var cornerPoints = [{
|
|
368
|
+
const findSectionsInSolutionSetForTwoLines = (gssLineData, answers, domain, range) => {
|
|
369
|
+
let mark1 = answers[0];
|
|
370
|
+
let mark2 = answers[1];
|
|
371
|
+
let cornerPoints = [{
|
|
431
372
|
x: domain.min,
|
|
432
373
|
y: range.min
|
|
433
374
|
}, {
|
|
@@ -440,68 +381,57 @@ var findSectionsInSolutionSetForTwoLines = function findSectionsInSolutionSetFor
|
|
|
440
381
|
x: domain.max,
|
|
441
382
|
y: range.max
|
|
442
383
|
}];
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
384
|
+
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);
|
|
385
|
+
let sections = [];
|
|
386
|
+
let intersectionPoint1 = findIntersectionPointForMark(mark1, domain, range);
|
|
446
387
|
intersectionPoint1 = removeDuplicatesFromArray(intersectionPoint1);
|
|
447
|
-
|
|
388
|
+
let intersectionPoint2 = findIntersectionPointForMark(mark2, domain, range);
|
|
448
389
|
intersectionPoint2 = removeDuplicatesFromArray(intersectionPoint2);
|
|
449
|
-
|
|
450
390
|
if (intersectPoint && isPointInsideGraph(intersectPoint, domain, range)) {
|
|
451
|
-
for (
|
|
452
|
-
for (
|
|
453
|
-
|
|
454
|
-
|
|
391
|
+
for (let i = 0; i < intersectionPoint1.length; i++) {
|
|
392
|
+
for (let j = 0; j < intersectionPoint2.length; j++) {
|
|
393
|
+
let bucket = [];
|
|
394
|
+
let newCornerPoints = [];
|
|
455
395
|
bucket.push(intersectPoint);
|
|
456
396
|
bucket.push(intersectionPoint1[i]);
|
|
457
397
|
bucket.push(intersectionPoint2[j]);
|
|
458
|
-
|
|
459
|
-
for (var k = 0; k < cornerPoints.length; k++) {
|
|
398
|
+
for (let k = 0; k < cornerPoints.length; k++) {
|
|
460
399
|
if (pointInAngle(intersectPoint, intersectionPoint1[i], intersectionPoint2[j], cornerPoints[k])) {
|
|
461
400
|
bucket.push(cornerPoints[k]);
|
|
462
401
|
} else {
|
|
463
402
|
newCornerPoints.push(cornerPoints[k]);
|
|
464
403
|
}
|
|
465
404
|
}
|
|
466
|
-
|
|
467
405
|
cornerPoints = newCornerPoints;
|
|
468
406
|
sections.push(bucket);
|
|
469
407
|
}
|
|
470
408
|
}
|
|
471
409
|
} else {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
sections.push(sections1[_i2]);
|
|
410
|
+
let sections1 = findSectionsInSolutionSetForOneLine(intersectionPoint1, domain, range);
|
|
411
|
+
let sections2 = findSectionsInSolutionSetForOneLine(intersectionPoint2, domain, range);
|
|
412
|
+
for (let i = 0; i < sections1.length; i++) {
|
|
413
|
+
if (!(pointInPolygon(intersectionPoint2[0], sections1[i]) && pointInPolygon(intersectionPoint2[1], sections1[i]))) {
|
|
414
|
+
sections.push(sections1[i]);
|
|
478
415
|
}
|
|
479
416
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
sections.push(sections2[_i3]);
|
|
417
|
+
for (let i = 0; i < sections2.length; i++) {
|
|
418
|
+
if (!(pointInPolygon(intersectionPoint1[0], sections2[i]) && pointInPolygon(intersectionPoint1[1], sections2[i]))) {
|
|
419
|
+
sections.push(sections2[i]);
|
|
484
420
|
}
|
|
485
421
|
}
|
|
486
|
-
|
|
487
|
-
var _loop2 = function _loop2(_i4) {
|
|
422
|
+
for (let i = 0; i < sections.length; i++) {
|
|
488
423
|
cornerPoints = cornerPoints.filter(function (o1) {
|
|
489
|
-
return !sections[
|
|
424
|
+
return !sections[i].some(function (o2) {
|
|
490
425
|
return o1.x === o2.x && o1.y === o2.y;
|
|
491
426
|
});
|
|
492
427
|
});
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
for (var _i4 = 0; _i4 < sections.length; _i4++) {
|
|
496
|
-
_loop2(_i4);
|
|
497
428
|
}
|
|
498
|
-
|
|
499
|
-
var sections3 = cornerPoints.concat(intersectionPoint1, intersectionPoint2);
|
|
429
|
+
let sections3 = cornerPoints.concat(intersectionPoint1, intersectionPoint2);
|
|
500
430
|
sections.push(sections3);
|
|
501
431
|
}
|
|
502
|
-
|
|
503
432
|
return removeDuplicateAndFilterSections(sections);
|
|
504
433
|
};
|
|
434
|
+
|
|
505
435
|
/*
|
|
506
436
|
* Function to find sections in solution set
|
|
507
437
|
* @param {Object} gssLineData - graphing solution set line data
|
|
@@ -509,69 +439,56 @@ var findSectionsInSolutionSetForTwoLines = function findSectionsInSolutionSetFor
|
|
|
509
439
|
* @param {Object} domain - domain object
|
|
510
440
|
* @param {Object} range - range object
|
|
511
441
|
* */
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
var findSectionsInSolutionSet = function findSectionsInSolutionSet(gssLineData, answers, domain, range) {
|
|
442
|
+
const findSectionsInSolutionSet = (gssLineData, answers, domain, range) => {
|
|
515
443
|
if (gssLineData.numberOfLines === 1) {
|
|
516
|
-
|
|
444
|
+
const intersectionPoint = findIntersectionPointForMark(answers[0], domain, range);
|
|
517
445
|
gssLineData.sections = findSectionsInSolutionSetForOneLine(intersectionPoint, domain, range);
|
|
518
446
|
} else {
|
|
519
447
|
gssLineData.sections = findSectionsInSolutionSetForTwoLines(gssLineData, answers, domain, range);
|
|
520
448
|
}
|
|
521
|
-
|
|
522
449
|
return gssLineData;
|
|
523
450
|
};
|
|
451
|
+
|
|
524
452
|
/*
|
|
525
453
|
* Function to check if a point is inside a polygon
|
|
526
454
|
* @param {Object} point - point to be checked
|
|
527
455
|
* @param {Array} polygon - polygon points array
|
|
528
456
|
* */
|
|
529
|
-
|
|
530
|
-
|
|
531
457
|
exports.findSectionsInSolutionSet = findSectionsInSolutionSet;
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
for (var i = 1; i <= num_vertices; i++) {
|
|
458
|
+
const pointInsidePolygon = (point, polygon) => {
|
|
459
|
+
const num_vertices = polygon.length;
|
|
460
|
+
const x = point.x;
|
|
461
|
+
const y = point.y;
|
|
462
|
+
let inside = false;
|
|
463
|
+
let p1 = polygon[0];
|
|
464
|
+
let p2;
|
|
465
|
+
for (let i = 1; i <= num_vertices; i++) {
|
|
542
466
|
p2 = polygon[i % num_vertices];
|
|
543
|
-
|
|
544
467
|
if (y > Math.min(p1.y, p2.y)) {
|
|
545
468
|
if (y <= Math.max(p1.y, p2.y)) {
|
|
546
469
|
if (x <= Math.max(p1.x, p2.x)) {
|
|
547
|
-
|
|
548
|
-
|
|
470
|
+
const x_intersection = (y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
|
|
549
471
|
if (p1.x === p2.x || x <= x_intersection) {
|
|
550
472
|
inside = !inside;
|
|
551
473
|
}
|
|
552
474
|
}
|
|
553
475
|
}
|
|
554
476
|
}
|
|
555
|
-
|
|
556
477
|
p1 = p2;
|
|
557
478
|
}
|
|
558
|
-
|
|
559
479
|
return inside;
|
|
560
480
|
};
|
|
481
|
+
|
|
561
482
|
/*
|
|
562
483
|
* Function to check if lines are added in the graph
|
|
563
484
|
* @param {Object} gssLineData - graphing solution set line data
|
|
564
485
|
* @param {Array} answer - answer array
|
|
565
486
|
* */
|
|
566
|
-
|
|
567
|
-
|
|
568
487
|
exports.pointInsidePolygon = pointInsidePolygon;
|
|
569
|
-
|
|
570
|
-
var checkIfLinesAreAdded = function checkIfLinesAreAdded(gssLineData, answer) {
|
|
488
|
+
const checkIfLinesAreAdded = (gssLineData, answer) => {
|
|
571
489
|
if (answer.length === 0) {
|
|
572
490
|
return false;
|
|
573
491
|
}
|
|
574
|
-
|
|
575
492
|
if (gssLineData.numberOfLines === 1) {
|
|
576
493
|
if (answer.length === 1) {
|
|
577
494
|
return !answer[0].building;
|
|
@@ -584,21 +501,15 @@ var checkIfLinesAreAdded = function checkIfLinesAreAdded(gssLineData, answer) {
|
|
|
584
501
|
}
|
|
585
502
|
}
|
|
586
503
|
};
|
|
504
|
+
|
|
587
505
|
/*
|
|
588
506
|
* Function to remove invalid answers
|
|
589
507
|
* @param {Array} answers - answers array
|
|
590
508
|
* */
|
|
591
|
-
|
|
592
|
-
|
|
593
509
|
exports.checkIfLinesAreAdded = checkIfLinesAreAdded;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
answer = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2);
|
|
599
|
-
return completeMark[type] ? completeMark[type](answer) : false;
|
|
600
|
-
}) : [];
|
|
601
|
-
};
|
|
602
|
-
|
|
510
|
+
const removeInvalidAnswers = answers => answers ? (answers || []).filter(({
|
|
511
|
+
type,
|
|
512
|
+
...answer
|
|
513
|
+
}) => completeMark[type] ? completeMark[type](answer) : false) : [];
|
|
603
514
|
exports.removeInvalidAnswers = removeInvalidAnswers;
|
|
604
515
|
//# sourceMappingURL=utils.js.map
|