Skip to content

Commit

Permalink
Refining scoring behavior for unlimited point.
Browse files Browse the repository at this point in the history
  • Loading branch information
catandthemachines committed Dec 16, 2024
1 parent 1fe4370 commit 6dcb14d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const enableMafs: APIOptions = {
segment: true,
polygon: true,
"unlimited-polygon": true,
"unlimited-point": true,
angle: true,
"interactive-graph-locked-features-labels": true,
},
Expand Down Expand Up @@ -71,6 +72,13 @@ export const Point = (args: StoryArgs): React.ReactElement => (
<RendererWithDebugUI question={pointQuestion} />
);

export const PointWithMafs = (args: StoryArgs): React.ReactElement => (
<RendererWithDebugUI
apiOptions={{...enableMafs}}
question={pointQuestion}
/>
);

export const Polygon = (args: StoryArgs): React.ReactElement => (
<RendererWithDebugUI question={polygonQuestion} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ const defaultAngleState: InteractiveGraphState = {
allowReflexAngles: false,
};

const defaultUnlimitedPointState: InteractiveGraphState = {
type: "point",
focusedPointIndex: 0,
coords: [[5, 0]],
numPoints: "unlimited",
hasBeenInteractedWith: true,
showRemovePointButton: false,
showKeyboardInteractionInvitation: false,
interactionMode: "mouse",
range: [
[-10, 10],
[-10, 10],
],
snapStep: [1, 1],
};

const defaultUnlimitedPolygonState: InteractiveGraphState = {
type: "polygon",
closedPolygon: false,
Expand Down Expand Up @@ -138,6 +154,32 @@ describe("getGradableGraph", () => {
]);
});

it("returns null coordinates if the unlimited point graph has an empty array of coordinates", () => {
const state: InteractiveGraphState = {
...defaultUnlimitedPointState,
coords: [],
};
const initialGraph: PerseusGraphType = {
type: "point",
};
const result = getGradableGraph(state, initialGraph);
invariant(result.type === "point");
expect(result.coords).toEqual(null);
});

it("returns coordinates if the unlimited point graph is has at least one coordinate", () => {
const state: InteractiveGraphState = {
...defaultUnlimitedPointState,
coords: [[1, 0]],
};
const initialGraph: PerseusGraphType = {
type: "point",
};
const result = getGradableGraph(state, initialGraph);
invariant(result.type === "point");
expect(result.coords).toEqual([[1, 0]]);
});

it("returns null coordinates if the unlimited polygon graph is open", () => {
const state: InteractiveGraphState = {
...defaultUnlimitedPolygonState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export function getGradableGraph(
}

if (state.type === "point" && initialGraph.type === "point") {
// The unlimited point graph must have at least 1 coordinate or else it is not considered score-able.
if (state.numPoints === "unlimited" && state.coords.length === 0) {
return {
...initialGraph,
coords: null,
};
}

return {
...initialGraph,
coords: state.coords,
Expand Down

0 comments on commit 6dcb14d

Please sign in to comment.