Skip to content

Commit

Permalink
Move getLines to polygon.tsx (#1398)
Browse files Browse the repository at this point in the history
## Summary:
It's only used by the polygon graph, and doesn't seem like a good candidate for
reuse (with a name like getLines, how would people find it?) so I moved it
closer to its usage site.

Issue: none

## Test plan:

`yarn test`

Author: benchristel

Reviewers: Myranae, jeremywiebe, mark-fitzgerald, nicolecomputer, nishasy

Required Reviewers:

Approved By: Myranae

Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1398
  • Loading branch information
benchristel authored Jul 9, 2024
1 parent cb4f23b commit fa19dbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-rats-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: move the getLines function to polygon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {PolygonAngle} from "./components/angle-indicators";
import {StyledMovablePoint} from "./components/movable-point";
import {TextLabel} from "./components/text-label";
import {useDraggable} from "./use-draggable";
import {getLines} from "./utils";

import type {MafsGraphProps, PolygonGraphState} from "../types";
import type {CollinearTuple} from "@khanacademy/perseus";

type Props = MafsGraphProps<PolygonGraphState>;

Expand Down Expand Up @@ -124,3 +124,10 @@ export const PolygonGraph = (props: Props) => {
</>
);
};

function getLines(points: readonly vec.Vector2[]): CollinearTuple[] {
return points.map((point, i) => {
const next = points[(i + 1) % points.length];
return [point, next];
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {CollinearTuple} from "../../../perseus-types";
import type {Interval, vec} from "mafs";

/**
Expand Down Expand Up @@ -42,13 +41,6 @@ export const getIntersectionOfRayWithBox = (
}
};

export const getLines = (points: readonly vec.Vector2[]): CollinearTuple[] => {
return points.map((point, i) => {
const next = points[(i + 1) % points.length];
return [point, next];
});
};

function isBetween(x: number, low: number, high: number) {
return x >= low && x <= high;
}

0 comments on commit fa19dbc

Please sign in to comment.