Skip to content

Commit

Permalink
clamp h if too big
Browse files Browse the repository at this point in the history
fix for #198
  • Loading branch information
joshmarinacci committed Sep 16, 2024
1 parent f3a45f3 commit 98b800a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ function sub_path_to_stroked_sub_path(
const A = curr;
const B = cmd[1];
if (A.equals(B))
return console.log("can't project the same paths", i, cmd, A, B);
return console.warn("can't project the same paths", i, cmd, A, B);
// console.log(i,"====",B)
let next = path[i + 1];
//if first
Expand All @@ -1479,7 +1479,7 @@ function sub_path_to_stroked_sub_path(
}
const C = next[1];
if (C.equals(B))
return console.log("can't project the same paths", i, cmd, A, B);
return console.warn("can't project the same paths", i, cmd, A, B);
// console.log(i,A,B,C)
// console.log("next",next)
let BA = A.subtract(B);
Expand Down Expand Up @@ -1511,6 +1511,7 @@ function sub_path_to_stroked_sub_path(
//if turning left
//adjust outside
let h = w / Math.cos(-(Math.PI - turn) / 2);
if (h > 10) h = 10;
let C_unit = C.subtract(B)
.unit()
.rotate(-turn / 2)
Expand Down
32 changes: 32 additions & 0 deletions test/bugs/bug198.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, beforeEach, it, expect } from "vitest";
import * as pureimage from "../../src/index.js";
import { save } from "../common.js";

describe("bug-198", () => {
it("should draw lines", async () => {
const img = pureimage.make(128, 128);
const ctx = img.getContext("2d");

ctx.fillStyle = "white";
ctx.fillRect(0, 0, 128, 128);
ctx.lineWidth = 4; // works with 1
ctx.strokeStyle = "black";
ctx.beginPath();
const line = [
[90.0, 91],
[92.25, 91],
[92.25, 90],
[90.0, 90],
//[92.00, 90] // works without this
];
console.log("moving");
ctx.moveTo(line[0][0], line[0][1]);
for (let i = 1; i < line.length; i++) {
ctx.lineTo(line[i][0], line[i][1]);
}
console.log("stroking");
ctx.stroke();
console.log("done");
await save(img, "bug/198");
});
});

0 comments on commit 98b800a

Please sign in to comment.