@khanacademy/perseus-score 2.1.0 → 2.2.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/dist/index.js CHANGED
@@ -12872,7 +12872,8 @@ function scoreIframe(userInput) {
12872
12872
  const {
12873
12873
  collinear,
12874
12874
  canonicalSineCoefficients,
12875
- similar
12875
+ similar,
12876
+ clockwise
12876
12877
  } = kmath.geometry;
12877
12878
  const {
12878
12879
  getClockwiseAngle
@@ -13032,9 +13033,27 @@ function scoreInteractiveGraph(userInput, rubric) {
13032
13033
  };
13033
13034
  }
13034
13035
  } else if (userInput.type === "angle" && rubric.correct.type === "angle") {
13035
- const guess = userInput.coords;
13036
+ const coords = userInput.coords;
13036
13037
  const correct = rubric.correct.coords;
13037
13038
  const allowReflexAngles = rubric.correct.allowReflexAngles;
13039
+
13040
+ // While the angle graph should always have 3 points, our types
13041
+ // technically allow for null values. We'll check for that here.
13042
+ // TODO: (LEMS-2857) We would like to update the type of coords
13043
+ // to be non-nullable, as the graph should always have 3 points.
13044
+ if (!coords) {
13045
+ return {
13046
+ type: "invalid",
13047
+ message: null
13048
+ };
13049
+ }
13050
+
13051
+ // We need to check both the direction of the angle and the
13052
+ // whether the graph allows for reflexive angles in order to
13053
+ // to determine if we need to reverse the coords for scoring.
13054
+ const areClockwise = clockwise([coords[0], coords[2], coords[1]]);
13055
+ const shouldReverseCoords = areClockwise && !allowReflexAngles;
13056
+ const guess = shouldReverseCoords ? coords.slice().reverse() : coords;
13038
13057
  let match;
13039
13058
  if (rubric.correct.match === "congruent") {
13040
13059
  const angles = _.map([guess, correct], function (coords) {
@@ -13048,13 +13067,7 @@ function scoreInteractiveGraph(userInput, rubric) {
13048
13067
  match = perseusCore.approximateEqual(...angles);
13049
13068
  } else {
13050
13069
  /* exact */
13051
- match =
13052
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
13053
- perseusCore.approximateDeepEqual(guess[1], correct[1]) &&
13054
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
13055
- collinear(correct[1], correct[0], guess[0]) &&
13056
- // @ts-expect-error - TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'. | TS2532 - Object is possibly 'undefined'.
13057
- collinear(correct[1], correct[2], guess[2]);
13070
+ match = perseusCore.approximateDeepEqual(guess[1], correct[1]) && collinear(correct[1], correct[0], guess[0]) && collinear(correct[1], correct[2], guess[2]);
13058
13071
  }
13059
13072
  if (match) {
13060
13073
  return {