Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersect does not seem to work when a shape is inside another #42

Closed
aalexgabi opened this issue Apr 30, 2020 · 2 comments
Closed

Intersect does not seem to work when a shape is inside another #42

aalexgabi opened this issue Apr 30, 2020 · 2 comments
Labels

Comments

@aalexgabi
Copy link

const { polygon } = require('@flatten-js/core');
const { intersect } = require('@flatten-js/boolean-op');

const item1 = polygon([
  [0, 30],
  [30, 30],
  [30, 0],
  [0, 0],
  [0, 30],
]);

const item2 = polygon([
  [10, 20],
  [20, 20],
  [20, 10],
  [10, 10],
  [10, 20],
]);

const intersection = intersect(item1, item2);

console.log('item1', item1.svg());
console.log('item2', item2.svg());
console.log('intersection', intersection.svg());

Prints:

<path stroke="black" stroke-width="1" fill="lightcyan" fill-rule="evenodd" fill-opacity="1"   d="
M0,30 L30,30 L30,0 L0,0 L0,30 L0,30 z" >
</path>
item2 
<path stroke="black" stroke-width="1" fill="lightcyan" fill-rule="evenodd" fill-opacity="1"   d="
M10,20 L20,20 L20,10 L10,10 L10,20 L10,20 z" >
</path>
intersection 
<path stroke="black" stroke-width="1" fill="lightcyan" fill-rule="evenodd" fill-opacity="1"   d="" >
</path>

I also tried using the intersect method on the polygon object:

const { polygon } = require('@flatten-js/core');

const item1 = polygon([
  [0, 30],
  [30, 30],
  [30, 0],
  [0, 0],
  [0, 30],
]);

const item2 = polygon([
  [10, 20],
  [20, 20],
  [20, 10],
  [10, 10],
  [10, 20],
]);


console.log('item1', item1.svg());
console.log('item2', item2.svg());
console.log('intersection', item1.intersect(item2));

Which prints:

item1 
<path stroke="black" stroke-width="1" fill="lightcyan" fill-rule="evenodd" fill-opacity="1"   d="
M0,30 L30,30 L30,0 L0,0 L0,30 L0,30 z" >
</path>
item2 
<path stroke="black" stroke-width="1" fill="lightcyan" fill-rule="evenodd" fill-opacity="1"   d="
M10,20 L20,20 L20,10 L10,10 L10,20 L10,20 z" >
</path>
intersection []
@alexbol99 alexbol99 added the bug label Apr 30, 2020
@alexbol99
Copy link
Owner

Hello @aalexgabi ,

Indeed, this is a bug in boolean operations (very stupid), I will release a patch soon.

Method intersect of the polygon object returns array of intersection points between two boundaries, so in this case it returns empty array, which is normal.

By the way, when define polygon, don't need to repeat the first point, it cause obsolete zero-length segment in the path.

Thanks,
Alex Bol

@alexbol99
Copy link
Owner

Hello @aalexgabi ,

Bug fixed in @flatten-js/core package release v.1.2.5.
Note, that boolean operations now moved to core package under namespace BooleanOperations, you can use it like this:

  const { polygon } = Flatten;
  const { intersect } = Flatten.BooleanOperations;

  const item1 = polygon([[0, 30], [30, 30], [30, 0], [0, 0]]);
  const item2 = polygon([[10, 20], [20, 20], [20, 10], [10, 10]]);
  const intersection = intersect(item1, item2);

See how it works in this notebook.

Package @flatten-js/boolean-op not fixed yes

Best regards,
Alex Bol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants