Skip to content

Commit

Permalink
wip: debugging collision
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Oct 9, 2024
1 parent 445db88 commit cdd61a5
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ export const createDynamicCollisionDetector = (
const { dragOperation, droppable } = input;

const { position } = dragOperation;
const dragShape = dragOperation.shape?.current;
const { shape: dropShape } = droppable;
const { current: dragShape, last: lastDragShape } =
dragOperation.shape || {};

const dropShape = droppable.shape;

// TODO last shape fix is custom dndkit patch
// const dropShape =
// dragOperation.source?.id === droppable.id
// ? lastDragShape
// : droppable.shape;

if (!dragShape || !dropShape) {
return null;
Expand Down Expand Up @@ -68,23 +76,29 @@ export const createDynamicCollisionDetector = (

const collision = directionalCollision(input, interval.previous);

if (collision) {
return {
...collision,
priority: CollisionPriority.Highest,
data: {
direction: interval.direction,
},
};
}

// return null;
// console.log("dropShape", droppable.id, dropShape);

collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "yellow");

// if (collision) {
// return {
// ...collision,
// priority: CollisionPriority.Highest,
// data: {
// direction: interval.direction,
// },
// };
// }

return null;
}

const intersectionArea = dragShape.intersectionArea(dropShape);
const intersectionRatio = intersectionArea / dropShape.area;

if (intersectionArea && overMidpoint) {
// console.log("dropShape", droppable.id, dropShape);

collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "green");

const collision: Collision = {
Expand All @@ -97,6 +111,8 @@ export const createDynamicCollisionDetector = (
type: "" as any,
};

console.log("collide", droppable.id);

return collision;
}

Expand Down

0 comments on commit cdd61a5

Please sign in to comment.