diff --git a/__tests__/shape.test.js b/__tests__/shape.test.js index db3d23faa4b6769cc98a19f49117a512cc48898b..917d617194b33f6893fb96b50c47206706b78dca 100644 --- a/__tests__/shape.test.js +++ b/__tests__/shape.test.js @@ -1,4 +1,4 @@ -import recognizeFromPoints, { Shapes, LineDirections } from "../src/shapes" +import recognizeFromPoints, { Shapes } from "../src/shapes" describe("shape recognition", () => { describe("general", () => { @@ -14,21 +14,21 @@ describe("shape recognition", () => { const points = [[0, 0], [100, 0]] const result = recognizeFromPoints(points) expect(result.shape).toBe(Shapes.line) - expect(result.direction).toBe(LineDirections.h) + expect(result.angle).toBe(0) }) test("should recognize a simple vertical line", () => { const points = [[0, 50], [0, -100]] const result = recognizeFromPoints(points) expect(result.shape).toBe(Shapes.line) - expect(result.direction).toBe(LineDirections.v) + expect(result.angle).toBe(90) }) test("should recognize a slightly curve horizontal line", () => { const points = [[0, 0], [30, 5], [100, 2]] const result = recognizeFromPoints(points) expect(result.shape).toBe(Shapes.line) - expect(result.direction).toBe(LineDirections.h) + expect(result.angle).toBe(0) }) test("should not recognize a really curved horizontal line", () => { @@ -57,7 +57,7 @@ describe("shape recognition", () => { ] const result = recognizeFromPoints(points) expect(result.shape).toBe(Shapes.line) - expect(result.direction).toBe(LineDirections.h) + expect(result.angle).toBe(0) }) test("should recognize a long vertical line", () => { @@ -100,7 +100,7 @@ describe("shape recognition", () => { ] const result = recognizeFromPoints(points) expect(result.shape).toBe(Shapes.line) - expect(result.direction).toBe(LineDirections.v) + expect(result.angle).toBe(90) }) test("should recognize a line at 20 degrees", () => { @@ -177,7 +177,7 @@ describe("shape recognition", () => { const result = recognizeFromPoints(points) expect(result.shape).toBe(Shapes.line) - expect(result.direction).toBe(LineDirections.d20) + expect(result.angle).toBe(20) }) }) diff --git a/src/shapes.js b/src/shapes.js index 4611b7324d6aa5a68b876504b250da520d3ec1ef..28268defc5c07ebef58668db0e0a86ae1c6fcf04 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -9,7 +9,7 @@ function sin(a) { } const rhoStep = 5 -const angleStep = 10 +const angleStep = rhoStep * 2 const numAngleCells = 180 / angleStep const rhoMax = 1000 @@ -63,7 +63,7 @@ function recognizeFromPoints(points) { if (angle !== undefined) { return { shape: Shapes.line, - direction: getDirection(angle), + angle: 90 - angle, points, } } @@ -71,20 +71,6 @@ function recognizeFromPoints(points) { return {} } -const dirMap = { 0: "v", 90: "h", 70: "d20" } - -function getDirection(angle) { - const map = dirMap[angle] - if (map == undefined) return angle - return LineDirections[map] -} - -export const LineDirections = { - v: "v", - h: "h", - d20: "20", -} - export const Shapes = { rectangle: "rect", line: "line",