Skip to content

Commit

Permalink
fixup! Do not consider invisible nodes in areNodesIntersecting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhin committed Oct 25, 2023
1 parent dc11840 commit 5f75784
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ describe('areNodesIntersecting', () => {
const node = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
id: '1',
visible: true,
} as unknown as SceneNode;

const selectedNode = {
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(false);
});

test('should return false if node and selectedNode are identical', () => {
const node = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
absoluteBoundingBox: { height: 50, width: 50, x: 20, y: 20 },
id: '1',
visible: true,
} as unknown as SceneNode;

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 20, y: 20 },
id: '1',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(false);
Expand All @@ -33,11 +37,13 @@ describe('areNodesIntersecting', () => {
test('should return false if node has no bounding box', () => {
const node = {
id: '1',
visible: true,
} as unknown as SceneNode;

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 20, y: 20 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(false);
Expand All @@ -47,11 +53,13 @@ describe('areNodesIntersecting', () => {
const selectedNode = {
absoluteBoundingBox: { height: 40, width: 40, x: 25, y: 25 },
id: '1',
visible: true,
} as unknown as SceneNode;

const node = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(true);
Expand All @@ -61,11 +69,13 @@ describe('areNodesIntersecting', () => {
const node = {
absoluteBoundingBox: { height: 60, width: 60, x: 50, y: 50 },
id: '1',
visible: true,
} as unknown as SceneNode;

const selectedNode = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(false);
Expand All @@ -75,13 +85,47 @@ describe('areNodesIntersecting', () => {
const node = {
absoluteBoundingBox: { height: 10, width: 10, x: 120, y: 120 },
id: '1',
visible: true,
} as unknown as SceneNode;

const selectedNode = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(false);
});

test('should return false if node is not visible', () => {
const node = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
id: '1',
visible: false,
} as unknown as SceneNode;

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 20, y: 20 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(false);
});

test('should return true if node is fully contained within visible selectedNode', () => {
const selectedNode = {
absoluteBoundingBox: { height: 40, width: 40, x: 25, y: 25 },
id: '1',
visible: true,
} as unknown as SceneNode;

const node = {
absoluteBoundingBox: { height: 100, width: 100, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(areNodesIntersecting(node, selectedNode)).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ describe('traverseAndCheckIntersections', () => {
{
absoluteBoundingBox: { height: 50, width: 50, x: 200, y: 200 },
id: '1',
visible: true,
},
] as unknown as SceneNode[];

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(traverseAndCheckIntersections(nodes, selectedNode)).toEqual([]);
Expand All @@ -24,12 +26,14 @@ describe('traverseAndCheckIntersections', () => {
{
absoluteBoundingBox: { height: 100, width: 100, x: 0, y: 0 },
id: '1',
visible: true,
},
] as unknown as SceneNode[];

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(traverseAndCheckIntersections(nodes, selectedNode)).toEqual(nodes);
Expand All @@ -42,14 +46,17 @@ describe('traverseAndCheckIntersections', () => {
{
absoluteBoundingBox: { height: 90, width: 90, x: 0, y: 0 },
id: '3',
visible: true,
},
],
id: '1',
visible: true,
} as unknown as FrameNode;

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(traverseAndCheckIntersections([frameNode], selectedNode)).toEqual([
Expand All @@ -66,15 +73,18 @@ describe('traverseAndCheckIntersections', () => {
{
absoluteBoundingBox: { height: 5, width: 5, x: 90, y: 90 },
id: '3',
visible: true,
},
],
id: '1',
visible: true,
},
] as unknown as SceneNode[];

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(traverseAndCheckIntersections(nodes, selectedNode)).toEqual([
Expand All @@ -87,12 +97,14 @@ describe('traverseAndCheckIntersections', () => {
{
absoluteBoundingBox: { height: 50, width: 50, x: 10, y: 10 },
id: '2',
visible: true,
},
] as unknown as SceneNode[];

const selectedNode = {
absoluteBoundingBox: { height: 50, width: 50, x: 10, y: 10 },
id: '2',
visible: true,
} as unknown as SceneNode;

expect(traverseAndCheckIntersections(nodes, selectedNode)).toEqual([]);
Expand Down

0 comments on commit 5f75784

Please sign in to comment.