mirror of
https://github.com/konvajs/konva.git
synced 2025-07-15 10:12:44 +08:00
new haveIntersection method
This commit is contained in:
parent
fa2db3ed1a
commit
52f1b91387
@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
* new `Konva.Transformer` group that allow simple resize, and rotate of a shape.
|
||||
* Add ability to remove event by callback `node.off('event', callback)`.
|
||||
* new `Konva.Filters.Contrast`.
|
||||
* new `Konva.Util.haveIntersection()` to detect collusion
|
||||
|
||||
## Changed
|
||||
|
||||
|
77
konva.js
77
konva.js
@ -2,7 +2,7 @@
|
||||
* Konva JavaScript Framework v1.7.6
|
||||
* http://konvajs.github.io/
|
||||
* Licensed under the MIT
|
||||
* Date: Mon Feb 05 2018
|
||||
* Date: Tue Feb 06 2018
|
||||
*
|
||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||
@ -732,59 +732,6 @@
|
||||
_isString: function(obj) {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
||||
},
|
||||
// Returns a function, that, when invoked, will only be triggered at most once
|
||||
// during a given window of time. Normally, the throttled function will run
|
||||
// as much as it can, without ever going more than once per `wait` duration;
|
||||
// but if you'd like to disable the execution on the leading edge, pass
|
||||
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
||||
_throttle: function(func, wait, opts) {
|
||||
var context, args, result;
|
||||
var timeout = null;
|
||||
var previous = 0;
|
||||
var options = opts || {};
|
||||
var later = function() {
|
||||
previous = options.leading === false ? 0 : new Date().getTime();
|
||||
timeout = null;
|
||||
result = func.apply(context, args);
|
||||
context = args = null;
|
||||
};
|
||||
return function() {
|
||||
var now = new Date().getTime();
|
||||
if (!previous && options.leading === false) {
|
||||
previous = now;
|
||||
}
|
||||
var remaining = wait - (now - previous);
|
||||
context = this;
|
||||
args = arguments;
|
||||
if (remaining <= 0) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
previous = now;
|
||||
result = func.apply(context, args);
|
||||
context = args = null;
|
||||
} else if (!timeout && options.trailing !== false) {
|
||||
timeout = setTimeout(later, remaining);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
},
|
||||
/*
|
||||
* other utils
|
||||
*/
|
||||
_hasMethods: function(obj) {
|
||||
var names = [],
|
||||
key;
|
||||
|
||||
for (key in obj) {
|
||||
if (!obj.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
if (this._isFunction(obj[key])) {
|
||||
names.push(key);
|
||||
}
|
||||
}
|
||||
return names.length > 0;
|
||||
},
|
||||
isValidSelector: function(selector) {
|
||||
if (typeof selector !== 'string') {
|
||||
return false;
|
||||
@ -1037,6 +984,19 @@
|
||||
}
|
||||
return retObj;
|
||||
},
|
||||
/**
|
||||
* check intersection of two client rectangles
|
||||
* @method
|
||||
* @memberof Konva.Util.prototype
|
||||
*/
|
||||
haveIntersection: function(r1, r2) {
|
||||
return !(
|
||||
r2.x > r1.x + r1.width ||
|
||||
r2.x + r2.width < r1.x ||
|
||||
r2.y > r1.y + r1.height ||
|
||||
r2.y + r2.height < r1.y
|
||||
);
|
||||
},
|
||||
cloneObject: function(obj) {
|
||||
var retObj = {};
|
||||
for (var key in obj) {
|
||||
@ -18348,6 +18308,8 @@
|
||||
'bottom-right'
|
||||
];
|
||||
|
||||
var warningShowed = false;
|
||||
|
||||
Konva.Transformer.prototype = {
|
||||
_centroid: false,
|
||||
____init: function(config) {
|
||||
@ -18361,6 +18323,13 @@
|
||||
|
||||
// update transformer data for certain attr changes
|
||||
this.on(ATTR_CHANGE_LIST, this._update);
|
||||
|
||||
if (!warningShowed) {
|
||||
Konva.Util.warn(
|
||||
'Konva.Transformer is currently experimental and may have many bugs. Please report any bugs to GitHub repo.'
|
||||
);
|
||||
warningShowed = true;
|
||||
}
|
||||
},
|
||||
|
||||
attachTo: function(node) {
|
||||
|
6
konva.min.js
vendored
6
konva.min.js
vendored
File diff suppressed because one or more lines are too long
66
src/Util.js
66
src/Util.js
@ -487,59 +487,6 @@
|
||||
_isString: function(obj) {
|
||||
return Object.prototype.toString.call(obj) === OBJECT_STRING;
|
||||
},
|
||||
// Returns a function, that, when invoked, will only be triggered at most once
|
||||
// during a given window of time. Normally, the throttled function will run
|
||||
// as much as it can, without ever going more than once per `wait` duration;
|
||||
// but if you'd like to disable the execution on the leading edge, pass
|
||||
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
||||
_throttle: function(func, wait, opts) {
|
||||
var context, args, result;
|
||||
var timeout = null;
|
||||
var previous = 0;
|
||||
var options = opts || {};
|
||||
var later = function() {
|
||||
previous = options.leading === false ? 0 : new Date().getTime();
|
||||
timeout = null;
|
||||
result = func.apply(context, args);
|
||||
context = args = null;
|
||||
};
|
||||
return function() {
|
||||
var now = new Date().getTime();
|
||||
if (!previous && options.leading === false) {
|
||||
previous = now;
|
||||
}
|
||||
var remaining = wait - (now - previous);
|
||||
context = this;
|
||||
args = arguments;
|
||||
if (remaining <= 0) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
previous = now;
|
||||
result = func.apply(context, args);
|
||||
context = args = null;
|
||||
} else if (!timeout && options.trailing !== false) {
|
||||
timeout = setTimeout(later, remaining);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
},
|
||||
/*
|
||||
* other utils
|
||||
*/
|
||||
_hasMethods: function(obj) {
|
||||
var names = [],
|
||||
key;
|
||||
|
||||
for (key in obj) {
|
||||
if (!obj.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
if (this._isFunction(obj[key])) {
|
||||
names.push(key);
|
||||
}
|
||||
}
|
||||
return names.length > 0;
|
||||
},
|
||||
isValidSelector: function(selector) {
|
||||
if (typeof selector !== 'string') {
|
||||
return false;
|
||||
@ -792,6 +739,19 @@
|
||||
}
|
||||
return retObj;
|
||||
},
|
||||
/**
|
||||
* check intersection of two client rectangles
|
||||
* @method
|
||||
* @memberof Konva.Util.prototype
|
||||
*/
|
||||
haveIntersection: function(r1, r2) {
|
||||
return !(
|
||||
r2.x > r1.x + r1.width ||
|
||||
r2.x + r2.width < r1.x ||
|
||||
r2.y > r1.y + r1.height ||
|
||||
r2.y + r2.height < r1.y
|
||||
);
|
||||
},
|
||||
cloneObject: function(obj) {
|
||||
var retObj = {};
|
||||
for (var key in obj) {
|
||||
|
@ -34,6 +34,8 @@
|
||||
'bottom-right'
|
||||
];
|
||||
|
||||
var warningShowed = false;
|
||||
|
||||
Konva.Transformer.prototype = {
|
||||
_centroid: false,
|
||||
____init: function(config) {
|
||||
@ -47,6 +49,13 @@
|
||||
|
||||
// update transformer data for certain attr changes
|
||||
this.on(ATTR_CHANGE_LIST, this._update);
|
||||
|
||||
if (!warningShowed) {
|
||||
Konva.Util.warn(
|
||||
'Konva.Transformer is currently experimental and may have many bugs. Please report any bugs to GitHub repo.'
|
||||
);
|
||||
warningShowed = true;
|
||||
}
|
||||
},
|
||||
|
||||
attachTo: function(node) {
|
||||
|
Loading…
Reference in New Issue
Block a user