Skip to content

Commit

Permalink
Minor clean-ups for the past few PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Oct 3, 2018
1 parent 959ccc8 commit 6a278c0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
13 changes: 7 additions & 6 deletions src/dom/DomEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ var DomEvent = /** @lends DomEvent */{
for (var i = 0, l = parts.length; i < l; i++) {
var name = parts[i];
// For touchstart/touchmove events on document, we need to
// explicitely declare that event is not passive (can be
// prevented). Otherwise chrome browser would ignore
// event.preventDefault() calls. See #1501 and
// explicitly declare that the event is not passive (can be
// prevented). Otherwise chrome browser would ignore
// `event.preventDefault()` calls and omit warnings.
// See #1501 and:
// https://www.chromestatus.com/features/5093566007214080
var options = (
el === document
&& (name === 'touchstart' || name === 'touchmove')
) ? { passive: false } : false;
el === document
&& (name === 'touchstart' || name === 'touchmove')
) ? { passive: false } : false;
el.addEventListener(name, func, options);
}
}
Expand Down
38 changes: 20 additions & 18 deletions src/item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,31 +751,32 @@ new function() { // Injection scope for various item event handlers
// use them to calculate the difference in #setPosition, as when it is
// modified, it would hold new values already and only then cause the
// calling of #setPosition.
if (!this._position) {
// set position if needed
this._position = this._getPositionFromBounds();
}
return new ctor(this._position.x, this._position.y, this, 'setPosition');
var position = this._position ||
(this._position = this._getPositionFromBounds());
return new ctor(position.x, position.y, this, 'setPosition');
},

setPosition: function(/* point */) {
// Calculate the distance to the current position, by which to
// translate the item. Pass true for _dontLink, as we do not need a
// LinkedPoint to simply calculate this distance.
this.translate(Point.read(arguments).subtract(this.getPosition(true)));
},

/**
* Internal method used to calculate position either from pivot point or bounds.
* Internal method used to calculate position either from pivot point or
* bounds.
* @param {Rectangle} bounds if provided, these bounds are used instead of
* calling getBounds()
* @returns {Point} the transformed pivot point or the center of the bounds
* calling getBounds()
* @return {Point} the transformed pivot point or the center of the bounds
* @private
*/
_getPositionFromBounds: function(bounds) {
// If an pivot point is provided, use it to determine position
// based on the matrix. Otherwise use the center of the bounds.
return this._pivot
? this._matrix._transformPoint(this._pivot)
: (bounds || this.getBounds()).getCenter(true);
},

setPosition: function(/* point */) {
// Calculate the distance to the current position, by which to
// translate the item. Pass true for _dontLink, as we do not need a
// LinkedPoint to simply calculate this distance.
this.translate(Point.read(arguments).subtract(this.getPosition(true)));
? this._matrix._transformPoint(this._pivot)
: (bounds || this.getBounds()).getCenter(true);
},

/**
Expand Down Expand Up @@ -3519,7 +3520,8 @@ new function() { // Injection scope for hit-test functions shared with project
this._bounds = bounds;
// If we have cached bounds, try to determine _position as its
// center. Use _boundsOptions do get the cached default bounds.
var cached = bounds[this._getBoundsCacheKey(this._boundsOptions || {})];
var cached = bounds[this._getBoundsCacheKey(
this._boundsOptions || {})];
if (cached) {
// use this method to handle pivot case (see #1503)
this._position = this._getPositionFromBounds(cached.rect);
Expand Down
2 changes: 1 addition & 1 deletion src/path/Curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ new function() { // Scope for methods that require private functions
* http://math.stackexchange.com/questions/1954845/bezier-curvature-extrema
*
* @param {Number[]} v the curve values array
* @returns {Number[]} the roots of all found peaks
* @return {Number[]} the roots of all found peaks
*/
getPeaks: function(v) {
var x0 = v[0], y0 = v[1],
Expand Down
2 changes: 1 addition & 1 deletion src/path/PathItem.Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ PathItem.inject(new function() {
* @param {Boolean} [clockwise] if provided, the orientation of the root
* paths will be set to the orientation specified by `clockwise`,
* otherwise the orientation of the largest root child is used.
* @returns {Item[]} the reoriented paths
* @return {Item[]} the reoriented paths
*/
function reorientPaths(paths, isInside, clockwise) {
var length = paths && paths.length;
Expand Down
4 changes: 2 additions & 2 deletions test/tests/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,10 @@ test('Item#scaling, #rotation', function() {
'shape2.bounds, setting shape2.scaling before shape2.rotation');
});

test('Item#position cache issue with pivot point #1503', function() {
test('Item#position pivot point and caching (#1503)', function() {
var item = Path.Rectangle(new Point(0, 0), new Size(20));
item.pivot = new Point(0, 0);
item.getBounds();
var bounds = item.bounds;
item.translate(5, 5);
equals(item.position, new Point(5, 5));
});

0 comments on commit 6a278c0

Please sign in to comment.