fix: apply the safety margin with a distance transform
An elliptical erode kernel costs radius² per pixel. While typing a length, an intermediate value like "3" mm made the margin hundreds of pixels and froze the page for minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
55a25ba978
commit
8ea525a1e8
2 files changed
+33
-7
No files matched your search
@@ -85,6 +85,17 @@ describe('traceMask', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('traceMask performance', () => {
|
||||
it('handles a huge margin quickly (e.g. while a length is half-typed)', () => {
|
||||
const m = maskFrom(cv, 2000, 1500, (x, y) => inRect(x, y, 200, 200, 1800, 1300));
|
||||
mats.push(m);
|
||||
const start = performance.now();
|
||||
const shape = traceMask(cv, m, -300)!;
|
||||
expect(performance.now() - start).toBeLessThan(1500);
|
||||
expect(Math.abs(bounds(shape.outer).minX - 500)).toBeLessThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('otsuThreshold', () => {
|
||||
it('lands between background and piece brightness', () => {
|
||||
const image = grayImage(200, 160, (x, y) => (inRect(x, y, 40, 30, 160, 130) ? 220 : 30));
|
||||
|
||||
Reference in new issue
Block a user