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("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)
})
})
......
......@@ -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",
......
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