mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Move named inner functions out of nested scopes, to prepare for 'use strict;' transition.
This commit is contained in:
parent
d793d8a43d
commit
dc35fdbd02
5 changed files with 58 additions and 57 deletions
|
@ -16,7 +16,6 @@
|
|||
* @private
|
||||
*/
|
||||
var DomElement = new function() {
|
||||
|
||||
// We use a mix of Bootstrap.js legacy and Bonzo.js magic, ported over and
|
||||
// furhter simplified to a subset actually required by Paper.js
|
||||
|
||||
|
|
|
@ -69,6 +69,13 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
* arrays and properties of objects.
|
||||
*/
|
||||
equals: function(obj1, obj2) {
|
||||
function checkKeys(o1, o2) {
|
||||
for (var i in o1)
|
||||
if (o1.hasOwnProperty(i) && typeof o2[i] === 'undefined')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obj1 == obj2)
|
||||
return true;
|
||||
// Call #equals() on both obj1 and obj2
|
||||
|
@ -88,12 +95,6 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
}
|
||||
// Compare objects
|
||||
if (typeof obj1 === 'object' && typeof obj2 === 'object') {
|
||||
function checkKeys(o1, o2) {
|
||||
for (var i in o1)
|
||||
if (o1.hasOwnProperty(i) && typeof o2[i] === 'undefined')
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (!checkKeys(obj1, obj2) || !checkKeys(obj2, obj1))
|
||||
return false;
|
||||
for (var i in obj1) {
|
||||
|
|
|
@ -1131,6 +1131,15 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* hit.
|
||||
*/
|
||||
hitTest: function(point, options) {
|
||||
function checkBounds(type, part) {
|
||||
var pt = bounds['get' + part]();
|
||||
// TODO: We need to transform the point back to the coordinate
|
||||
// system of the DOM level on which the inquiry was started!
|
||||
if (point.getDistance(pt) < options.tolerance)
|
||||
return new HitResult(type, that,
|
||||
{ name: Base.hyphenate(part), point: pt });
|
||||
}
|
||||
|
||||
point = Point.read(arguments);
|
||||
options = HitResult.getOptions(Base.read(arguments));
|
||||
// Check if the point is withing roughBounds + tolerance, but only if
|
||||
|
@ -1153,14 +1162,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
points = ['TopLeft', 'TopRight', 'BottomLeft', 'BottomRight',
|
||||
'LeftCenter', 'TopCenter', 'RightCenter', 'BottomCenter'],
|
||||
res;
|
||||
function checkBounds(type, part) {
|
||||
var pt = bounds['get' + part]();
|
||||
// TODO: We need to transform the point back to the coordinate
|
||||
// system of the DOM level on which the inquiry was started!
|
||||
if (point.getDistance(pt) < options.tolerance)
|
||||
return new HitResult(type, that,
|
||||
{ name: Base.hyphenate(part), point: pt });
|
||||
}
|
||||
if (options.center && (res = checkBounds('center', 'Center')))
|
||||
return res;
|
||||
if (options.bounds) {
|
||||
|
|
|
@ -1442,6 +1442,20 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
// performance.
|
||||
|
||||
function drawHandles(ctx, segments, matrix) {
|
||||
function drawHandle(index) {
|
||||
var hX = coords[index],
|
||||
hY = coords[index + 1];
|
||||
if (pX != hX || pY != hY) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(pX, pY);
|
||||
ctx.lineTo(hX, hY);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(hX, hY, 1.75, 0, Math.PI * 2, true);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
var coords = new Array(6);
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
var segment = segments[i];
|
||||
|
@ -1450,21 +1464,6 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
selected = state & /*#=*/ SelectionState.POINT,
|
||||
pX = coords[0],
|
||||
pY = coords[1];
|
||||
|
||||
function drawHandle(index) {
|
||||
var hX = coords[index],
|
||||
hY = coords[index + 1];
|
||||
if (pX != hX || pY != hY) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(pX, pY);
|
||||
ctx.lineTo(hX, hY);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(hX, hY, 1.75, 0, Math.PI * 2, true);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
if (selected || (state & /*#=*/ SelectionState.HANDLE_IN))
|
||||
drawHandle(2);
|
||||
if (selected || (state & /*#=*/ SelectionState.HANDLE_OUT))
|
||||
|
|
|
@ -265,6 +265,34 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
*/
|
||||
|
||||
draw: function(ctx, matrix) {
|
||||
// Create a local lookup table for hierarchically concatenated matrices
|
||||
// by item id, to speed up drawing by eliminating repeated concatenation
|
||||
// of parent's matrices through caching.
|
||||
var matrices = {};
|
||||
// Description of the paramters to getGlobalMatrix():
|
||||
// mx is the container for the final concatenated matrix, passed to
|
||||
// getGlobalMatrix() on the initial call.
|
||||
// cached defines wether the result of the concatenation should be
|
||||
// cached, only used for parents of items that this is called for.
|
||||
function getGlobalMatrix(item, mx, cached) {
|
||||
var cache = cached && matrices[item._id];
|
||||
// Found a cached version? Return a clone of it.
|
||||
if (cache)
|
||||
return cache.clone();
|
||||
// Get concatenated matrix from all the parents, using
|
||||
// local caching (passing true for cached):
|
||||
if (item._parent)
|
||||
mx = getGlobalMatrix(item._parent, mx, true);
|
||||
// No need to concatenate if it's the identity matrix
|
||||
if (!item._matrix.isIdentity())
|
||||
mx.concatenate(item._matrix);
|
||||
// If the result needs to be cached, create a copy since matrix
|
||||
// might be further modified through recursive calls
|
||||
if (cached)
|
||||
matrices[item._id] = mx.clone();
|
||||
return mx;
|
||||
}
|
||||
|
||||
this._drawCount++;
|
||||
ctx.save();
|
||||
if (!matrix.isIdentity())
|
||||
|
@ -280,33 +308,6 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
ctx.strokeWidth = 1;
|
||||
// TODO: use Layer#color
|
||||
ctx.strokeStyle = ctx.fillStyle = '#009dec';
|
||||
// Create a local lookup table for hierarchically concatenated
|
||||
// matrices by item id, to speed up drawing by eliminating repeated
|
||||
// concatenation of parent's matrices through caching.
|
||||
var matrices = {};
|
||||
// Description of the paramters to getGlobalMatrix():
|
||||
// mx is the container for the final concatenated matrix, passed
|
||||
// to getGlobalMatrix() on the initial call.
|
||||
// cached defines wether the result of the concatenation should be
|
||||
// cached, only used for parents of items that this is called for.
|
||||
function getGlobalMatrix(item, mx, cached) {
|
||||
var cache = cached && matrices[item._id];
|
||||
// Found a cached version? Return a clone of it.
|
||||
if (cache)
|
||||
return cache.clone();
|
||||
// Get concatenated matrix from all the parents, using
|
||||
// local caching (passing true for cached):
|
||||
if (item._parent)
|
||||
mx = getGlobalMatrix(item._parent, mx, true);
|
||||
// No need to concatenate if it's the identity matrix
|
||||
if (!item._matrix.isIdentity())
|
||||
mx.concatenate(item._matrix);
|
||||
// If the result needs to be cached, create a copy since matrix
|
||||
// might be further modified through recursive calls
|
||||
if (cached)
|
||||
matrices[item._id] = mx.clone();
|
||||
return mx;
|
||||
}
|
||||
for (var id in this._selectedItems) {
|
||||
var item = this._selectedItems[id];
|
||||
if (item._drawCount === this._drawCount)
|
||||
|
|
Loading…
Reference in a new issue