@pie-element/graphing 8.3.4-next.3 → 9.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,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
- var equalLabel = true;
29
- A = _objectSpread({}, A);
30
- B = _objectSpread({}, B);
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["default"])(A.label, B.label);
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["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);
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["default"])(vector1.from, vector2.from) && (0, _isEqual["default"])(vector1.to, vector2.to);
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
- var returnLineEquationCoefficients = function returnLineEquationCoefficients(line) {
71
- line = _objectSpread(_objectSpread({}, line), {}, {
72
- to: _objectSpread({}, line.to),
73
- from: _objectSpread({}, line.from)
74
- });
75
- var xA = line.from.x;
76
- var yA = line.from.y;
77
- var xB = line.to.x;
78
- var yB = line.to.y;
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
- var getSignificantDecimals = function getSignificantDecimals(number) {
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
- return _lodash["default"].uniq(proportions).length === 1; // (y2 - y1)/(x2 - x1) = (y4 - y3)/(x4 - x3);
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
- var equalRay = function equalRay(ray1, ray2) {
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
- var mRay1 = (ray1.to.y - ray1.from.y) / (ray1.to.x - ray1.from.x);
144
- var mRay2 = (ray2.to.y - ray2.from.y) / (ray2.to.x - ray2.from.x);
145
- var angleRay1 = Math.atan2(ray1.to.y - ray1.from.y, ray1.to.x - ray1.from.x) * 180 / Math.PI;
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(function (point, index) {
156
- return {
157
- from: point,
158
- to: points[(index + 1) % points.length]
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
- var removeDuplicateSegments = function removeDuplicateSegments(segments) {
166
- segments = segments || []; // removes segments that are duplicates; eg. These segments are the same, so one will be removed:
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
- var removeInvalidSegments = function removeInvalidSegments(segments) {
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
- var equalPolygon = function equalPolygon(poly1, poly2) {
188
- var points1 = poly1.points;
189
- var points2 = poly2.points; // generate segments
190
-
191
- var segments1 = constructSegmentsFromPoints(points1);
192
- var segments2 = constructSegmentsFromPoints(points2);
193
- var segments1NoDuplicates = removeDuplicateSegments(removeInvalidSegments(segments1));
194
- var segments2NoDuplicates = removeDuplicateSegments(removeInvalidSegments(segments2));
195
- var differentSegments1 = (0, _differenceWith["default"])(segments1NoDuplicates, segments2NoDuplicates, equalSegment);
196
- var differentSegments2 = (0, _differenceWith["default"])(segments2NoDuplicates, segments1NoDuplicates, equalSegment);
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
- var equalCircle = function equalCircle(c1, c2) {
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
- var rC1 = Math.sqrt(Math.pow(c1.edge.x - c1.root.x, 2) + Math.pow(c1.edge.y - c1.root.y, 2));
215
- var rC2 = Math.sqrt(Math.pow(c2.edge.x - c2.root.x, 2) + Math.pow(c2.edge.y - c2.root.y, 2)); // if both root and radius are the same, it means the shapes are equal
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
- return (0, _isEqual["default"])(c2.root, c1.root) && (0, _isEqual["default"])(rC1, rC2);
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
- var equalSine = function equalSine(sine1, sine2) {
223
- var getPoints = function getPoints(_ref) {
224
- var root = _ref.root,
225
- edge = _ref.edge;
226
- root = _objectSpread({}, root);
227
- edge = _objectSpread({}, edge);
228
-
229
- var _getAmplitudeAndFreq = (0, _graphingUtils.getAmplitudeAndFreq)(root, edge),
230
- amplitude = _getAmplitudeAndFreq.amplitude,
231
- freq = _getAmplitudeAndFreq.freq; // the height of the sine wave
232
-
233
-
234
- var tY = Math.abs(root.y - edge.y) * 2; // the distance on x axis between edge and root
235
-
236
- var tXRoot = Math.abs(root.x - edge.x); // the distance on x axis between 2 edges for sine wave (min & max)
237
-
238
- var tX = tXRoot * 2; // the first edge placed east side of root
239
-
240
- var edgeAboveZeroX = edge.x;
241
- var edgeAboveZeroY = edge.y; // if edge less then 0, find out the appropriate edge placed east side of zero (0)
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
- } // if edge more then 0, find out the appropriate edge placed east side of zero (0)
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
- var studentAnswerBpY = getPoints(sine1);
265
- var correctAnswerBpY = getPoints(sine2);
266
- var amplitude1 = studentAnswerBpY.amplitude,
267
- freq1 = studentAnswerBpY.freq,
268
- min1 = studentAnswerBpY.min,
269
- max1 = studentAnswerBpY.max,
270
- edgeAboveZeroX1 = studentAnswerBpY.edgeAboveZeroX,
271
- edgeAboveZeroY1 = studentAnswerBpY.edgeAboveZeroY;
272
- var amplitude2 = correctAnswerBpY.amplitude,
273
- freq2 = correctAnswerBpY.freq,
274
- min2 = correctAnswerBpY.min,
275
- max2 = correctAnswerBpY.max,
276
- edgeAboveZeroX2 = correctAnswerBpY.edgeAboveZeroX,
277
- edgeAboveZeroY2 = correctAnswerBpY.edgeAboveZeroY;
278
- return Math.abs(amplitude1) === Math.abs(amplitude2) && Math.abs(freq1) === Math.abs(freq2) && min1 === min2 && max1 === max2 && edgeAboveZeroX1 === edgeAboveZeroX2 && edgeAboveZeroY1 === edgeAboveZeroY2; // rootDiff1 === rootDiff2);
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
- var equalParabola = function equalParabola(p1, p2) {
284
- var edgeP1 = p1.edge;
285
- var edgeP2 = p2.edge;
286
- var rootP1 = p1.root;
287
- var rootP2 = p2.root;
288
- rootP1 = _objectSpread({}, rootP1);
289
- rootP2 = _objectSpread({}, rootP2);
290
-
291
- var p1edge = edgeP1 || _objectSpread({}, rootP1);
292
-
293
- var p2edge = edgeP2 || _objectSpread({}, rootP2);
294
-
295
- var p1mirrorEdge = {
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
- var p2mirrorEdge = {
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
- var _pointsToABC = (0, _graphingUtils.pointsToABC)(rootP1, edgeP1, p1mirrorEdge),
306
- a1 = _pointsToABC.a,
307
- b1 = _pointsToABC.b,
308
- c1 = _pointsToABC.c;
309
-
310
- var _pointsToABC2 = (0, _graphingUtils.pointsToABC)(rootP2, edgeP2, p2mirrorEdge),
311
- a2 = _pointsToABC2.a,
312
- b2 = _pointsToABC2.b,
313
- c2 = _pointsToABC2.c; // sometimes numbers have this form: 1.00000000002 because of calculations, we have to round them
314
-
315
-
316
- var round = function round(number) {
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
- var equalAbsolute = function equalAbsolute(p1, p2) {
333
- var edgeP1 = p1.edge;
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
- var equalExponential = function equalExponential(p1, p2) {
360
- var edgeP1 = p1.edge;
361
- var edgeP2 = p2.edge;
362
- var rootP1 = p1.root;
363
- var rootP2 = p2.root;
364
- rootP1 = _objectSpread({}, rootP1);
365
- rootP2 = _objectSpread({}, rootP2);
366
-
367
- var p1edge = edgeP1 || _objectSpread({}, rootP1);
368
-
369
- var p2edge = edgeP2 || _objectSpread({}, rootP2);
370
-
371
- var _pointsToABForExponen = (0, _graphingUtils.pointsToABForExponential)(rootP1, p1edge),
372
- a1 = _pointsToABForExponen.a1,
373
- b1 = _pointsToABForExponen.b1;
374
-
375
- var _pointsToABForExponen2 = (0, _graphingUtils.pointsToABForExponential)(rootP2, p2edge),
376
- a2 = _pointsToABForExponen2.a2,
377
- b2 = _pointsToABForExponen2.b2; // if both a and b value are equal
378
-
379
-
380
- return (0, _isEqual["default"])(a2, a1) && (0, _isEqual["default"])(b2, b1);
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
- var equalMarks = {
385
- circle: function circle(sessAnswer, mark) {
386
- return equalCircle(sessAnswer, mark);
387
- },
388
- line: function line(sessAnswer, mark) {
389
- return equalLine(sessAnswer, mark);
390
- },
391
- parabola: function parabola(sessAnswer, mark) {
392
- return equalParabola(sessAnswer, mark);
393
- },
394
- absolute: function absolute(sessAnswer, mark) {
395
- return equalAbsolute(sessAnswer, mark);
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
- var completeFromTo = function completeFromTo(item) {
426
- return item && completeMark.point(item.from) && completeMark.point(item.to);
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,