Skip to content

Commit

Permalink
fix(graph.ts): overlapping area calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Oct 23, 2019
1 parent 66711f1 commit c76483a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ const storeModel: StoreModel = {
selection,
state.transform
);

if (!selectedNodes.length) {
state.nodesSelectionActive = false;
state.selectedElements = [];

return;
}

const selectedNodesBbox = getRectOfNodes(selectedNodes);

state.selection = selection;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ export const getNodesInside = (
width: rect.width / tScale,
height: rect.height / tScale,
});

return nodes.filter(({ __rg: { position, width, height } }) => {
const nBox = rectToBox({ ...position, width, height });
const overlappingArea =
(Math.max(rBox.x, nBox.x) - Math.min(rBox.x2, nBox.x2)) * (Math.max(rBox.y, nBox.y) - Math.min(rBox.y2, nBox.y2));
const xOverlap = Math.max(0, Math.min(rBox.x2, nBox.x2) - Math.max(rBox.x, nBox.x));
const yOverlap = Math.max(0, Math.min(rBox.y2, nBox.y2) - Math.max(rBox.y, nBox.y));
const overlappingArea = xOverlap * yOverlap;

if (partially) {
return overlappingArea >= 0;
}
Expand Down

0 comments on commit c76483a

Please sign in to comment.