Commit 9a82021a authored by hucy's avatar hucy

fix:不重要的提交

parent 481607b1
...@@ -87,10 +87,10 @@ function createShape() { ...@@ -87,10 +87,10 @@ function createShape() {
draggable: true, draggable: true,
}); });
state.shape = new Konva.Rect({ state.shape = new Konva.Rect({
width: 30 + Math.random() * 30, width: 60 + Math.random() * 30,
height: 30 + Math.random() * 30, height: 60 + Math.random() * 30,
fill: 'grey', fill: 'grey',
rotation: 360 * Math.random(), // rotation: 360 * Math.random(),
name: 'fillShape', name: 'fillShape',
}); });
state.group.add(state.shape); state.group.add(state.shape);
...@@ -117,10 +117,10 @@ function haveIntersection(r1: any, r2: any) { ...@@ -117,10 +117,10 @@ function haveIntersection(r1: any, r2: any) {
c: false, c: false,
d: false, d: false,
}; };
let pos: any = { // let pos: any = {
x: r2.x + r2.width, // x: r2.x + r2.width,
y: r2.y + r2.height, // y: r2.y + r2.height,
}; // };
if (r2.x > r1.x + r1.width) { if (r2.x > r1.x + r1.width) {
obj.a = true; obj.a = true;
} }
...@@ -133,11 +133,11 @@ function haveIntersection(r1: any, r2: any) { ...@@ -133,11 +133,11 @@ function haveIntersection(r1: any, r2: any) {
if (r2.y + r2.height < r1.y) { if (r2.y + r2.height < r1.y) {
obj.d = true; obj.d = true;
} }
console.log('obj', obj, obj.a || obj.b || obj.c || obj.d); // console.log('obj', obj, obj.a || obj.b || obj.c || obj.d);
return { return {
value: !(obj.a || obj.b || obj.c || obj.d), value: !(obj.a || obj.b || obj.c || obj.d),
pos, // pos,
}; };
// return !( // return !(
...@@ -156,13 +156,21 @@ function layerDragmove(e: any) { ...@@ -156,13 +156,21 @@ function layerDragmove(e: any) {
if (group._id == target._id) { if (group._id == target._id) {
return; return;
} }
// r1当前循环的可视矩形区域 r2当前移动目标的可视矩形区域
let r1 = group.getClientRect(); let r1 = group.getClientRect();
let r2 = targetRect; let r2 = targetRect;
let result = haveIntersection(r1, r2); let result = haveIntersection(r1, r2);
if (result.value) { if (result.value) {
console.log('1', target._lastPos); // 有碰撞
// target.x(result.pos.x); console.log('1', target);
// target.y(result.pos.y); if (r2.x < r1.x + r1.width / 2) {
target.x(r1.x - r2.width);
} else {
target.x(r1.x + r1.width);
}
// target.x(100);
// target.y(100);
group.findOne('.fillShape').fill('red'); group.findOne('.fillShape').fill('red');
} else { } else {
group.findOne('.fillShape').fill('grey'); group.findOne('.fillShape').fill('grey');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment