Skip to content
Snippets Groups Projects
Commit 4a2642ae authored by Yuriy Maksymets's avatar Yuriy Maksymets
Browse files

Using angles instead of directions

parent 41e2851b
No related branches found
No related tags found
No related merge requests found
import recognizeFromPoints, { Shapes, LineDirections } from "../src/shapes" import recognizeFromPoints, { Shapes } from "../src/shapes"
describe("shape recognition", () => { describe("shape recognition", () => {
describe("general", () => { describe("general", () => {
...@@ -14,21 +14,21 @@ describe("shape recognition", () => { ...@@ -14,21 +14,21 @@ describe("shape recognition", () => {
const points = [[0, 0], [100, 0]] const points = [[0, 0], [100, 0]]
const result = recognizeFromPoints(points) const result = recognizeFromPoints(points)
expect(result.shape).toBe(Shapes.line) expect(result.shape).toBe(Shapes.line)
expect(result.direction).toBe(LineDirections.h) expect(result.angle).toBe(0)
}) })
test("should recognize a simple vertical line", () => { test("should recognize a simple vertical line", () => {
const points = [[0, 50], [0, -100]] const points = [[0, 50], [0, -100]]
const result = recognizeFromPoints(points) const result = recognizeFromPoints(points)
expect(result.shape).toBe(Shapes.line) 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", () => { test("should recognize a slightly curve horizontal line", () => {
const points = [[0, 0], [30, 5], [100, 2]] const points = [[0, 0], [30, 5], [100, 2]]
const result = recognizeFromPoints(points) const result = recognizeFromPoints(points)
expect(result.shape).toBe(Shapes.line) 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", () => { test("should not recognize a really curved horizontal line", () => {
...@@ -57,7 +57,7 @@ describe("shape recognition", () => { ...@@ -57,7 +57,7 @@ describe("shape recognition", () => {
] ]
const result = recognizeFromPoints(points) const result = recognizeFromPoints(points)
expect(result.shape).toBe(Shapes.line) expect(result.shape).toBe(Shapes.line)
expect(result.direction).toBe(LineDirections.h) expect(result.angle).toBe(0)
}) })
test("should recognize a long vertical line", () => { test("should recognize a long vertical line", () => {
...@@ -100,7 +100,7 @@ describe("shape recognition", () => { ...@@ -100,7 +100,7 @@ describe("shape recognition", () => {
] ]
const result = recognizeFromPoints(points) const result = recognizeFromPoints(points)
expect(result.shape).toBe(Shapes.line) 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", () => { test("should recognize a line at 20 degrees", () => {
...@@ -177,7 +177,7 @@ describe("shape recognition", () => { ...@@ -177,7 +177,7 @@ describe("shape recognition", () => {
const result = recognizeFromPoints(points) const result = recognizeFromPoints(points)
expect(result.shape).toBe(Shapes.line) expect(result.shape).toBe(Shapes.line)
expect(result.direction).toBe(LineDirections.d20) expect(result.angle).toBe(20)
}) })
}) })
......
...@@ -9,7 +9,7 @@ function sin(a) { ...@@ -9,7 +9,7 @@ function sin(a) {
} }
const rhoStep = 5 const rhoStep = 5
const angleStep = 10 const angleStep = rhoStep * 2
const numAngleCells = 180 / angleStep const numAngleCells = 180 / angleStep
const rhoMax = 1000 const rhoMax = 1000
...@@ -63,7 +63,7 @@ function recognizeFromPoints(points) { ...@@ -63,7 +63,7 @@ function recognizeFromPoints(points) {
if (angle !== undefined) { if (angle !== undefined) {
return { return {
shape: Shapes.line, shape: Shapes.line,
direction: getDirection(angle), angle: 90 - angle,
points, points,
} }
} }
...@@ -71,20 +71,6 @@ function recognizeFromPoints(points) { ...@@ -71,20 +71,6 @@ function recognizeFromPoints(points) {
return {} 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 = { export const Shapes = {
rectangle: "rect", rectangle: "rect",
line: "line", line: "line",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment