Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Intersection of two rectangles gives invalid results because of rounding errors #207

@theres

Description

@theres

Hi!
I've two rectangles that are overlapping only a tiny bit. However, as a result I'm getting back the polygon2.

import { polygon, BooleanOperations } from '@flatten-js/core';

const { intersect } = BooleanOperations;

const coords1 = [
  { x: -268, y: -334.18 },
  { x: -1768, y: -334.18 },
  { x: -1768, y: -686.18 },
  { x: -268, y: -686.18 },
];

const coords2 = [
  { x: -968, y: -334.17999999999995 },
  { x: -868, y: -334.17999999999995 },
  { x: -868, y: -234.17999999999995 },
  { x: -968, y: -234.17999999999995 },
];

const poly1 = polygon(coords1.map(p => [p.x, p.y]));
const poly2 = polygon(coords2.map(p => [p.x, p.y]));

const intersection = intersect(poly1, poly2);

console.log(intersection.vertices);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions