@pie-element/graphing 8.0.1 → 8.2.0-mui-update.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.
- package/CHANGELOG.md +19 -0
- package/configure/CHANGELOG.md +19 -0
- package/configure/lib/configure.js +303 -403
- package/configure/lib/configure.js.map +1 -1
- package/configure/lib/correct-response.js +402 -513
- package/configure/lib/correct-response.js.map +1 -1
- package/configure/lib/defaults.js +4 -4
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/graphing-config.js +312 -359
- package/configure/lib/graphing-config.js.map +1 -1
- package/configure/lib/index.js +130 -189
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +43 -88
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +11 -8
- package/controller/CHANGELOG.md +19 -0
- package/controller/lib/defaults.js +5 -5
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +180 -267
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +301 -311
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +3 -3
- package/lib/index.js +48 -95
- package/lib/index.js.map +1 -1
- package/lib/main.js +145 -210
- package/lib/main.js.map +1 -1
- package/lib/utils.js +5 -19
- package/lib/utils.js.map +1 -1
- package/package.json +13 -27
- package/LICENSE.md +0 -5
- package/esm/configure.js +0 -10338
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -846
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -7623
- package/esm/element.js.map +0 -1
package/controller/lib/utils.js
CHANGED
|
@@ -1,256 +1,249 @@
|
|
|
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.sortedAnswers = exports.removeInvalidSegments = exports.removeDuplicateSegments = exports.equalVector = exports.equalSine = exports.equalSegment = exports.equalRay = exports.equalPolygon = exports.equalPoint = exports.equalParabola = exports.equalMarks = exports.equalLine = exports.equalExponential = exports.equalCircle = exports.equalAbsolute = exports.constructSegmentsFromPoints = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
8
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
13
|
-
|
|
14
9
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
15
|
-
|
|
16
10
|
var _uniqWith = _interopRequireDefault(require("lodash/uniqWith"));
|
|
17
|
-
|
|
18
11
|
var _differenceWith = _interopRequireDefault(require("lodash/differenceWith"));
|
|
19
|
-
|
|
20
12
|
var _graphingUtils = require("@pie-lib/graphing-utils");
|
|
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
|
-
var equalPoint = function equalPoint(A, B) {
|
|
13
|
+
const equalPoint = (A, B) => {
|
|
27
14
|
// x1 = x2 & y1 = y2
|
|
28
|
-
|
|
29
|
-
A =
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
let equalLabel = true;
|
|
16
|
+
A = {
|
|
17
|
+
...A
|
|
18
|
+
};
|
|
19
|
+
B = {
|
|
20
|
+
...B
|
|
21
|
+
};
|
|
32
22
|
if (A.label || B.label) {
|
|
33
|
-
equalLabel = (0, _isEqual
|
|
23
|
+
equalLabel = (0, _isEqual.default)(A.label, B.label);
|
|
34
24
|
}
|
|
35
|
-
|
|
36
|
-
return (0, _isEqual["default"])(A.x, B.x) && (0, _isEqual["default"])(A.y, B.y);
|
|
25
|
+
return (0, _isEqual.default)(A.x, B.x) && (0, _isEqual.default)(A.y, B.y);
|
|
37
26
|
};
|
|
38
|
-
|
|
39
27
|
exports.equalPoint = equalPoint;
|
|
40
|
-
|
|
41
|
-
var equalSegment = function equalSegment(segment1, segment2) {
|
|
28
|
+
const equalSegment = (segment1, segment2) => {
|
|
42
29
|
// A.from = B.from, A.to = B.to OR A.from = B.to, A.to = B.from
|
|
43
30
|
// x1 = x3 & y1 = y3 & x2 = x4 & y2 = y4
|
|
44
|
-
return (0, _isEqual
|
|
31
|
+
return (0, _isEqual.default)(segment1.from, segment2.from) && (0, _isEqual.default)(segment1.to, segment2.to) || (0, _isEqual.default)(segment1.to, segment2.from) && (0, _isEqual.default)(segment1.from, segment2.to);
|
|
45
32
|
};
|
|
46
|
-
|
|
47
33
|
exports.equalSegment = equalSegment;
|
|
48
|
-
|
|
49
|
-
var equalVector = function equalVector(vector1, vector2) {
|
|
34
|
+
const equalVector = (vector1, vector2) => {
|
|
50
35
|
// A.from = B.from, A.to = B.to;
|
|
51
36
|
// x1 = x3 & y1 = y3 & x2 = x4 & y2 = y4
|
|
52
|
-
return (0, _isEqual
|
|
53
|
-
}; // this function is implemented in configure as well
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
exports.equalVector = equalVector;
|
|
57
|
-
|
|
58
|
-
var sortedAnswers = function sortedAnswers(answers) {
|
|
59
|
-
return Object.keys(answers || {}).sort().reduce(function (result, key) {
|
|
60
|
-
if (key !== 'correctAnswer') {
|
|
61
|
-
result[key] = answers[key];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return result;
|
|
65
|
-
}, {});
|
|
37
|
+
return (0, _isEqual.default)(vector1.from, vector2.from) && (0, _isEqual.default)(vector1.to, vector2.to);
|
|
66
38
|
};
|
|
67
39
|
|
|
40
|
+
// this function is implemented in configure as well
|
|
41
|
+
exports.equalVector = equalVector;
|
|
42
|
+
const sortedAnswers = answers => Object.keys(answers || {}).sort().reduce((result, key) => {
|
|
43
|
+
if (key !== 'correctAnswer') {
|
|
44
|
+
result[key] = answers[key];
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}, {});
|
|
68
48
|
exports.sortedAnswers = sortedAnswers;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
to:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
49
|
+
const returnLineEquationCoefficients = line => {
|
|
50
|
+
line = {
|
|
51
|
+
...line,
|
|
52
|
+
to: {
|
|
53
|
+
...line.to
|
|
54
|
+
},
|
|
55
|
+
from: {
|
|
56
|
+
...line.from
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const xA = line.from.x;
|
|
60
|
+
const yA = line.from.y;
|
|
61
|
+
const xB = line.to.x;
|
|
62
|
+
const yB = line.to.y;
|
|
79
63
|
return {
|
|
80
64
|
a: yB - yA,
|
|
81
65
|
b: xA - xB,
|
|
82
66
|
c: xB * yA - xA * yB
|
|
83
67
|
};
|
|
84
68
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return Math.round(number * 10000) / 10000;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
var equalLine = function equalLine(line1, line2) {
|
|
69
|
+
const getSignificantDecimals = number => Math.round(number * 10000) / 10000;
|
|
70
|
+
const equalLine = (line1, line2) => {
|
|
91
71
|
// line equation: ax + by + c = 0
|
|
92
72
|
// 2 lines are equal if a1/a2 = b1/b2 = c1/c2, where a, b, c are the coefficients in line equation
|
|
73
|
+
|
|
93
74
|
// line equation knowing 2 points: (y - yA) / (yB - yA) = (x - xA) / (xB - xA)
|
|
94
75
|
// extending this equation, we get: x * (yB - yA) + y * (xA - xB) + (xB * yA - xA * yB) = 0
|
|
95
76
|
// where a = yB - yA; b = xA - xB; c = xB * yA - xA * yB
|
|
96
|
-
var _returnLineEquationCo = returnLineEquationCoefficients(line1),
|
|
97
|
-
a1 = _returnLineEquationCo.a,
|
|
98
|
-
b1 = _returnLineEquationCo.b,
|
|
99
|
-
c1 = _returnLineEquationCo.c;
|
|
100
|
-
|
|
101
|
-
var _returnLineEquationCo2 = returnLineEquationCoefficients(line2),
|
|
102
|
-
a2 = _returnLineEquationCo2.a,
|
|
103
|
-
b2 = _returnLineEquationCo2.b,
|
|
104
|
-
c2 = _returnLineEquationCo2.c;
|
|
105
|
-
|
|
106
|
-
var proportions = [];
|
|
107
77
|
|
|
78
|
+
const {
|
|
79
|
+
a: a1,
|
|
80
|
+
b: b1,
|
|
81
|
+
c: c1
|
|
82
|
+
} = returnLineEquationCoefficients(line1);
|
|
83
|
+
const {
|
|
84
|
+
a: a2,
|
|
85
|
+
b: b2,
|
|
86
|
+
c: c2
|
|
87
|
+
} = returnLineEquationCoefficients(line2);
|
|
88
|
+
const proportions = [];
|
|
108
89
|
if (a2 !== 0) {
|
|
109
90
|
proportions.push(getSignificantDecimals(a1 / a2));
|
|
110
91
|
} else if (a1 !== a2) {
|
|
111
92
|
return false;
|
|
112
93
|
}
|
|
113
|
-
|
|
114
94
|
if (b2 !== 0) {
|
|
115
95
|
proportions.push(getSignificantDecimals(b1 / b2));
|
|
116
96
|
} else if (b1 !== b2) {
|
|
117
97
|
return false;
|
|
118
98
|
}
|
|
119
|
-
|
|
120
99
|
if (c2 !== 0) {
|
|
121
100
|
proportions.push(getSignificantDecimals(c1 / c2));
|
|
122
101
|
} else if (c1 !== c2) {
|
|
123
102
|
return false;
|
|
124
103
|
}
|
|
104
|
+
return _lodash.default.uniq(proportions).length === 1;
|
|
125
105
|
|
|
126
|
-
|
|
106
|
+
// (y2 - y1)/(x2 - x1) = (y4 - y3)/(x4 - x3);
|
|
127
107
|
// return ((Math.abs((line1.to.y - line1.from.y) / (line1.to.x - line1.from.x))) === (Math.abs((line2.to.y - line2.from.y) / (line2.to.x - line2.from.x))));
|
|
128
108
|
};
|
|
129
|
-
|
|
130
109
|
exports.equalLine = equalLine;
|
|
110
|
+
const equalRay = (ray1, ray2) => {
|
|
111
|
+
ray1 = {
|
|
112
|
+
...ray1,
|
|
113
|
+
to: {
|
|
114
|
+
...ray1.to
|
|
115
|
+
},
|
|
116
|
+
from: {
|
|
117
|
+
...ray1.from
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
ray2 = {
|
|
121
|
+
...ray2,
|
|
122
|
+
to: {
|
|
123
|
+
...ray2.to
|
|
124
|
+
},
|
|
125
|
+
from: {
|
|
126
|
+
...ray2.from
|
|
127
|
+
}
|
|
128
|
+
};
|
|
131
129
|
|
|
132
|
-
|
|
133
|
-
ray1 = _objectSpread(_objectSpread({}, ray1), {}, {
|
|
134
|
-
to: _objectSpread({}, ray1.to),
|
|
135
|
-
from: _objectSpread({}, ray1.from)
|
|
136
|
-
});
|
|
137
|
-
ray2 = _objectSpread(_objectSpread({}, ray2), {}, {
|
|
138
|
-
to: _objectSpread({}, ray2.to),
|
|
139
|
-
from: _objectSpread({}, ray2.from)
|
|
140
|
-
}); // slope: m = (y2-y1)/(x2-x1)
|
|
130
|
+
// slope: m = (y2-y1)/(x2-x1)
|
|
141
131
|
// slope & x1 = x3 & y1 = y3 & angle between (x1, y1) (x2, y2) is same as angle between (x3, y3) (x4, y4)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var angleRay2 = Math.atan2(ray2.to.y - ray2.from.y, ray2.to.x - ray2.from.x) * 180 / Math.PI;
|
|
132
|
+
const mRay1 = (ray1.to.y - ray1.from.y) / (ray1.to.x - ray1.from.x);
|
|
133
|
+
const mRay2 = (ray2.to.y - ray2.from.y) / (ray2.to.x - ray2.from.x);
|
|
134
|
+
const angleRay1 = Math.atan2(ray1.to.y - ray1.from.y, ray1.to.x - ray1.from.x) * 180 / Math.PI;
|
|
135
|
+
const angleRay2 = Math.atan2(ray2.to.y - ray2.from.y, ray2.to.x - ray2.from.x) * 180 / Math.PI;
|
|
147
136
|
return mRay1 === mRay2 && ray1.from.x === ray2.from.x && ray1.from.y === ray2.from.y && angleRay1 === angleRay2;
|
|
148
137
|
};
|
|
149
|
-
|
|
150
138
|
exports.equalRay = equalRay;
|
|
151
|
-
|
|
152
|
-
var constructSegmentsFromPoints = function constructSegmentsFromPoints(points) {
|
|
139
|
+
const constructSegmentsFromPoints = points => {
|
|
153
140
|
// takes the list of points that represent a polygon and transforms it into a list of segments; eg.:
|
|
154
141
|
// points: A, B, C, D => segments: AB, BC, CD, DA
|
|
155
|
-
return (points || []).map(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
160
|
-
});
|
|
142
|
+
return (points || []).map((point, index) => ({
|
|
143
|
+
from: point,
|
|
144
|
+
to: points[(index + 1) % points.length]
|
|
145
|
+
}));
|
|
161
146
|
};
|
|
162
|
-
|
|
163
147
|
exports.constructSegmentsFromPoints = constructSegmentsFromPoints;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
148
|
+
const removeDuplicateSegments = segments => {
|
|
149
|
+
segments = segments || [];
|
|
150
|
+
// removes segments that are duplicates; eg. These segments are the same, so one will be removed:
|
|
167
151
|
// segment1: from: { x: 1, y: 1 }, to: { x: 2, y: 1 }
|
|
168
152
|
// segment2: from: { x: 2, y: 1 }, to: { x: 1, y: 1 }
|
|
169
|
-
|
|
170
|
-
return (0, _uniqWith["default"])(segments, function (s1, s2) {
|
|
171
|
-
return equalSegment(s1, s2);
|
|
172
|
-
});
|
|
153
|
+
return (0, _uniqWith.default)(segments, (s1, s2) => equalSegment(s1, s2));
|
|
173
154
|
};
|
|
174
|
-
|
|
175
155
|
exports.removeDuplicateSegments = removeDuplicateSegments;
|
|
156
|
+
const removeInvalidSegments = segments => {
|
|
157
|
+
segments = segments || [];
|
|
158
|
+
// removes segments that start in a point and end in the same point (eg.: from: { x: 1, y: 1 }, to: { x: 1, y: 1 })
|
|
176
159
|
|
|
177
|
-
|
|
178
|
-
segments = segments || []; // removes segments that start in a point and end in the same point (eg.: from: { x: 1, y: 1 }, to: { x: 1, y: 1 })
|
|
179
|
-
|
|
180
|
-
return segments.filter(function (segment) {
|
|
181
|
-
return !(0, _isEqual["default"])(segment.from, segment.to);
|
|
182
|
-
});
|
|
160
|
+
return segments.filter(segment => !(0, _isEqual.default)(segment.from, segment.to));
|
|
183
161
|
};
|
|
184
|
-
|
|
185
162
|
exports.removeInvalidSegments = removeInvalidSegments;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
163
|
+
const equalPolygon = (poly1, poly2) => {
|
|
164
|
+
const {
|
|
165
|
+
points: points1
|
|
166
|
+
} = poly1;
|
|
167
|
+
const {
|
|
168
|
+
points: points2
|
|
169
|
+
} = poly2;
|
|
170
|
+
|
|
171
|
+
// generate segments
|
|
172
|
+
const segments1 = constructSegmentsFromPoints(points1);
|
|
173
|
+
const segments2 = constructSegmentsFromPoints(points2);
|
|
174
|
+
const segments1NoDuplicates = removeDuplicateSegments(removeInvalidSegments(segments1));
|
|
175
|
+
const segments2NoDuplicates = removeDuplicateSegments(removeInvalidSegments(segments2));
|
|
176
|
+
const differentSegments1 = (0, _differenceWith.default)(segments1NoDuplicates, segments2NoDuplicates, equalSegment);
|
|
177
|
+
const differentSegments2 = (0, _differenceWith.default)(segments2NoDuplicates, segments1NoDuplicates, equalSegment);
|
|
197
178
|
return (!differentSegments1 || !differentSegments1.length) && (!differentSegments2 || !differentSegments2.length);
|
|
198
179
|
};
|
|
199
|
-
|
|
200
180
|
exports.equalPolygon = equalPolygon;
|
|
181
|
+
const equalCircle = (c1, c2) => {
|
|
182
|
+
c1 = {
|
|
183
|
+
...c1,
|
|
184
|
+
root: {
|
|
185
|
+
...c1.root
|
|
186
|
+
},
|
|
187
|
+
edge: {
|
|
188
|
+
...c1.edge
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
c2 = {
|
|
192
|
+
...c2,
|
|
193
|
+
root: {
|
|
194
|
+
...c2.root
|
|
195
|
+
},
|
|
196
|
+
edge: {
|
|
197
|
+
...c2.edge
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
const equalRootAndEdge = (0, _isEqual.default)(c2.edge, c1.edge) && (0, _isEqual.default)(c2.root, c1.root);
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
c1 = _objectSpread(_objectSpread({}, c1), {}, {
|
|
204
|
-
root: _objectSpread({}, c1.root),
|
|
205
|
-
edge: _objectSpread({}, c1.edge)
|
|
206
|
-
});
|
|
207
|
-
c2 = _objectSpread(_objectSpread({}, c2), {}, {
|
|
208
|
-
root: _objectSpread({}, c2.root),
|
|
209
|
-
edge: _objectSpread({}, c2.edge)
|
|
210
|
-
});
|
|
211
|
-
var equalRootAndEdge = (0, _isEqual["default"])(c2.edge, c1.edge) && (0, _isEqual["default"])(c2.root, c1.root); // if both edge and root are the same, it means the shapes are exactly the same
|
|
212
|
-
|
|
202
|
+
// if both edge and root are the same, it means the shapes are exactly the same
|
|
213
203
|
if (equalRootAndEdge) return true;
|
|
214
|
-
|
|
215
|
-
|
|
204
|
+
const rC1 = Math.sqrt((c1.edge.x - c1.root.x) ** 2 + (c1.edge.y - c1.root.y) ** 2);
|
|
205
|
+
const rC2 = Math.sqrt((c2.edge.x - c2.root.x) ** 2 + (c2.edge.y - c2.root.y) ** 2);
|
|
216
206
|
|
|
217
|
-
|
|
207
|
+
// if both root and radius are the same, it means the shapes are equal
|
|
208
|
+
return (0, _isEqual.default)(c2.root, c1.root) && (0, _isEqual.default)(rC1, rC2);
|
|
218
209
|
};
|
|
219
|
-
|
|
220
210
|
exports.equalCircle = equalCircle;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
root =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
211
|
+
const equalSine = (sine1, sine2) => {
|
|
212
|
+
const getPoints = ({
|
|
213
|
+
root,
|
|
214
|
+
edge
|
|
215
|
+
}) => {
|
|
216
|
+
root = {
|
|
217
|
+
...root
|
|
218
|
+
};
|
|
219
|
+
edge = {
|
|
220
|
+
...edge
|
|
221
|
+
};
|
|
222
|
+
const {
|
|
223
|
+
amplitude,
|
|
224
|
+
freq
|
|
225
|
+
} = (0, _graphingUtils.getAmplitudeAndFreq)(root, edge);
|
|
226
|
+
// the height of the sine wave
|
|
227
|
+
const tY = Math.abs(root.y - edge.y) * 2;
|
|
228
|
+
// the distance on x axis between edge and root
|
|
229
|
+
const tXRoot = Math.abs(root.x - edge.x);
|
|
230
|
+
// the distance on x axis between 2 edges for sine wave (min & max)
|
|
231
|
+
const tX = tXRoot * 2;
|
|
232
|
+
// the first edge placed east side of root
|
|
233
|
+
let edgeAboveZeroX = edge.x;
|
|
234
|
+
let edgeAboveZeroY = edge.y;
|
|
235
|
+
|
|
236
|
+
// if edge less then 0, find out the appropriate edge placed east side of zero (0)
|
|
243
237
|
while (edgeAboveZeroX < 0 && tX !== 0) {
|
|
244
238
|
edgeAboveZeroX = edgeAboveZeroX + tX;
|
|
245
239
|
edgeAboveZeroY = edgeAboveZeroY < root.y ? edgeAboveZeroY + tY : edgeAboveZeroY - tY;
|
|
246
|
-
}
|
|
247
|
-
|
|
240
|
+
}
|
|
248
241
|
|
|
242
|
+
// if edge more then 0, find out the appropriate edge placed east side of zero (0)
|
|
249
243
|
while (edgeAboveZeroX - tX > 0 && tX !== 0) {
|
|
250
244
|
edgeAboveZeroX = edgeAboveZeroX - tX;
|
|
251
245
|
edgeAboveZeroY = edgeAboveZeroY < root.y ? edgeAboveZeroY + tY : edgeAboveZeroY - tY;
|
|
252
246
|
}
|
|
253
|
-
|
|
254
247
|
return {
|
|
255
248
|
amplitude: getSignificantDecimals(amplitude),
|
|
256
249
|
freq: getSignificantDecimals(freq),
|
|
@@ -260,183 +253,180 @@ var equalSine = function equalSine(sine1, sine2) {
|
|
|
260
253
|
edgeAboveZeroY: getSignificantDecimals(edgeAboveZeroY)
|
|
261
254
|
};
|
|
262
255
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
256
|
+
const studentAnswerBpY = getPoints(sine1);
|
|
257
|
+
const correctAnswerBpY = getPoints(sine2);
|
|
258
|
+
const {
|
|
259
|
+
amplitude: amplitude1,
|
|
260
|
+
freq: freq1,
|
|
261
|
+
min: min1,
|
|
262
|
+
max: max1,
|
|
263
|
+
edgeAboveZeroX: edgeAboveZeroX1,
|
|
264
|
+
edgeAboveZeroY: edgeAboveZeroY1
|
|
265
|
+
} = studentAnswerBpY;
|
|
266
|
+
const {
|
|
267
|
+
amplitude: amplitude2,
|
|
268
|
+
freq: freq2,
|
|
269
|
+
min: min2,
|
|
270
|
+
max: max2,
|
|
271
|
+
edgeAboveZeroX: edgeAboveZeroX2,
|
|
272
|
+
edgeAboveZeroY: edgeAboveZeroY2
|
|
273
|
+
} = correctAnswerBpY;
|
|
274
|
+
return Math.abs(amplitude1) === Math.abs(amplitude2) && Math.abs(freq1) === Math.abs(freq2) && min1 === min2 && max1 === max2 && edgeAboveZeroX1 === edgeAboveZeroX2 && edgeAboveZeroY1 === edgeAboveZeroY2;
|
|
275
|
+
// rootDiff1 === rootDiff2);
|
|
279
276
|
};
|
|
280
|
-
|
|
281
277
|
exports.equalSine = equalSine;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
278
|
+
const equalParabola = (p1, p2) => {
|
|
279
|
+
const {
|
|
280
|
+
edge: edgeP1
|
|
281
|
+
} = p1;
|
|
282
|
+
const {
|
|
283
|
+
edge: edgeP2
|
|
284
|
+
} = p2;
|
|
285
|
+
let {
|
|
286
|
+
root: rootP1
|
|
287
|
+
} = p1;
|
|
288
|
+
let {
|
|
289
|
+
root: rootP2
|
|
290
|
+
} = p2;
|
|
291
|
+
rootP1 = {
|
|
292
|
+
...rootP1
|
|
293
|
+
};
|
|
294
|
+
rootP2 = {
|
|
295
|
+
...rootP2
|
|
296
|
+
};
|
|
297
|
+
const p1edge = edgeP1 || {
|
|
298
|
+
...rootP1
|
|
299
|
+
};
|
|
300
|
+
const p2edge = edgeP2 || {
|
|
301
|
+
...rootP2
|
|
302
|
+
};
|
|
303
|
+
const p1mirrorEdge = {
|
|
296
304
|
x: rootP1.x - (p1edge.x - rootP1.x),
|
|
297
305
|
y: p1edge.y
|
|
298
306
|
};
|
|
299
|
-
|
|
307
|
+
const p2mirrorEdge = {
|
|
300
308
|
x: rootP2.x - (p2edge.x - rootP2.x),
|
|
301
309
|
y: p2edge.y
|
|
302
310
|
};
|
|
303
311
|
if (!edgeP1 || !edgeP2) return false;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return Math.round(number * 10000) / 10000;
|
|
318
|
-
};
|
|
319
|
-
|
|
312
|
+
const {
|
|
313
|
+
a: a1,
|
|
314
|
+
b: b1,
|
|
315
|
+
c: c1
|
|
316
|
+
} = (0, _graphingUtils.pointsToABC)(rootP1, edgeP1, p1mirrorEdge);
|
|
317
|
+
const {
|
|
318
|
+
a: a2,
|
|
319
|
+
b: b2,
|
|
320
|
+
c: c2
|
|
321
|
+
} = (0, _graphingUtils.pointsToABC)(rootP2, edgeP2, p2mirrorEdge);
|
|
322
|
+
|
|
323
|
+
// sometimes numbers have this form: 1.00000000002 because of calculations, we have to round them
|
|
324
|
+
const round = number => Math.round(number * 10000) / 10000;
|
|
320
325
|
return round(a1) === round(a2) && round(b1) === round(b2) && round(c1) === round(c2);
|
|
321
326
|
};
|
|
327
|
+
|
|
322
328
|
/*
|
|
323
329
|
* Function to check if given two points for absolute function
|
|
324
330
|
* for correct answer and student answer are equal or not.
|
|
325
331
|
* @param p1 - student answer
|
|
326
332
|
* @param p2 - correct answer
|
|
327
333
|
* */
|
|
328
|
-
|
|
329
|
-
|
|
330
334
|
exports.equalParabola = equalParabola;
|
|
335
|
+
const equalAbsolute = (p1, p2) => {
|
|
336
|
+
const {
|
|
337
|
+
edge: edgeP1
|
|
338
|
+
} = p1;
|
|
339
|
+
const {
|
|
340
|
+
edge: edgeP2
|
|
341
|
+
} = p2;
|
|
342
|
+
let {
|
|
343
|
+
root: rootP1
|
|
344
|
+
} = p1;
|
|
345
|
+
let {
|
|
346
|
+
root: rootP2
|
|
347
|
+
} = p2;
|
|
348
|
+
rootP1 = {
|
|
349
|
+
...rootP1
|
|
350
|
+
};
|
|
351
|
+
rootP2 = {
|
|
352
|
+
...rootP2
|
|
353
|
+
};
|
|
354
|
+
const p1edge = edgeP1 || {
|
|
355
|
+
...rootP1
|
|
356
|
+
};
|
|
357
|
+
const p2edge = edgeP2 || {
|
|
358
|
+
...rootP2
|
|
359
|
+
};
|
|
360
|
+
const p1a1 = (0, _graphingUtils.pointsToAForAbsolute)(rootP1, p1edge);
|
|
361
|
+
const p2a2 = (0, _graphingUtils.pointsToAForAbsolute)(rootP2, p2edge);
|
|
331
362
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
var edgeP2 = p2.edge;
|
|
335
|
-
var rootP1 = p1.root;
|
|
336
|
-
var rootP2 = p2.root;
|
|
337
|
-
rootP1 = _objectSpread({}, rootP1);
|
|
338
|
-
rootP2 = _objectSpread({}, rootP2);
|
|
339
|
-
|
|
340
|
-
var p1edge = edgeP1 || _objectSpread({}, rootP1);
|
|
341
|
-
|
|
342
|
-
var p2edge = edgeP2 || _objectSpread({}, rootP2);
|
|
343
|
-
|
|
344
|
-
var p1a1 = (0, _graphingUtils.pointsToAForAbsolute)(rootP1, p1edge);
|
|
345
|
-
var p2a2 = (0, _graphingUtils.pointsToAForAbsolute)(rootP2, p2edge); // if both root and a value are equal
|
|
346
|
-
|
|
347
|
-
return (0, _isEqual["default"])(rootP2, rootP1) && (0, _isEqual["default"])(p2a2, p1a1);
|
|
363
|
+
// if both root and a value are equal
|
|
364
|
+
return (0, _isEqual.default)(rootP2, rootP1) && (0, _isEqual.default)(p2a2, p1a1);
|
|
348
365
|
};
|
|
366
|
+
|
|
349
367
|
/*
|
|
350
368
|
* Function to check if given two points for exponential function
|
|
351
369
|
* for correct answer and student answer are equal or not.
|
|
352
370
|
* @param p1 - student answer
|
|
353
371
|
* @param p2 - correct answer
|
|
354
372
|
* */
|
|
355
|
-
|
|
356
|
-
|
|
357
373
|
exports.equalAbsolute = equalAbsolute;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
374
|
+
const equalExponential = (p1, p2) => {
|
|
375
|
+
const {
|
|
376
|
+
edge: edgeP1
|
|
377
|
+
} = p1;
|
|
378
|
+
const {
|
|
379
|
+
edge: edgeP2
|
|
380
|
+
} = p2;
|
|
381
|
+
let {
|
|
382
|
+
root: rootP1
|
|
383
|
+
} = p1;
|
|
384
|
+
let {
|
|
385
|
+
root: rootP2
|
|
386
|
+
} = p2;
|
|
387
|
+
rootP1 = {
|
|
388
|
+
...rootP1
|
|
389
|
+
};
|
|
390
|
+
rootP2 = {
|
|
391
|
+
...rootP2
|
|
392
|
+
};
|
|
393
|
+
const p1edge = edgeP1 || {
|
|
394
|
+
...rootP1
|
|
395
|
+
};
|
|
396
|
+
const p2edge = edgeP2 || {
|
|
397
|
+
...rootP2
|
|
398
|
+
};
|
|
399
|
+
const {
|
|
400
|
+
a1,
|
|
401
|
+
b1
|
|
402
|
+
} = (0, _graphingUtils.pointsToABForExponential)(rootP1, p1edge);
|
|
403
|
+
const {
|
|
404
|
+
a2,
|
|
405
|
+
b2
|
|
406
|
+
} = (0, _graphingUtils.pointsToABForExponential)(rootP2, p2edge);
|
|
407
|
+
|
|
408
|
+
// if both a and b value are equal
|
|
409
|
+
return (0, _isEqual.default)(a2, a1) && (0, _isEqual.default)(b2, b1);
|
|
381
410
|
};
|
|
382
|
-
|
|
383
411
|
exports.equalExponential = equalExponential;
|
|
384
|
-
|
|
385
|
-
circle:
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
},
|
|
397
|
-
exponential: function exponential(sessAnswer, mark) {
|
|
398
|
-
return equalExponential(sessAnswer, mark);
|
|
399
|
-
},
|
|
400
|
-
point: function point(sessAnswer, mark) {
|
|
401
|
-
return equalPoint(sessAnswer, mark);
|
|
402
|
-
},
|
|
403
|
-
polygon: function polygon(sessAnswer, poly) {
|
|
404
|
-
return equalPolygon(sessAnswer, poly);
|
|
405
|
-
},
|
|
406
|
-
ray: function ray(sessAnswer, mark) {
|
|
407
|
-
return equalRay(sessAnswer, mark);
|
|
408
|
-
},
|
|
409
|
-
segment: function segment(sessAnswer, mark) {
|
|
410
|
-
return equalSegment(sessAnswer, mark);
|
|
411
|
-
},
|
|
412
|
-
sine: function sine(sessAnswer, mark) {
|
|
413
|
-
return equalSine(sessAnswer, mark);
|
|
414
|
-
},
|
|
415
|
-
vector: function vector(sessAnswer, mark) {
|
|
416
|
-
return equalVector(sessAnswer, mark);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
exports.equalMarks = equalMarks;
|
|
420
|
-
|
|
421
|
-
var completePoint = function completePoint(point) {
|
|
422
|
-
return point && Number.isFinite(point.x) && Number.isFinite(point.y);
|
|
412
|
+
const equalMarks = exports.equalMarks = {
|
|
413
|
+
circle: (sessAnswer, mark) => equalCircle(sessAnswer, mark),
|
|
414
|
+
line: (sessAnswer, mark) => equalLine(sessAnswer, mark),
|
|
415
|
+
parabola: (sessAnswer, mark) => equalParabola(sessAnswer, mark),
|
|
416
|
+
absolute: (sessAnswer, mark) => equalAbsolute(sessAnswer, mark),
|
|
417
|
+
exponential: (sessAnswer, mark) => equalExponential(sessAnswer, mark),
|
|
418
|
+
point: (sessAnswer, mark) => equalPoint(sessAnswer, mark),
|
|
419
|
+
polygon: (sessAnswer, poly) => equalPolygon(sessAnswer, poly),
|
|
420
|
+
ray: (sessAnswer, mark) => equalRay(sessAnswer, mark),
|
|
421
|
+
segment: (sessAnswer, mark) => equalSegment(sessAnswer, mark),
|
|
422
|
+
sine: (sessAnswer, mark) => equalSine(sessAnswer, mark),
|
|
423
|
+
vector: (sessAnswer, mark) => equalVector(sessAnswer, mark)
|
|
423
424
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
var completeRootEdge = function completeRootEdge(item) {
|
|
430
|
-
return item && completeMark.point(item.edge) && completeMark.point(item.root);
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
var completePoints = function completePoints(item) {
|
|
434
|
-
return item && item.points && item.points.length && (item.points.filter(function (point) {
|
|
435
|
-
return completePoint(point);
|
|
436
|
-
}) || []).length === item.points.length;
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
var completeMark = {
|
|
425
|
+
const completePoint = point => point && Number.isFinite(point.x) && Number.isFinite(point.y);
|
|
426
|
+
const completeFromTo = item => item && completeMark.point(item.from) && completeMark.point(item.to);
|
|
427
|
+
const completeRootEdge = item => item && completeMark.point(item.edge) && completeMark.point(item.root);
|
|
428
|
+
const completePoints = item => item && item.points && item.points.length && (item.points.filter(point => completePoint(point)) || []).length === item.points.length;
|
|
429
|
+
const completeMark = {
|
|
440
430
|
point: completePoint,
|
|
441
431
|
line: completeFromTo,
|
|
442
432
|
ray: completeFromTo,
|