Skip to content

Commit

Permalink
fix: #5
Browse files Browse the repository at this point in the history
  • Loading branch information
exqt committed Oct 19, 2023
1 parent ddcbeb1 commit 8f99cd9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/models/glyphData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,37 +197,38 @@ export class GlyphData {
// | |
// <----v

getContours(offsetX = 0, offsetY = 0, scale = 1, size = 24) {
getContours(offsetX = 0, offsetY = 0, scale = 1) {
const UP = 0;
const RIGHT = 1;
const DOWN = 2;
const LEFT = 3;

size += 1;
let arrows: Array<Array<[number, number]>> = new Array<Array<[number, number]>>(size*size);
let toVertex = (x: number, y: number) => x*size + y;
let toPosition = (v: number): [number, number] => [Math.floor(v / size), v % size];
let width = this.getWidth() + 1;
let height = this.getHeight() + 1;
let arrows: Array<Array<[number, number]>> = new Array<Array<[number, number]>>((width+2)*(height+2)+1);
let toVertex = (x: number, y: number) => x + y*(width+1);
let toPosition = (v: number): [number, number] => [v % (width+1), Math.floor(v / (width+1))];

for (let i = 0; i < size*size; i++) arrows[i] = [];
for (let i = 0; i < (width+2)*(height+2) + 1; i++) arrows[i] = [];

// generate unit arrows
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
let b0 = this.getPixel(x, y);
let bl = this.getPixel(x - 1, y);
let bd = this.getPixel(x, y - 1);

if (b0 != 0 && bl == 0) { // up
arrows[toVertex(x, y)].push([toVertex(x, y + 1), UP]);
}
else if(b0 == 0 && bl != 0) { // down
else if (b0 == 0 && bl != 0) { // down
arrows[toVertex(x, y + 1)].push([toVertex(x, y), DOWN]);
}

if (b0 != 0 && bd == 0) { // left
arrows[toVertex(x + 1, y)].push([toVertex(x, y), LEFT]);
}
else if(b0 == 0 && bd != 0) { // right
else if (b0 == 0 && bd != 0) { // right
arrows[toVertex(x, y)].push([toVertex(x + 1, y), RIGHT]);
}
}
Expand Down Expand Up @@ -256,7 +257,7 @@ export class GlyphData {
}
}

for (let v = 0; v < size*size; v++) {
for (let v = 0; v < (width+2)*(height+2) + 1; v++) {
while (arrows[v].length > 0) {
tour(arrows[v][0][0], arrows[v][0][1]);
}
Expand Down

0 comments on commit 8f99cd9

Please sign in to comment.