microsoft / microsoft/maker.js

Unexpected subtract behaviour

Open
#463 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2k
Forks
302
Avg merge
21h 28m
Merged PRs (30d)
5

Description

Version 0.17 (NPM)

While using this library I stumbled upon the following unexpected result after subtracting a square model from two concentric circles:

image

The result should be:

image

Code to reproduce in the playground:

var makerjs = require('makerjs');

var rectangle = {
  paths: {
    top: new makerjs.paths.Line([-84, 226], [-82, -7]),
    bottom: new makerjs.paths.Line([32.5,227], [34.5, -6]),
    left: new makerjs.paths.Line([32.5, 227], [-84, 226]),
    right: new makerjs.paths.Line([-82,-7], [34.5,-6])
  }
};

var concentricCirles = {
  paths: {
    outerCircle: new makerjs.paths.Circle([0.5, 2], 194.005),
    innerCircle: new makerjs.paths.Circle([1.5, -0], 162)
  }
};
    
var cut = makerjs.model.combineSubtraction(concentricCirles, rectangle);

var svg = makerjs.exporter.toSVG(cut);

document.write(svg);

When making a straight rectangle, problem seems to disappear:

var rectangle = {
    	paths: {
		top: new makerjs.paths.Line([-75, 226], [-75, -5]),
      		bottom: new makerjs.paths.Line([35,225], [35, -5]),
      		left: new makerjs.paths.Line([35, 225], [-75, 225]),
      		right: new makerjs.paths.Line([-75,-5], [34.5,-5])
	}
};

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied playground reproduction with makerjs.model.combineSubtraction on the concentric circles and skewed rectangle, then inspect the subtraction and SVG export path. Compare its output with the expected image and use the straight-rectangle variant as a control; done when the skewed rectangle subtraction produces the expected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.