mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Merge master
This commit is contained in:
commit
87ded4dcff
121 changed files with 1047 additions and 980 deletions
|
@ -1,6 +1,6 @@
|
|||
## Authors
|
||||
|
||||
- Juerg Lehni <juerg@lehni.org>
|
||||
- Juerg Lehni <juerg@scratchdisk.com>
|
||||
- Jonathan Puckey <jonathan@studiomoniker.com>
|
||||
|
||||
## Contributors
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
http://lehni.org/ & http://jonathanpuckey.com/
|
||||
Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
44
README.md
44
README.md
|
@ -14,7 +14,11 @@ You can download prebuilt packages from <http://paperjs.org/download/>.
|
|||
|
||||
As of July 2013, the recommended way to install and maintain Paper.js is through Bower for browsers, and through NPM for Node.js.
|
||||
|
||||
See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX.
|
||||
For OSX see <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower.
|
||||
|
||||
For Linux see <http://nodejs.org/download/> to locate 32-bit and 64-bit nodejs binaries as well as sources. It is recommended that you download directly from the nodejs site; the version available via many OS-supplied package managers is out-of-date and doesn't work with many of the packages paper uses. NPM is now included with the nodejs distribution. Once nodejs (with npm) has been installed you can install bower using the following command:
|
||||
|
||||
npm install -g bower
|
||||
|
||||
With Bower installed, simply type this command in your project folder:
|
||||
|
||||
|
@ -22,18 +26,16 @@ With Bower installed, simply type this command in your project folder:
|
|||
|
||||
Upon execution, you will find a `paper` folder inside the project's `component` folder. For more information on Bower and to learn about its features for dependence tracking, see <http://bower.io/>.
|
||||
|
||||
## Installing for Node.js
|
||||
## Installing Paper.js for Node.js through NPM
|
||||
|
||||
Similarly you can use NPM to install Paper.js for Node.js. But before doing so, you need the Cairo Graphics library installed, see <http://cairographics.org/>.
|
||||
You can also use NPM to install Paper.js for Node.js. But before doing so, you need the Cairo Graphics library installed, see <http://cairographics.org/>.
|
||||
|
||||
The easiest way to install Cairo on OSX is through Homebrew <http://mxcl.github.io/homebrew/>.
|
||||
**Installing Cairo on OSX:**
|
||||
|
||||
The easiest way to install Cairo is install Homebrew <http://mxcl.github.io/homebrew/> then issue the command:
|
||||
|
||||
brew install cairo
|
||||
|
||||
Once Homebrew has installed this for you, you can then install the Paper.js module:
|
||||
|
||||
npm install paper
|
||||
|
||||
Note that currently there is an issue on OSX with Cairo. If the above causes errors, the following will most likely fix it:
|
||||
|
||||
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm install paper
|
||||
|
@ -42,6 +44,20 @@ Also, whenever you would like to update the modules, you will need to execute:
|
|||
|
||||
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm update
|
||||
|
||||
**Installing Cairo on Debian/Ubuntu Linux:**
|
||||
|
||||
sudo apt-get install libcairo2-dev
|
||||
|
||||
You might also need these additional packages if you don't usually build from c++ sources:
|
||||
|
||||
sudo apt-get install build-essential libssl-dev libjpeg8-dev libgif-dev
|
||||
|
||||
**Ater Cairo has been installed:**
|
||||
|
||||
You should now be able to install the Paper.js module from NPM:
|
||||
|
||||
npm install paper
|
||||
|
||||
## Development
|
||||
|
||||
**Get the source (for building):**
|
||||
|
@ -53,11 +69,12 @@ Also, whenever you would like to update the modules, you will need to execute:
|
|||
If you want to contribute to the project you will have to [make a fork](http://help.github.com/forking/). Then do this:
|
||||
|
||||
git clone --recursive git@github.com:yourusername/paper.js.git
|
||||
cd paper.js
|
||||
git remote add upstream git://github.com/paperjs/paper.js.git
|
||||
|
||||
### Refreshing Your Clone
|
||||
|
||||
To fetch changes from origin, run
|
||||
To fetch changes from origin (your fork), run
|
||||
|
||||
git fetch origin
|
||||
|
||||
|
@ -73,11 +90,15 @@ To update the `jsdoc-toolkit` submodule inside the `build` folder, used to gener
|
|||
|
||||
Paper.js has a couple of dependencies as Bower and NPM modules. See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX.
|
||||
|
||||
In order to be able to build Paper.js, these dependencies need to be installed first after checking out the repository:
|
||||
In order to be able to build Paper.js, after checking out the repository, paper has dependencies that need to be installed. Install them by issuing the following commands from the paper.js directory:
|
||||
|
||||
npm install
|
||||
bower install
|
||||
|
||||
You might find that the npm command fails attempting to fetch packages needed for dependencies due to using https (the default protocol to access the npm registry). If that is the case you can switch to using http for registry access with the following command:
|
||||
|
||||
npm config set registry http://registry.npmjs.org/
|
||||
|
||||
Next you need to create minified versions of some of these dependencies. This is handled by the `minify-components.sh` script inside the `build` folder:
|
||||
|
||||
cd build
|
||||
|
@ -145,7 +166,8 @@ As mentioned earlier in this article, we prefer that you send a [*pull request*]
|
|||
|
||||
3. This is important: Create a so-called *topic branch*: `git checkout -tb name-of-my-patch` where "name-of-my-patch" is a short but descriptive name of the patch you're about to create. Don't worry about the perfect name though -- you can change this name at any time later on.
|
||||
|
||||
4. Hack! Make your changes, additions, etc and commit them.
|
||||
4. Hack! Make your changes, additions, etc., commit them then push them to your github fork: `git push origin name-of-my-patch`
|
||||
|
||||
|
||||
5. Send a pull request to the upstream repository's owner by visiting your repository's site at github (i.e. https://github.com/yourusername/paper.js) and press the "Pull Request" button. Here's a good guide on pull requests: <http://help.github.com/pull-requests/>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"test"
|
||||
],
|
||||
"devDependencies": {
|
||||
"straps": "~1.4.1",
|
||||
"straps": "~1.4.3",
|
||||
"acorn": "git://github.com/paperjs/acorn#0.3.2",
|
||||
"esprima": "~1.0.3",
|
||||
"stats.js": "r11"
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
# http://paperjs.org/
|
||||
#
|
||||
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
# http://lehni.org/ & http://jonathanpuckey.com/
|
||||
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
# http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
#
|
||||
# Distributed under the MIT license. See LICENSE file for details.
|
||||
#
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require('paper');
|
||||
var paper = require('./Tadpoles.pjs');
|
||||
var paper = require('paper');
|
||||
var scope = require('./Tadpoles.pjs')(new paper.Size(1024, 768));
|
||||
|
||||
paper.view.exportFrames({
|
||||
scope.view.exportFrames({
|
||||
amount: 400,
|
||||
directory: __dirname,
|
||||
onComplete: function() {
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
paper.setup(new Canvas(1024, 768));
|
||||
|
||||
// Adapted from Flocking Processing example by Daniel Schiffman:
|
||||
// http://processing.org/learning/topics/flocking.html
|
||||
|
||||
|
|
|
@ -89,12 +89,11 @@
|
|||
|
||||
function onMouseDrag(event) {
|
||||
if (segment) {
|
||||
segment.point = event.point;
|
||||
segment.point += event.delta;
|
||||
path.smooth();
|
||||
}
|
||||
|
||||
if (movePath)
|
||||
} else if (path) {
|
||||
path.position += event.delta;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
@ -6,92 +6,74 @@
|
|||
<link rel="stylesheet" href="../css/style.css">
|
||||
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||||
<script type="text/paperscript" canvas="canvas">
|
||||
var y = view.size.height / 2;
|
||||
var width = view.size.width;
|
||||
var vector = new Point({
|
||||
angle: 45,
|
||||
length: width / 5
|
||||
});
|
||||
var offset = width / 30;
|
||||
var handleTexts = [];
|
||||
var path = new Path({
|
||||
segments: [
|
||||
[[offset, y], null, vector.rotate(-90)],
|
||||
[[width / 2, y], vector.rotate(-180), vector],
|
||||
[[width - offset, y], vector.rotate(90), null]
|
||||
],
|
||||
fullySelected: true
|
||||
});
|
||||
|
||||
var segmentTexts = new Layer();
|
||||
for (var i = 0; i < 3; i++) {
|
||||
new PointText({
|
||||
content: i,
|
||||
justification: 'center',
|
||||
fontSize: 12
|
||||
});
|
||||
}
|
||||
|
||||
var handleTexts = new Layer();
|
||||
for (var i = 0; i < 2; i++) {
|
||||
new PointText({
|
||||
content: 'handleIn',
|
||||
justification: 'center',
|
||||
fontSize: 12
|
||||
});
|
||||
|
||||
new PointText({
|
||||
content: 'handleOut',
|
||||
justification: 'center',
|
||||
fontSize: 12
|
||||
});
|
||||
}
|
||||
|
||||
function onResize() {
|
||||
var width = view.size.width;
|
||||
var offset = width / 30;
|
||||
var vector = new Point({
|
||||
angle: 45,
|
||||
length: width / 5
|
||||
});
|
||||
var yMiddle = view.size.height / 2;
|
||||
path.segments = [
|
||||
{
|
||||
point: [offset, yMiddle],
|
||||
handleIn: null,
|
||||
handleOut: vector.rotate(-90)
|
||||
},
|
||||
{
|
||||
point: [width / 2, yMiddle],
|
||||
handleIn: vector.rotate(-180),
|
||||
handleOut: vector
|
||||
},
|
||||
{
|
||||
point: [width - offset, yMiddle],
|
||||
handleIn: vector.rotate(90),
|
||||
handleOut: null
|
||||
}
|
||||
];
|
||||
|
||||
for (var i = 0; i < path.segments.length; i++) {
|
||||
var point = path.segments[i].point;
|
||||
segmentTexts.children[i].point = point - [0, 10];
|
||||
}
|
||||
|
||||
onMouseMove({
|
||||
point: view.bounds.bottomRight
|
||||
});
|
||||
}
|
||||
|
||||
function onMouseMove(event) {
|
||||
var point = event.point.clone();
|
||||
// Constrain the event point, to not cut off the text:
|
||||
if (point.y < 22) {
|
||||
if (point.y < 22)
|
||||
point.y = 22;
|
||||
}
|
||||
if (point.y > view.size.height - 24) {
|
||||
if (point.y > view.size.height - 24)
|
||||
point.y = view.size.height - 24;
|
||||
}
|
||||
var delta = point - view.center;
|
||||
|
||||
for (var i = 0; i < path.curves.length; i++) {
|
||||
var delta = point - view.center;
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var curve = path.curves[i];
|
||||
curve.handle1.y = curve.handle2.y = delta.y * (i % 2 ? 1 : -1);
|
||||
var firstPoint = curve.point1 + curve.handle1;
|
||||
var secondPoint = curve.point2 + curve.handle2;
|
||||
var yMiddle = view.size.height / 2;
|
||||
var offset = (firstPoint.y < yMiddle ? [0, 10] : [0, -18]);
|
||||
handleTexts.children[i * 2].point = secondPoint - offset;
|
||||
handleTexts.children[i * 2 + 1].point = firstPoint - offset;
|
||||
handleTexts[i * 2].point = secondPoint -
|
||||
(firstPoint.y < y ? [0, 10] : [0, -18]);
|
||||
handleTexts[i * 2 + 1].point = firstPoint -
|
||||
(firstPoint.y < y ? [0, 10] : [0, -18]);
|
||||
}
|
||||
}
|
||||
|
||||
project.currentStyle.fillColor = 'black';
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var segment = path.segments[i];
|
||||
var text = new PointText({
|
||||
point: segment.point - [0, 10],
|
||||
content: i,
|
||||
fontSize: 12,
|
||||
justification: 'center'
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var handleInText = new PointText({
|
||||
content: 'handleIn',
|
||||
fontSize: 12,
|
||||
justification: 'center'
|
||||
});
|
||||
handleTexts.push(handleInText);
|
||||
|
||||
var handleOutText = new PointText({
|
||||
content: 'handleOut',
|
||||
fontSize: 12,
|
||||
justification: 'center'
|
||||
});
|
||||
handleTexts.push(handleOutText);
|
||||
}
|
||||
|
||||
// Call onMouseMove once to correctly position the text items:
|
||||
onMouseMove({
|
||||
point: view.center + vector.rotate(-90)
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Resize</title>
|
||||
<title>Shapes</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||||
<script type="text/paperscript" canvas="canvas">
|
||||
|
@ -60,4 +60,4 @@
|
|||
<body>
|
||||
<canvas id="canvas" resize></canvas>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
5
node_modules/.gitignore
generated
vendored
5
node_modules/.gitignore
generated
vendored
|
@ -1,7 +1,8 @@
|
|||
.bin
|
||||
canvas
|
||||
grunt*
|
||||
jsdoc
|
||||
jsdom
|
||||
prepro
|
||||
request
|
||||
uglify-js
|
||||
prepro
|
||||
grunt*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"homepage": "http://paperjs.org",
|
||||
"repository": "git://github.com/paperjs/paper.js",
|
||||
"contributors": [
|
||||
"Jürg Lehni <juerg@lehni.org> (http://lehni.org)",
|
||||
"Jürg Lehni <juerg@scratchdisk.com> (http://scratchdisk.com)",
|
||||
"Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"
|
||||
],
|
||||
"main": "./dist/paper-node.js",
|
||||
|
@ -26,7 +26,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"uglify-js": "~2.3.6",
|
||||
"prepro": "~0.8.0",
|
||||
"prepro": "~0.8.1",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-contrib-uglify": "~0.2.2"
|
||||
},
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -140,10 +140,11 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
* "Resets" the matrix by setting its values to the ones of the identity
|
||||
* matrix that results in no transformation.
|
||||
*/
|
||||
reset: function() {
|
||||
reset: function(_dontNotify) {
|
||||
this._a = this._d = 1;
|
||||
this._c = this._b = this._tx = this._ty = 0;
|
||||
this._changed();
|
||||
if (!_dontNotify)
|
||||
this._changed();
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -197,7 +198,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
// Do not modify scale, center, since that would arguments of which
|
||||
// we're reading from!
|
||||
var scale = Point.read(arguments),
|
||||
center = Point.read(arguments, 0, 0, { readNull: true });
|
||||
center = Point.read(arguments, 0, { readNull: true });
|
||||
if (center)
|
||||
this.translate(center);
|
||||
this._a *= scale.x;
|
||||
|
@ -231,11 +232,11 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
* @param {Number} y the y coordinate of the anchor point
|
||||
* @return {Matrix} this affine transform
|
||||
*/
|
||||
rotate: function(angle, center) {
|
||||
center = Point.read(arguments, 1);
|
||||
rotate: function(angle /*, center */) {
|
||||
angle *= Math.PI / 180;
|
||||
// Concatenate rotation matrix into this one
|
||||
var x = center.x,
|
||||
var center = Point.read(arguments, 1),
|
||||
// Concatenate rotation matrix into this one
|
||||
x = center.x,
|
||||
y = center.y,
|
||||
cos = Math.cos(angle),
|
||||
sin = Math.sin(angle),
|
||||
|
@ -278,7 +279,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
// Do not modify point, center, since that would arguments of which
|
||||
// we're reading from!
|
||||
var shear = Point.read(arguments),
|
||||
center = Point.read(arguments, 0, 0, { readNull: true });
|
||||
center = Point.read(arguments, 0, { readNull: true });
|
||||
if (center)
|
||||
this.translate(center);
|
||||
var a = this._a,
|
||||
|
@ -314,7 +315,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{
|
|||
*/
|
||||
skew: function(/* skew, center */) {
|
||||
var skew = Point.read(arguments),
|
||||
center = Point.read(arguments, 0, 0, { readNull: true }),
|
||||
center = Point.read(arguments, 0, { readNull: true }),
|
||||
toRadians = Math.PI / 180,
|
||||
shear = new Point(Math.tan(skew.x * toRadians),
|
||||
Math.tan(skew.y * toRadians));
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -270,8 +270,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* var result = point1 + point2;
|
||||
* console.log(result); // {x: 15, y: 30}
|
||||
*/
|
||||
add: function(point) {
|
||||
point = Point.read(arguments);
|
||||
add: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return new Point(this.x + point.x, this.y + point.y);
|
||||
},
|
||||
|
||||
|
@ -308,8 +308,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* var result = firstPoint - secondPoint;
|
||||
* console.log(result); // {x: 5, y: 15}
|
||||
*/
|
||||
subtract: function(point) {
|
||||
point = Point.read(arguments);
|
||||
subtract: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return new Point(this.x - point.x, this.y - point.y);
|
||||
},
|
||||
|
||||
|
@ -346,8 +346,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* var result = firstPoint * secondPoint;
|
||||
* console.log(result); // {x: 20, y: 20}
|
||||
*/
|
||||
multiply: function(point) {
|
||||
point = Point.read(arguments);
|
||||
multiply: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return new Point(this.x * point.x, this.y * point.y);
|
||||
},
|
||||
|
||||
|
@ -384,8 +384,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* var result = firstPoint / secondPoint;
|
||||
* console.log(result); // {x: 4, y: 2}
|
||||
*/
|
||||
divide: function(point) {
|
||||
point = Point.read(arguments);
|
||||
divide: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return new Point(this.x / point.x, this.y / point.y);
|
||||
},
|
||||
|
||||
|
@ -419,8 +419,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* var point = new Point(12, 6);
|
||||
* console.log(point % new Point(5, 2)); // {x: 2, y: 0}
|
||||
*/
|
||||
modulo: function(point) {
|
||||
point = Point.read(arguments);
|
||||
modulo: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return new Point(this.x % point.x, this.y % point.y);
|
||||
},
|
||||
|
||||
|
@ -449,11 +449,17 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* remain squared, or its square root should be calculated.
|
||||
* @return {Number}
|
||||
*/
|
||||
getDistance: function(point, squared) {
|
||||
point = Point.read(arguments);
|
||||
var x = point.x - this.x,
|
||||
getDistance: function(_point, squared) {
|
||||
// NOTE: Although we're reading from the argument list, we need the
|
||||
// above arguments to prevent beans from being created (Strap.js issue).
|
||||
// And for browser optimization we shouldn't re-asign an object to it,
|
||||
// but we need to prevent the minifier from removing it again, so:
|
||||
var point = Point.read(arguments),
|
||||
x = point.x - this.x,
|
||||
y = point.y - this.y,
|
||||
d = x * x + y * y;
|
||||
// Reassigning boolean values to arguments is apparently OK.
|
||||
squared = Base.read(arguments);
|
||||
return squared ? d : Math.sqrt(d);
|
||||
},
|
||||
|
||||
|
@ -467,11 +473,7 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @bean
|
||||
*/
|
||||
getLength: function() {
|
||||
// Supports a hidden parameter 'squared', which controls whether the
|
||||
// squared length should be returned. Hide it so it produces a bean
|
||||
// property called #length.
|
||||
var length = this.x * this.x + this.y * this.y;
|
||||
return arguments.length && arguments[0] ? length : Math.sqrt(length);
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
},
|
||||
|
||||
setLength: function(length) {
|
||||
|
@ -494,7 +496,6 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
this.y * scale
|
||||
);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -536,28 +537,16 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @type Number
|
||||
*/
|
||||
getAngle: function(/* point */) {
|
||||
// Hide parameters from Bootstrap so it injects bean too
|
||||
return this.getAngleInRadians(arguments[0]) * 180 / Math.PI;
|
||||
return this.getAngleInRadians.apply(this, arguments) * 180 / Math.PI;
|
||||
},
|
||||
|
||||
setAngle: function(angle) {
|
||||
// We store a reference to _angle internally so we still preserve it
|
||||
// when the vector's length is set to zero, and then anything else.
|
||||
// Note that we cannot rely on it if x and y are something else than 0,
|
||||
// since updating x / y does not automatically change _angle!
|
||||
angle = this._angle = angle * Math.PI / 180;
|
||||
if (!this.isZero()) {
|
||||
var length = this.getLength();
|
||||
// Use #set() instead of direct assignment of x/y, so LinkedPoint
|
||||
// does not report changes twice.
|
||||
this.set(
|
||||
Math.cos(angle) * length,
|
||||
Math.sin(angle) * length
|
||||
);
|
||||
}
|
||||
return this;
|
||||
this.setAngleInRadians.call(this, angle * Math.PI / 180);
|
||||
},
|
||||
|
||||
getAngleInDegrees: '#getAngle',
|
||||
setAngleInDegrees: '#setAngle',
|
||||
|
||||
/**
|
||||
* Returns the smaller angle between two vectors in radians. The angle is
|
||||
* unsigned, no information about rotational direction is given.
|
||||
|
@ -575,8 +564,7 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @type Number
|
||||
*/
|
||||
getAngleInRadians: function(/* point */) {
|
||||
// Hide parameters from Bootstrap so it injects bean too
|
||||
if (arguments[0] === undefined) {
|
||||
if (!arguments.length) {
|
||||
return this.isZero()
|
||||
// Return the preseved angle in case the vector has no
|
||||
// length, and update the internal _angle in case the
|
||||
|
@ -595,8 +583,21 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
}
|
||||
},
|
||||
|
||||
getAngleInDegrees: function(/* point */) {
|
||||
return this.getAngle(arguments[0]);
|
||||
setAngleInRadians: function(angle) {
|
||||
// We store a reference to _angle internally so we still preserve it
|
||||
// when the vector's length is set to zero, and then anything else.
|
||||
// Note that we cannot rely on it if x and y are something else than 0,
|
||||
// since updating x / y does not automatically change _angle!
|
||||
this._angle = angle;
|
||||
if (!this.isZero()) {
|
||||
var length = this.getLength();
|
||||
// Use #set() instead of direct assignment of x/y, so LinkedPoint
|
||||
// does not report changes twice.
|
||||
this.set(
|
||||
Math.cos(angle) * length,
|
||||
Math.sin(angle) * length
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -640,7 +641,12 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @param {Point} point
|
||||
* @return {Number} the angle between the two vectors
|
||||
*/
|
||||
getDirectedAngle: function(point) {
|
||||
getDirectedAngle: function(_point) {
|
||||
// NOTE: Although we're reading from the argument list, we need the
|
||||
// above arguments to prevent beans from being created (Strap.js issue).
|
||||
// And for browser optimization we shouldn't re-asign an object to it,
|
||||
// but we need to prevent the minifier from removing it again, so:
|
||||
var point = _point;
|
||||
point = Point.read(arguments);
|
||||
return Math.atan2(this.cross(point), this.dot(point)) * 180 / Math.PI;
|
||||
},
|
||||
|
@ -741,8 +747,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @param {Point} point
|
||||
* @returns {Number} the dot product of the two points
|
||||
*/
|
||||
dot: function(point) {
|
||||
point = Point.read(arguments);
|
||||
dot: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return this.x * point.x + this.y * point.y;
|
||||
},
|
||||
|
||||
|
@ -752,8 +758,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @param {Point} point
|
||||
* @returns {Number} the cross product of the two points
|
||||
*/
|
||||
cross: function(point) {
|
||||
point = Point.read(arguments);
|
||||
cross: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
return this.x * point.y - this.y * point.x;
|
||||
},
|
||||
|
||||
|
@ -764,8 +770,8 @@ var Point = Base.extend(/** @lends Point# */{
|
|||
* @param {Point} point
|
||||
* @returns {Point} the projection of the point on another point
|
||||
*/
|
||||
project: function(point) {
|
||||
point = Point.read(arguments);
|
||||
project: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
if (point.isZero()) {
|
||||
return new Point(0, 0);
|
||||
} else {
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -141,7 +141,7 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
this.width = size.width;
|
||||
this.height = size.height;
|
||||
}
|
||||
read = arguments._index;
|
||||
read = arguments.__index;
|
||||
}
|
||||
if (this.__read)
|
||||
this.__read = read;
|
||||
|
@ -201,11 +201,12 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @return {Boolean} {@true if the rectangles are equal}
|
||||
*/
|
||||
equals: function(rect) {
|
||||
if (Base.isPlainValue(rect))
|
||||
rect = Rectangle.read(arguments);
|
||||
return rect === this
|
||||
|| rect && this.x === rect.x && this.y === rect.y
|
||||
&& this.width === rect.width && this.height === rect.height
|
||||
var rt = Base.isPlainValue(rect)
|
||||
? Rectangle.read(arguments)
|
||||
: rect;
|
||||
return rt === this
|
||||
|| rt && this.x === rt.x && this.y === rt.y
|
||||
&& this.width === rt.width && this.height === rt.height
|
||||
|| false;
|
||||
},
|
||||
|
||||
|
@ -236,13 +237,13 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @type Point
|
||||
* @bean
|
||||
*/
|
||||
getPoint: function(/* dontLink */) {
|
||||
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||
getPoint: function(_dontLink) {
|
||||
var ctor = _dontLink ? Point : LinkedPoint;
|
||||
return new ctor(this.x, this.y, this, 'setPoint');
|
||||
},
|
||||
|
||||
setPoint: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setPoint: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this.x = point.x;
|
||||
this.y = point.y;
|
||||
},
|
||||
|
@ -254,13 +255,13 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @type Size
|
||||
* @bean
|
||||
*/
|
||||
getSize: function(/* dontLink */) {
|
||||
var ctor = arguments[0] ? Size : LinkedSize;
|
||||
getSize: function(_dontLink) {
|
||||
var ctor = _dontLink ? Size : LinkedSize;
|
||||
return new ctor(this.width, this.height, this, 'setSize');
|
||||
},
|
||||
|
||||
setSize: function(size) {
|
||||
size = Size.read(arguments);
|
||||
setSize: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
// Keep track of how dimensions were specified through this._fix*
|
||||
// attributes.
|
||||
// _fixX / Y can either be 0 (l), 0.5 (center) or 1 (r), and is used as
|
||||
|
@ -400,13 +401,13 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @type Point
|
||||
* @bean
|
||||
*/
|
||||
getCenter: function(/* dontLink */) {
|
||||
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||
getCenter: function(_dontLink) {
|
||||
var ctor = _dontLink ? Point : LinkedPoint;
|
||||
return new ctor(this.getCenterX(), this.getCenterY(), this, 'setCenter');
|
||||
},
|
||||
|
||||
setCenter: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setCenter: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this.setCenterX(point.x);
|
||||
this.setCenterY(point.y);
|
||||
// A special setter where we allow chaining, because it comes in handy
|
||||
|
@ -633,16 +634,16 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* }
|
||||
* }
|
||||
*/
|
||||
intersects: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
intersects: function(/* rect */) {
|
||||
var rect = Rectangle.read(arguments);
|
||||
return rect.x + rect.width > this.x
|
||||
&& rect.y + rect.height > this.y
|
||||
&& rect.x < this.x + this.width
|
||||
&& rect.y < this.y + this.height;
|
||||
},
|
||||
|
||||
touches: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
touches: function(/* rect */) {
|
||||
var rect = Rectangle.read(arguments);
|
||||
return rect.x + rect.width >= this.x
|
||||
&& rect.y + rect.height >= this.y
|
||||
&& rect.x <= this.x + this.width
|
||||
|
@ -690,9 +691,9 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* var intersectionPath = new Path.Rectangle(intersected);
|
||||
* intersectionPath.fillColor = 'red';
|
||||
*/
|
||||
intersect: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var x1 = Math.max(this.x, rect.x),
|
||||
intersect: function(/* rect */) {
|
||||
var rect = Rectangle.read(arguments),
|
||||
x1 = Math.max(this.x, rect.x),
|
||||
y1 = Math.max(this.y, rect.y),
|
||||
x2 = Math.min(this.x + this.width, rect.x + rect.width),
|
||||
y2 = Math.min(this.y + this.height, rect.y + rect.height);
|
||||
|
@ -707,9 +708,9 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
* @return {Rectangle} the smallest rectangle containing both the specified
|
||||
* rectangle and this rectangle.
|
||||
*/
|
||||
unite: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var x1 = Math.min(this.x, rect.x),
|
||||
unite: function(/* rect */) {
|
||||
var rect = Rectangle.read(arguments),
|
||||
x1 = Math.min(this.x, rect.x),
|
||||
y1 = Math.min(this.y, rect.y),
|
||||
x2 = Math.max(this.x + this.width, rect.x + rect.width),
|
||||
y2 = Math.max(this.y + this.height, rect.y + rect.height);
|
||||
|
@ -730,8 +731,8 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
*
|
||||
* @param {Point} point
|
||||
*/
|
||||
include: function(point) {
|
||||
point = Point.read(arguments);
|
||||
include: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
var x1 = Math.min(this.x, point.x),
|
||||
y1 = Math.min(this.y, point.y),
|
||||
x2 = Math.max(this.x + this.width, point.x),
|
||||
|
@ -811,12 +812,12 @@ var Rectangle = Base.extend(/** @lends Rectangle# */{
|
|||
setY = 'set' + y,
|
||||
get = 'get' + part,
|
||||
set = 'set' + part;
|
||||
this[get] = function(/* dontLink */) {
|
||||
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||
this[get] = function(_dontLink) {
|
||||
var ctor = _dontLink ? Point : LinkedPoint;
|
||||
return new ctor(this[getX](), this[getY](), this, set);
|
||||
};
|
||||
this[set] = function(point) {
|
||||
point = Point.read(arguments);
|
||||
this[set] = function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this[setX](point.x);
|
||||
this[setY](point.y);
|
||||
};
|
||||
|
@ -880,7 +881,7 @@ var LinkedRectangle = Rectangle.extend({
|
|||
// afterwards here, only once per change.
|
||||
this._dontNotify = true;
|
||||
proto[name].apply(this, arguments);
|
||||
delete this._dontNotify;
|
||||
this._dontNotify = false;
|
||||
this._owner[this._setter](this);
|
||||
};
|
||||
}, /** @lends Rectangle# */{
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -218,8 +218,8 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
* var result = size1 + size2;
|
||||
* console.log(result); // {width: 15, height: 30}
|
||||
*/
|
||||
add: function(size) {
|
||||
size = Size.read(arguments);
|
||||
add: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
return new Size(this.width + size.width, this.height + size.height);
|
||||
},
|
||||
|
||||
|
@ -255,8 +255,8 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
* var result = firstSize - secondSize;
|
||||
* console.log(result); // {width: 5, height: 15}
|
||||
*/
|
||||
subtract: function(size) {
|
||||
size = Size.read(arguments);
|
||||
subtract: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
return new Size(this.width - size.width, this.height - size.height);
|
||||
},
|
||||
|
||||
|
@ -291,8 +291,8 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
* var result = firstSize * secondSize;
|
||||
* console.log(result); // {width: 20, height: 20}
|
||||
*/
|
||||
multiply: function(size) {
|
||||
size = Size.read(arguments);
|
||||
multiply: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
return new Size(this.width * size.width, this.height * size.height);
|
||||
},
|
||||
|
||||
|
@ -327,8 +327,8 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
* var result = firstSize / secondSize;
|
||||
* console.log(result); // {width: 4, height: 2}
|
||||
*/
|
||||
divide: function(size) {
|
||||
size = Size.read(arguments);
|
||||
divide: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
return new Size(this.width / size.width, this.height / size.height);
|
||||
},
|
||||
|
||||
|
@ -362,8 +362,8 @@ var Size = Base.extend(/** @lends Size# */{
|
|||
* var size = new Size(12, 6);
|
||||
* console.log(size % new Size(5, 2)); // {width: 2, height: 0}
|
||||
*/
|
||||
modulo: function(size) {
|
||||
size = Size.read(arguments);
|
||||
modulo: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
return new Size(this.width % size.width, this.height % size.height);
|
||||
},
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -15,8 +15,7 @@
|
|||
* @class
|
||||
* @private
|
||||
*/
|
||||
// Extend Base with utility functions used across the library. Also set
|
||||
// this.Base on the injection scope, since straps.js ommits that.
|
||||
// Extend Base with utility functions used across the library.
|
||||
Base.inject(/** @lends Base# */{
|
||||
/**
|
||||
* Renders base objects to strings in object literal notation.
|
||||
|
@ -40,7 +39,7 @@ Base.inject(/** @lends Base# */{
|
|||
/**
|
||||
* Serializes this object to a JSON string.
|
||||
*
|
||||
* @param {Object} [options={ precision: 5 }]
|
||||
* @param {Object} [options={ asString: true, precision: 5 }]
|
||||
*/
|
||||
exportJSON: function(options) {
|
||||
return Base.exportJSON(this, options);
|
||||
|
@ -156,44 +155,35 @@ Base.inject(/** @lends Base# */{
|
|||
* passed objects should be cloned if they are already provided in the
|
||||
* required type
|
||||
*/
|
||||
read: function(list, start, length, options) {
|
||||
read: function(list, start, options, length) {
|
||||
// See if it's called directly on Base, and if so, read value and
|
||||
// return without object conversion.
|
||||
if (this === Base) {
|
||||
var value = this.peek(list, start);
|
||||
list._index++;
|
||||
list.__read = 1;
|
||||
list.__index++;
|
||||
return value;
|
||||
}
|
||||
var proto = this.prototype,
|
||||
readIndex = proto._readIndex,
|
||||
index = start || readIndex && list._index || 0;
|
||||
index = start || readIndex && list.__index || 0;
|
||||
if (!length)
|
||||
length = list.length - index;
|
||||
var obj = list[index];
|
||||
if (obj instanceof this
|
||||
|| options && options.readNull && obj == null && length <= 1) {
|
||||
if (readIndex)
|
||||
list._index = index + 1;
|
||||
list.__index = index + 1;
|
||||
return obj && options && options.clone ? obj.clone() : obj;
|
||||
}
|
||||
obj = Base.create(this.prototype);
|
||||
if (readIndex)
|
||||
obj.__read = true;
|
||||
// If options were provided, pass them on to the constructed object
|
||||
if (options)
|
||||
obj.__options = options;
|
||||
obj = obj.initialize.apply(obj, index > 0 || length < list.length
|
||||
? Array.prototype.slice.call(list, index, index + length)
|
||||
: list) || obj;
|
||||
if (readIndex) {
|
||||
list._index = index + obj.__read;
|
||||
// Have arguments.__read point to the amount of args read in the
|
||||
// last read() call
|
||||
list.__read = obj.__read;
|
||||
delete obj.__read;
|
||||
if (options)
|
||||
delete obj.__options;
|
||||
list.__index = index + obj.__read;
|
||||
obj.__read = undefined;
|
||||
}
|
||||
return obj;
|
||||
},
|
||||
|
@ -206,12 +196,12 @@ Base.inject(/** @lends Base# */{
|
|||
* @param {Number} start the index at which to start reading in the list
|
||||
*/
|
||||
peek: function(list, start) {
|
||||
return list[list._index = start || list._index || 0];
|
||||
return list[list.__index = start || list.__index || 0];
|
||||
},
|
||||
|
||||
/**
|
||||
* Reads all readable arguments from the list, handling nested arrays
|
||||
* seperately.
|
||||
* separately.
|
||||
* @param {Array} list the list to read from, either an arguments object
|
||||
* or a normal array.
|
||||
* @param {Number} start the index at which to start reading in the list
|
||||
|
@ -221,12 +211,12 @@ Base.inject(/** @lends Base# */{
|
|||
* required type
|
||||
*/
|
||||
readAll: function(list, start, options) {
|
||||
var res = [], entry;
|
||||
var res = [],
|
||||
entry;
|
||||
for (var i = start || 0, l = list.length; i < l; i++) {
|
||||
res.push(Array.isArray(entry = list[i])
|
||||
// lenghh = 0 for length = max
|
||||
? this.read(entry, 0, 0, options)
|
||||
: this.read(list, i, 1, options));
|
||||
? this.read(entry, 0, options)
|
||||
: this.read(list, i, options, 1));
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
@ -242,7 +232,7 @@ Base.inject(/** @lends Base# */{
|
|||
* @param {Number} start the index at which to start reading in the list
|
||||
* @param {String} name the property name to read from.
|
||||
*/
|
||||
readNamed: function(list, name, start, length, options) {
|
||||
readNamed: function(list, name, start, options, length) {
|
||||
var value = this.getNamed(list, name),
|
||||
hasObject = value !== undefined;
|
||||
if (hasObject) {
|
||||
|
@ -259,7 +249,7 @@ Base.inject(/** @lends Base# */{
|
|||
// shine through.
|
||||
filtered[name] = undefined;
|
||||
}
|
||||
return this.read(hasObject ? [value] : list, start, length, options);
|
||||
return this.read(hasObject ? [value] : list, start, options, length);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -433,7 +423,10 @@ Base.inject(/** @lends Base# */{
|
|||
},
|
||||
|
||||
exportJSON: function(obj, options) {
|
||||
return JSON.stringify(Base.serialize(obj, options));
|
||||
var json = Base.serialize(obj, options);
|
||||
return options && options.asString === false
|
||||
? json
|
||||
: JSON.stringify(json);
|
||||
},
|
||||
|
||||
importJSON: function(json, target) {
|
||||
|
@ -491,9 +484,9 @@ Base.inject(/** @lends Base# */{
|
|||
if (items)
|
||||
args.push.apply(args, items);
|
||||
var removed = list.splice.apply(list, args);
|
||||
// Delete the indices of the removed items
|
||||
// Erase the indices of the removed items
|
||||
for (var i = 0, l = removed.length; i < l; i++)
|
||||
delete removed[i]._index;
|
||||
removed[i]._index = undefined;
|
||||
// Adjust the indices of the items above.
|
||||
for (var i = index + amount, l = list.length; i < l; i++)
|
||||
list[i]._index = i;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -77,32 +77,16 @@ var Callback = {
|
|||
if (!handlers)
|
||||
return false;
|
||||
var args = [].slice.call(arguments, 1),
|
||||
PaperScript = paper.PaperScript,
|
||||
handleException = PaperScript && PaperScript.handleException,
|
||||
that = this;
|
||||
|
||||
function callHandlers() {
|
||||
for (var i in handlers) {
|
||||
// When the handler function returns false, prevent the default
|
||||
// behaviour and stop propagation of the event by calling stop()
|
||||
if (handlers[i].apply(that, args) === false
|
||||
&& event && event.stop) {
|
||||
event.stop();
|
||||
break;
|
||||
}
|
||||
for (var i in handlers) {
|
||||
// When the handler function returns false, prevent the default
|
||||
// behaviour and stop propagation of the event by calling stop()
|
||||
if (handlers[i].apply(that, args) === false
|
||||
&& event && event.stop) {
|
||||
event.stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// See PaperScript.handleException for an explanation of the following.
|
||||
// Firefox is to blame for the necessity of this...
|
||||
if (handleException) {
|
||||
try {
|
||||
callHandlers();
|
||||
} catch (e) {
|
||||
handleException(e);
|
||||
}
|
||||
} else {
|
||||
callHandlers();
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -102,16 +102,15 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
|
||||
/**
|
||||
* The reference to the active tool.
|
||||
* @name PaperScope#tool
|
||||
* @type Tool
|
||||
* @bean
|
||||
*/
|
||||
getTool: function() {
|
||||
// If no tool exists yet but one is requested, produce it now on the fly
|
||||
// so it can be used in PaperScript.
|
||||
if (!this._tool)
|
||||
this._tool = new Tool();
|
||||
return this._tool;
|
||||
},
|
||||
|
||||
/**
|
||||
* The list of available tools.
|
||||
* @name PaperScope#tools
|
||||
* @type Tool[]
|
||||
*/
|
||||
|
||||
/**
|
||||
* A reference to the local scope. This is required, so `paper` will always
|
||||
|
@ -125,16 +124,9 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* The list of available tools.
|
||||
* @name PaperScope#tools
|
||||
* @type Tool[]
|
||||
*/
|
||||
|
||||
evaluate: function(code) {
|
||||
var res = paper.PaperScript.evaluate(code, this);
|
||||
execute: function(code) {
|
||||
paper.PaperScript.execute(code, this);
|
||||
View.updateFocus();
|
||||
return res;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -166,10 +158,10 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
// Copy over all fields from this scope to the destination.
|
||||
// Do not use Base.each, since we also want to enumerate over
|
||||
// fields on PaperScope.prototype, e.g. all classes
|
||||
for (var key in this) {
|
||||
if (!/^(version|_id)/.test(key))
|
||||
for (var key in this)
|
||||
// Exclude all 'hidden' fields
|
||||
if (!/^_/.test(key) && this[key])
|
||||
scope[key] = this[key];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -228,14 +220,14 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
_id: 0,
|
||||
|
||||
/**
|
||||
* Retrieves a PaperScope object with the given id or associated with
|
||||
* the passed canvas element.
|
||||
* Retrieves a PaperScope object with the given id or associated
|
||||
* with the passed canvas element.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
get: function(id) {
|
||||
// If a script tag is passed, get the id from it.
|
||||
if (typeof id === 'object')
|
||||
if (id && id.getAttribute)
|
||||
id = id.getAttribute('id');
|
||||
return this._scopes[id] || null;
|
||||
},
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -14,26 +14,12 @@
|
|||
* @name PaperScript
|
||||
* @namespace
|
||||
*/
|
||||
// Note that due to the use of with(), PaperScript gets compiled outside the
|
||||
// main paper scope, and is added to the PaperScope class. This allows for
|
||||
// better minification and the future use of strict mode once it makes sense
|
||||
// in terms of performance.
|
||||
paper.PaperScope.prototype.PaperScript = (function(root) {
|
||||
var Base = paper.Base,
|
||||
PaperScope = paper.PaperScope,
|
||||
// For local reference, for now only when setting lineNumberBase on
|
||||
// Firefox.
|
||||
PaperScript,
|
||||
// Locally turn of exports and define for inlined acorn / esprima.
|
||||
// Just declaring the local vars is enough, as they will be undefined.
|
||||
exports, define,
|
||||
Base.exports.PaperScript = (function() {
|
||||
// Locally turn of exports and define for inlined acorn / esprima.
|
||||
// Just declaring the local vars is enough, as they will be undefined.
|
||||
var exports, define,
|
||||
// The scope into which the library is loaded.
|
||||
scope = this;
|
||||
/*#*/ if (__options.version == 'dev') {
|
||||
// As the above inclusion loads code into the root scope during dev,
|
||||
// set scope to root, so we can find the library.
|
||||
scope = root;
|
||||
/*#*/ } // __options.version == 'dev'
|
||||
/*#*/ if (__options.parser == 'acorn') {
|
||||
/*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false });
|
||||
/*#*/ } else if (__options.parser == 'esprima') {
|
||||
|
@ -43,7 +29,7 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
// Operators to overload
|
||||
|
||||
var binaryOperators = {
|
||||
// The hidden math functions are to be injected specifically, see below.
|
||||
// The hidden math methods are to be injected specifically, see below.
|
||||
'+': '__add',
|
||||
'-': '__subtract',
|
||||
'*': '__multiply',
|
||||
|
@ -59,19 +45,19 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
'+': null
|
||||
};
|
||||
|
||||
// Inject underscored math functions as aliases to Point, Size and Color.
|
||||
// Inject underscored math methods as aliases to Point, Size and Color.
|
||||
var fields = Base.each(
|
||||
['add', 'subtract', 'multiply', 'divide', 'modulo', 'negate'],
|
||||
function(name) {
|
||||
// Create an alias for ach math function to be injected into the
|
||||
// Create an alias for each math method to be injected into the
|
||||
// classes using Straps.js' #inject()
|
||||
this['__' + name] = '#' + name;
|
||||
},
|
||||
{}
|
||||
);
|
||||
paper.Point.inject(fields);
|
||||
paper.Size.inject(fields);
|
||||
paper.Color.inject(fields);
|
||||
Point.inject(fields);
|
||||
Size.inject(fields);
|
||||
Color.inject(fields);
|
||||
|
||||
// Use very short name for the binary operator (_$_) as well as the
|
||||
// unary operator ($_), as operations will be replaced with then.
|
||||
|
@ -118,13 +104,12 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
*/
|
||||
function compile(code) {
|
||||
// Use Acorn or Esprima to translate the code into an AST structure
|
||||
// which is then walked and parsed for operators to overload.
|
||||
// Instead of modifying the AST and converting back to code, we directly
|
||||
// change the source code based on the parser's range information, so we
|
||||
// can preserve line-numbers in syntax errors and remove the need for
|
||||
// Escodegen.
|
||||
// which is then walked and parsed for operators to overload. Instead of
|
||||
// modifying the AST and translating it back to code, we directly change
|
||||
// the source code based on the parser's range information, to preserve
|
||||
// line-numbers in syntax errors and remove the need for Escodegen.
|
||||
|
||||
// Tracks code insertions so we can add their differences to the
|
||||
// Track code insertions so their differences can be added to the
|
||||
// original offsets.
|
||||
var insertions = [];
|
||||
|
||||
|
@ -152,8 +137,8 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
// information up-to-date.
|
||||
function replaceCode(node, str) {
|
||||
var start = getOffset(node.range[0]),
|
||||
end = getOffset(node.range[1]);
|
||||
var insert = 0;
|
||||
end = getOffset(node.range[1]),
|
||||
insert = 0;
|
||||
// Sort insertions by their offset, so getOffest() can do its thing
|
||||
for (var i = insertions.length - 1; i >= 0; i--) {
|
||||
if (start > insertions[i][0]) {
|
||||
|
@ -183,7 +168,15 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
}
|
||||
}
|
||||
switch (node && node.type) {
|
||||
case 'BinaryExpression':
|
||||
case 'UnaryExpression': // -a
|
||||
if (node.operator in unaryOperators
|
||||
&& node.argument.type !== 'Literal') {
|
||||
var arg = getCode(node.argument);
|
||||
replaceCode(node, '$_("' + node.operator + '", '
|
||||
+ arg + ')');
|
||||
}
|
||||
break;
|
||||
case 'BinaryExpression': // a + b, a - b, a / b, a * b, a == b, ...
|
||||
if (node.operator in binaryOperators
|
||||
&& node.left.type !== 'Literal') {
|
||||
var left = getCode(node.left),
|
||||
|
@ -192,38 +185,37 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
+ '", ' + right + ')');
|
||||
}
|
||||
break;
|
||||
case 'AssignmentExpression':
|
||||
if (/^.=$/.test(node.operator)
|
||||
&& node.left.type !== 'Literal') {
|
||||
var left = getCode(node.left),
|
||||
right = getCode(node.right);
|
||||
replaceCode(node, left + ' = _$_(' + left + ', "'
|
||||
+ node.operator[0] + '", ' + right + ')');
|
||||
}
|
||||
break;
|
||||
case 'UpdateExpression':
|
||||
if (!node.prefix && !(parent && (
|
||||
case 'UpdateExpression': // a++, a--
|
||||
case 'AssignmentExpression': /// a += b, a -= b
|
||||
if (!(parent && (
|
||||
// Filter out for statements to allow loop increments
|
||||
// to perform well
|
||||
parent.type === 'ForStatement'
|
||||
// We need to filter out parents that are comparison
|
||||
// operators, e.g. for situations like if (++i < 1),
|
||||
// as we can't replace that with if (_$_(i, "+", 1) < 1)
|
||||
// Match any operator beginning with =, !, < and >.
|
||||
parent.type === 'BinaryExpression'
|
||||
|| parent.type === 'BinaryExpression'
|
||||
&& /^[=!<>]/.test(parent.operator)
|
||||
// array[i++] is a MemberExpression with computed = true
|
||||
// We can't replace that with array[_$_(i, "+", 1)].
|
||||
|| parent.type === 'MemberExpression'
|
||||
&& parent.computed))) {
|
||||
var arg = getCode(node.argument);
|
||||
replaceCode(node, arg + ' = _$_(' + arg + ', "'
|
||||
+ node.operator[0] + '", 1)');
|
||||
}
|
||||
break;
|
||||
case 'UnaryExpression':
|
||||
if (node.operator in unaryOperators
|
||||
&& node.argument.type !== 'Literal') {
|
||||
var arg = getCode(node.argument);
|
||||
replaceCode(node, '$_("' + node.operator + '", '
|
||||
+ arg + ')');
|
||||
if (node.type === 'UpdateExpression') {
|
||||
if (!node.prefix) {
|
||||
var arg = getCode(node.argument);
|
||||
replaceCode(node, arg + ' = _$_(' + arg + ', "'
|
||||
+ node.operator[0] + '", 1)');
|
||||
}
|
||||
} else { // AssignmentExpression
|
||||
if (/^.=$/.test(node.operator)
|
||||
&& node.left.type !== 'Literal') {
|
||||
var left = getCode(node.left),
|
||||
right = getCode(node.right);
|
||||
replaceCode(node, left + ' = _$_(' + left + ', "'
|
||||
+ node.operator[0] + '", ' + right + ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -238,97 +230,117 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Evaluates parsed PaperScript code in the passed {@link PaperScope}
|
||||
* object. It also installs handlers automatically for us.
|
||||
* Executes the parsed PaperScript code in a compiled function that receives
|
||||
* all properties of the passed {@link PaperScope} as arguments, to emulate
|
||||
* a global scope with unaffected performance. It also installs global view
|
||||
* and tool handlers automatically for you.
|
||||
*
|
||||
* @name PaperScript.evaluate
|
||||
* @name PaperScript.execute
|
||||
* @function
|
||||
* @param {String} code The PaperScript code
|
||||
* @param {PaperScript} scope The scope in which the code is executed
|
||||
* @return {Object} the result of the code evaluation
|
||||
* @param {PaperScript} scope The scope for which the code is executed
|
||||
*/
|
||||
function evaluate(code, scope) {
|
||||
function execute(code, scope) {
|
||||
// Set currently active scope.
|
||||
paper = scope;
|
||||
var view = scope.project && scope.project.view,
|
||||
res;
|
||||
// Define variables for potential handlers, so eval() calls below to
|
||||
// fetch their values do not require try-catch around them.
|
||||
// Use with() {} in order to make the scope the current 'global' scope
|
||||
// instead of window.
|
||||
with (scope) {
|
||||
// Within this, use a function scope, so local variables to not try
|
||||
// and set themselves on the scope object.
|
||||
(function() {
|
||||
var onActivate, onDeactivate, onEditOptions,
|
||||
onMouseDown, onMouseUp, onMouseDrag, onMouseMove,
|
||||
onKeyDown, onKeyUp, onFrame, onResize;
|
||||
code = compile(code);
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
if (root.InstallTrigger) { // Firefox
|
||||
// On Firefox, all error numbers inside evaled code are
|
||||
// relative to the line where the eval happened. Totally
|
||||
// silly, but that's how it is. So we're calculating the
|
||||
// base of lineNumbers, to remove it again from reported
|
||||
// errors. Luckily, Firefox is the only browser where we can
|
||||
// define the lineNumber for exceptions.
|
||||
var handle = PaperScript.handleException;
|
||||
if (!handle) {
|
||||
handle = PaperScript.handleException = function(e) {
|
||||
throw e.lineNumber >= lineNumber
|
||||
? new Error(e.message, e.fileName,
|
||||
e.lineNumber - lineNumber)
|
||||
: e;
|
||||
}
|
||||
// We're using a crazy hack to detect wether the library
|
||||
// is minified or not: By generating a second error on
|
||||
// the 2nd line and using the difference in line numbers
|
||||
// to calculate the offset to the eval, it works in both
|
||||
// casees.
|
||||
var lineNumber = new Error().lineNumber;
|
||||
lineNumber += (new Error().lineNumber - lineNumber) * 3;
|
||||
}
|
||||
try {
|
||||
// Add a semi-colon at the start so Firefox doesn't
|
||||
// swallow empty lines and shift error messages.
|
||||
res = eval(';' + code);
|
||||
} catch (e) {
|
||||
handle(e);
|
||||
}
|
||||
} else {
|
||||
res = eval(code);
|
||||
var view = scope.getView(),
|
||||
// Only create a tool object if something resembling a tool handler
|
||||
// definition is contained in the code.
|
||||
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code)
|
||||
? new Tool()
|
||||
: null,
|
||||
toolHandlers = tool ? tool._events : [],
|
||||
// Compile a list of all handlers that can be defined globally
|
||||
// inside the PaperScript. These are passed on to the function as
|
||||
// undefined arguments, so that their name exists, rather than
|
||||
// injecting a code line that defines them as variables.
|
||||
// They are exported again at the end of the function.
|
||||
handlers = ['onFrame', 'onResize'].concat(toolHandlers),
|
||||
// compile a list of paramter names for all variables that need to
|
||||
// appear as globals inside the script. At the same time, also
|
||||
// collect their values, so we can pass them on as arguments in the
|
||||
// function call.
|
||||
params = [],
|
||||
args = [],
|
||||
func;
|
||||
code = compile(code);
|
||||
function expose(scope, hidden) {
|
||||
// Look through all enumerable properties on the scope and expose
|
||||
// these too as pseudo-globals, but only if they seem to be in use.
|
||||
for (var key in scope) {
|
||||
if ((hidden || !/^_/.test(key)) && new RegExp(
|
||||
'\\b' + key.replace(/\$/g, '\\$') + '\\b').test(code)) {
|
||||
params.push(key);
|
||||
args.push(scope[key]);
|
||||
}
|
||||
/*#*/ } else { // !__options.environment == 'browser'
|
||||
res = eval(code);
|
||||
/*#*/ } // !__options.environment == 'browser'
|
||||
// Only look for tool handlers if something resembling their
|
||||
// name is contained in the code.
|
||||
if (/on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)) {
|
||||
Base.each(paper.Tool.prototype._events, function(key) {
|
||||
var value = eval(key);
|
||||
if (value) {
|
||||
// Use the getTool accessor that handles auto tool
|
||||
// creation for us:
|
||||
scope.getTool()[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (view) {
|
||||
view.setOnResize(onResize);
|
||||
// Fire resize event directly, so any user
|
||||
// defined resize handlers are called.
|
||||
view.fire('resize', {
|
||||
size: view.size,
|
||||
delta: new Point()
|
||||
});
|
||||
if (onFrame)
|
||||
view.setOnFrame(onFrame);
|
||||
// Automatically update view at the end.
|
||||
view.update();
|
||||
}
|
||||
}).call(scope);
|
||||
}
|
||||
}
|
||||
expose({ _$_: _$_, $_: $_, view: view, tool: tool }, true);
|
||||
expose(scope);
|
||||
// Finally define the handler variable names as parameters and compose
|
||||
// the string describing the properties for the returned object at the
|
||||
// end of the code execution, so we can retrieve their values from the
|
||||
// function call.
|
||||
handlers = Base.each(handlers, function(key) {
|
||||
// Check for each handler explicitely and only return them if they
|
||||
// seem to exist.
|
||||
if (new RegExp('\\s+' + key + '\\b').test(code)) {
|
||||
params.push(key);
|
||||
this.push(key + ': ' + key);
|
||||
}
|
||||
}, []).join(', ');
|
||||
// We need an additional line that returns the handlers in one object.
|
||||
if (handlers)
|
||||
code += '\nreturn { ' + handlers + ' };';
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
var firefox = window.InstallTrigger;
|
||||
if (firefox || window.chrome) {
|
||||
// On Firefox, all error numbers inside dynamically compiled code
|
||||
// are relative to the line where the eval / compilation happened.
|
||||
// To fix this issue, we're temporarily inserting a new script
|
||||
// tag. We also use this on Chrome to fix an issue with compiled
|
||||
// functions:
|
||||
// https://code.google.com/p/chromium/issues/detail?id=331655
|
||||
var script = document.createElement('script'),
|
||||
head = document.head;
|
||||
// Add a new-line before the code on Firefox since the error
|
||||
// messages appeawr to be aligned to line number 0...
|
||||
if (firefox)
|
||||
code = '\n' + code;
|
||||
script.appendChild(document.createTextNode(
|
||||
'paper._execute = function(' + params + ') {' + code + '\n}'
|
||||
));
|
||||
head.appendChild(script);
|
||||
func = paper._execute;
|
||||
delete paper._execute;
|
||||
head.removeChild(script);
|
||||
} else {
|
||||
func = Function(params, code);
|
||||
}
|
||||
/*#*/ } else { // !__options.environment == 'browser'
|
||||
func = Function(params, code);
|
||||
/*#*/ } // !__options.environment == 'browser'
|
||||
var res = func.apply(scope, args) || {};
|
||||
// Now install the 'global' tool and view handlers, and we're done!
|
||||
Base.each(toolHandlers, function(key) {
|
||||
var value = res[key];
|
||||
if (value)
|
||||
tool[key] = value;
|
||||
});
|
||||
if (view) {
|
||||
if (res.onResize)
|
||||
view.setOnResize(res.onResize);
|
||||
// Fire resize event directly, so any user
|
||||
// defined resize handlers are called.
|
||||
view.fire('resize', {
|
||||
size: view.size,
|
||||
delta: new Point()
|
||||
});
|
||||
if (res.onFrame)
|
||||
view.setOnFrame(res.onFrame);
|
||||
// Automatically update view at the end.
|
||||
view.update();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
|
@ -356,12 +368,12 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
if (src) {
|
||||
// If we're loading from a source, request that first and
|
||||
// then run later.
|
||||
paper.Http.request('get', src, function(code) {
|
||||
evaluate(code, scope);
|
||||
Http.request('get', src, function(code) {
|
||||
execute(code, scope);
|
||||
});
|
||||
} else {
|
||||
// We can simply get the code form the script tag.
|
||||
evaluate(script.innerHTML, scope);
|
||||
execute(script.innerHTML, scope);
|
||||
}
|
||||
// Mark script as loaded now.
|
||||
script.setAttribute('data-paper-ignore', true);
|
||||
|
@ -375,12 +387,12 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
// Handle it asynchronously
|
||||
setTimeout(load);
|
||||
} else {
|
||||
paper.DomEvent.add(window, { load: load });
|
||||
DomEvent.add(window, { load: load });
|
||||
}
|
||||
|
||||
return PaperScript = {
|
||||
return {
|
||||
compile: compile,
|
||||
evaluate: evaluate,
|
||||
execute: execute,
|
||||
load: load,
|
||||
lineNumberBase: 0
|
||||
};
|
||||
|
@ -393,23 +405,31 @@ paper.PaperScope.prototype.PaperScript = (function(root) {
|
|||
path = require('path');
|
||||
|
||||
require.extensions['.pjs'] = function(module, uri) {
|
||||
var source = compile(fs.readFileSync(uri, 'utf8')),
|
||||
scope = new PaperScope();
|
||||
scope.__filename = uri;
|
||||
scope.__dirname = path.dirname(uri);
|
||||
// Expose core methods and values
|
||||
scope.require = require;
|
||||
scope.console = console;
|
||||
evaluate(source, scope);
|
||||
module.exports = scope;
|
||||
// Requiring a PaperScript on Node.js returns an initialize method which
|
||||
// needs to receive a Canvas object when called and returns the
|
||||
// PaperScope.
|
||||
module.exports = function(canvas) {
|
||||
var source = compile(fs.readFileSync(uri, 'utf8')),
|
||||
scope = new PaperScope();
|
||||
scope.setup(canvas);
|
||||
scope.__filename = uri;
|
||||
scope.__dirname = path.dirname(uri);
|
||||
// Expose core methods and values
|
||||
scope.require = require;
|
||||
scope.console = console;
|
||||
execute(source, scope);
|
||||
return scope;
|
||||
};
|
||||
};
|
||||
|
||||
/*#*/ } // __options.environment == 'node'
|
||||
|
||||
return PaperScript = {
|
||||
return {
|
||||
compile: compile,
|
||||
evaluate: evaluate
|
||||
execute: execute
|
||||
};
|
||||
|
||||
/*#*/ } // !__options.environment == 'browser'
|
||||
})(this);
|
||||
// Pass on `this` as the binding object, so we can reference Acorn both in
|
||||
// development and in the built library.
|
||||
}).call(this);
|
||||
|
|
|
@ -2,24 +2,27 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/** @scope _global_ */ {
|
||||
|
||||
// DOCS: Find a way to put this description into _global_
|
||||
|
||||
/**
|
||||
* In a PaperScript context, the global scope is populated with all
|
||||
* fields of the currently active {@link PaperScope} object. In a JavaScript
|
||||
* context, it only contains the {@link #paper} reference to the currently
|
||||
* active {@link PaperScope} object, which also exposes all Paper classes.
|
||||
*/
|
||||
/**
|
||||
* @name _global_
|
||||
* @namespace
|
||||
*
|
||||
* When code is executed as PaperScript, the script's scope is populated with
|
||||
* all fields of the currently active {@link PaperScope} object, which within
|
||||
* the script appear to be global.
|
||||
*
|
||||
* In a JavaScript context, only the {@link paper} variable is added to the
|
||||
* global scope, referencing the currently active {@link PaperScope} object,
|
||||
* through which all properties and Paper.js classes can be accessed.
|
||||
*/
|
||||
/** @scope _global_ */{
|
||||
|
||||
/**
|
||||
* A reference to the currently active {@link PaperScope} object.
|
||||
|
@ -32,40 +35,58 @@
|
|||
// DOCS: This does not work: @borrows PaperScope#version as _global_#version,
|
||||
// so we're repeating documentation here form PaperScope:
|
||||
/**
|
||||
* {@grouptitle Global PaperScope Properties (for PaperScript)}
|
||||
* {@grouptitle Global PaperScript Properties}
|
||||
*
|
||||
* The project for which the PaperScript is executed.
|
||||
*
|
||||
* Note that when working with mulitple projects, this does not necessarily
|
||||
* reflect the currently active project. For this, use
|
||||
* {@link PaperScope#project} instead.
|
||||
*
|
||||
* The currently active project.
|
||||
* @name project
|
||||
* @type Project
|
||||
*/
|
||||
|
||||
/**
|
||||
* The list of all open projects within the current Paper.js context.
|
||||
*
|
||||
* @name projects
|
||||
* @type Project[]
|
||||
*/
|
||||
|
||||
/**
|
||||
* The reference to the active project's view.
|
||||
* The reference to the project's view.
|
||||
*
|
||||
* Note that when working with mulitple projects, this does not necessarily
|
||||
* reflect the view of the currently active project. For this, use
|
||||
* {@link PaperScope#view} instead.
|
||||
*
|
||||
* @name view
|
||||
* @type View
|
||||
*/
|
||||
|
||||
/**
|
||||
* The reference to the active tool.
|
||||
* The reference to the tool object which is automatically created when global
|
||||
* tool event handlers are defined.
|
||||
*
|
||||
* Note that when working with mulitple tools, this does not necessarily
|
||||
* reflect the currently active tool. For this, use {@link PaperScope#tool}
|
||||
* instead.
|
||||
*
|
||||
* @name tool
|
||||
* @type Tool
|
||||
*/
|
||||
|
||||
/**
|
||||
* The list of available tools.
|
||||
*
|
||||
* @name tools
|
||||
* @type Tool[]
|
||||
*/
|
||||
|
||||
/**
|
||||
* {@grouptitle View Event Handlers (for PaperScript)}
|
||||
* A reference to the {@link View#onFrame} handler function.
|
||||
* {@grouptitle PaperScript View Event Handlers}
|
||||
* A global reference to the {@link View#onFrame} handler function.
|
||||
*
|
||||
* @name onFrame
|
||||
* @property
|
||||
|
@ -81,7 +102,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* {@grouptitle Mouse Event Handlers (for PaperScript)}
|
||||
* {@grouptitle PaperScript Tool Event Handlers}
|
||||
* A reference to the {@link Tool#onMouseDown} handler function.
|
||||
* @name onMouseDown
|
||||
* @property
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -46,7 +46,7 @@ var DomElement = new function() {
|
|||
return res;
|
||||
}
|
||||
|
||||
return {
|
||||
return /** @lends DomElement */{
|
||||
create: function(nodes, parent) {
|
||||
var isArray = Array.isArray(nodes),
|
||||
res = create(isArray ? nodes : arguments, isArray ? parent : null);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -15,7 +15,7 @@
|
|||
* @namespace
|
||||
* @private
|
||||
*/
|
||||
var DomEvent = {
|
||||
var DomEvent = /** @lends DomEvent */{
|
||||
add: function(el, events) {
|
||||
for (var type in events)
|
||||
el.addEventListener(type, events[type], false);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -106,7 +106,7 @@ var Group = Item.extend(/** @lends Group# */{
|
|||
}
|
||||
if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.CLIPPING)) {
|
||||
// Clear cached clip item whenever hierarchy changes
|
||||
delete this._clipItem;
|
||||
this._clipItem = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
100
src/item/Item.js
100
src/item/Item.js
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -214,10 +214,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
project = this._project;
|
||||
if (flags & /*#=*/ ChangeFlag.GEOMETRY) {
|
||||
// Clear cached bounds and position whenever geometry changes
|
||||
delete this._bounds;
|
||||
delete this._position;
|
||||
delete this._decomposed;
|
||||
delete this._globalMatrix;
|
||||
this._bounds = this._position = this._decomposed =
|
||||
this._globalMatrix = undefined;
|
||||
}
|
||||
if (cacheParent && (flags
|
||||
& (/*#=*/ ChangeFlag.GEOMETRY | /*#=*/ ChangeFlag.STROKE))) {
|
||||
|
@ -762,11 +760,11 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* // Move the circle 100 points to the right
|
||||
* circle.position.x += 100;
|
||||
*/
|
||||
getPosition: function(/* dontLink */) {
|
||||
getPosition: function(_dontLink) {
|
||||
// Cache position value.
|
||||
// Pass true for dontLink in getCenter(), so receive back a normal point
|
||||
// Pass true for _dontLink in getCenter(), so receive back a normal point
|
||||
var position = this._position,
|
||||
ctor = arguments[0] ? Point : LinkedPoint;
|
||||
ctor = _dontLink ? Point : LinkedPoint;
|
||||
// Do not cache LinkedPoints directly, since we would not be able to
|
||||
// use them to calculate the difference in #setPosition, as when it is
|
||||
// modified, it would hold new values already and only then cause the
|
||||
|
@ -784,7 +782,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
|
||||
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
|
||||
// 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)));
|
||||
},
|
||||
|
@ -802,10 +800,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
*
|
||||
* @example {@paperscript}
|
||||
*/
|
||||
getPivot: function(/* dontLink */) {
|
||||
getPivot: function(_dontLink) {
|
||||
var pivot = this._pivot;
|
||||
if (pivot) {
|
||||
var ctor = arguments[0] ? Point : LinkedPoint;
|
||||
var ctor = _dontLink ? Point : LinkedPoint;
|
||||
pivot = new ctor(pivot.x, pivot.y, this, 'setAnchor');
|
||||
}
|
||||
return pivot;
|
||||
|
@ -814,17 +812,17 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
setPivot: function(/* point */) {
|
||||
this._pivot = Point.read(arguments);
|
||||
// No need for _changed() since the only thing this affects is _position
|
||||
delete this._position;
|
||||
this._position = undefined;
|
||||
},
|
||||
|
||||
_pivot: null,
|
||||
|
||||
// TODO: Keep these around for a bit since it was introduced on the mailing
|
||||
// list, then remove in a while.
|
||||
getRegistration: '#getAnchor',
|
||||
setRegistration: '#setAnchor'
|
||||
}, Base.each(['getBounds', 'getStrokeBounds', 'getHandleBounds',
|
||||
'getRoughBounds', 'getInternalBounds', 'getInternalRoughBounds'],
|
||||
getRegistration: '#getPivot',
|
||||
setRegistration: '#setPivot'
|
||||
}, Base.each(['bounds', 'strokeBounds', 'handleBounds', 'roughBounds',
|
||||
'internalBounds', 'internalRoughBounds'],
|
||||
function(key) {
|
||||
// Produce getters for bounds properties. These handle caching, matrices
|
||||
// and redirect the call to the private _getBounds, which can be
|
||||
|
@ -836,25 +834,33 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// as internalGetter.
|
||||
// NOTE: These need to be versions of other methods, as otherwise the
|
||||
// cache gets messed up.
|
||||
var match = key.match(/^getInternal(.*)$/),
|
||||
var getter = 'get' + Base.capitalize(key),
|
||||
match = key.match(/^internal(.*)$/),
|
||||
internalGetter = match ? 'get' + match[1] : null;
|
||||
this[key] = function(/* matrix */) {
|
||||
var getter = this._boundsGetter,
|
||||
// Allow subclasses to override _boundsGetter if they use
|
||||
// the same calculations for multiple type of bounds.
|
||||
// The default is key:
|
||||
bounds = this._getCachedBounds(!internalGetter
|
||||
&& (typeof getter === 'string'
|
||||
? getter : getter && getter[key])
|
||||
|| key, arguments[0], null, internalGetter);
|
||||
this[getter] = function(_matrix) {
|
||||
var boundsGetter = this._boundsGetter,
|
||||
// Allow subclasses to override _boundsGetter if they use the
|
||||
// same calculations for multiple type of bounds.
|
||||
// The default is getter:
|
||||
name = !internalGetter && (typeof boundsGetter === 'string'
|
||||
? boundsGetter : boundsGetter && boundsGetter[getter])
|
||||
|| getter,
|
||||
bounds = this._getCachedBounds(name, _matrix, null,
|
||||
internalGetter);
|
||||
// If we're returning 'bounds', create a LinkedRectangle that uses
|
||||
// the setBounds() setter to update the Item whenever the bounds are
|
||||
// changed:
|
||||
return key === 'getBounds'
|
||||
return key === 'bounds'
|
||||
? new LinkedRectangle(bounds.x, bounds.y, bounds.width,
|
||||
bounds.height, this, 'setBounds')
|
||||
: bounds;
|
||||
};
|
||||
// As the function defines a _matrix parameter and has no setter,
|
||||
// Straps.js doesn't produce a bean for it. Explicitely define an
|
||||
// accesor now too:
|
||||
this[key] = {
|
||||
get: this[getter]
|
||||
};
|
||||
},
|
||||
/** @lends Item# */{
|
||||
/**
|
||||
|
@ -891,9 +897,9 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
: new Rectangle();
|
||||
},
|
||||
|
||||
setBounds: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var bounds = this.getBounds(),
|
||||
setBounds: function(/* rect */) {
|
||||
var rect = Rectangle.read(arguments),
|
||||
bounds = this.getBounds(),
|
||||
matrix = new Matrix(),
|
||||
center = rect.getCenter();
|
||||
// Read this from bottom to top:
|
||||
|
@ -991,16 +997,15 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
for (var i = 0, list = item._boundsCache.list, l = list.length;
|
||||
i < l; i++) {
|
||||
var child = list[i];
|
||||
delete child._bounds;
|
||||
child._bounds = child._position = undefined;
|
||||
// Delete position as well, since it's depending on bounds.
|
||||
delete child._position;
|
||||
// We need to recursively call _clearBoundsCache, because if
|
||||
// the cache for this child's children is not valid anymore,
|
||||
// that propagates up the DOM tree.
|
||||
if (child !== item && child._boundsCache)
|
||||
child._clearBoundsCache();
|
||||
}
|
||||
delete item._boundsCache;
|
||||
item._boundsCache = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1083,7 +1088,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
var current = this.getScaling();
|
||||
if (current != null) {
|
||||
// Clone existing points since we're caching internally.
|
||||
var scaling = Point.read(arguments, 0, 0, { clone: true }),
|
||||
var scaling = Point.read(arguments, 0, { clone: true }),
|
||||
// See #setRotation() for preservation of _decomposed.
|
||||
decomposed = this._decomposed;
|
||||
this.scale(scaling.x / current.x, scaling.y / current.y);
|
||||
|
@ -1804,12 +1809,15 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* data string.
|
||||
*
|
||||
* The options object offers control over some aspects of the SVG export:
|
||||
* <b>options.asString:</b> {@code Boolean} – wether the JSON is returned as
|
||||
* a {@code Object} or a {@code String}.
|
||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||
* digits in numbers used in JSON data.
|
||||
*
|
||||
* @name Item#exportJSON
|
||||
* @function
|
||||
* @param {Object} [options={ precision: 5 }] the serialization options
|
||||
* @param {Object} [options={ asString: true, precision: 5 }] the
|
||||
* serialization options
|
||||
* @return {String} the exported JSON data
|
||||
*/
|
||||
|
||||
|
@ -1836,8 +1844,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* Exports the item with its content and child items as an SVG DOM.
|
||||
*
|
||||
* The options object offers control over some aspects of the SVG export:
|
||||
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a String
|
||||
* is to be returned.
|
||||
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a
|
||||
* {@code String} is to be returned.
|
||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||
* digits in numbers used in SVG data.
|
||||
* <b>options.matchShapes:</b> {@code Boolean} – wether imported path
|
||||
|
@ -1851,6 +1859,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* @return {SVGSVGElement} the item converted to an SVG node
|
||||
*/
|
||||
|
||||
// DOCS: Document importSVG('file.svg', callback);
|
||||
/**
|
||||
* Converts the provided SVG content into Paper.js items and adds them to
|
||||
* the this item's children list.
|
||||
|
@ -2589,14 +2598,14 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
*/
|
||||
rotate: function(angle /*, center */) {
|
||||
return this.transform(new Matrix().rotate(angle,
|
||||
Point.read(arguments, 1, 0, { readNull: true })
|
||||
Point.read(arguments, 1, { readNull: true })
|
||||
|| this.getPosition(true)));
|
||||
}
|
||||
}, Base.each(['scale', 'shear', 'skew'], function(name) {
|
||||
this[name] = function() {
|
||||
// See Matrix#scale for explanation of this:
|
||||
var point = Point.read(arguments),
|
||||
center = Point.read(arguments, 0, 0, { readNull: true });
|
||||
center = Point.read(arguments, 0, { readNull: true });
|
||||
return this.transform(new Matrix()[name](point,
|
||||
center || this.getPosition(true)));
|
||||
};
|
||||
|
@ -2717,7 +2726,10 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// @param {String[]} flags Array of any of the following: 'objects',
|
||||
// 'children', 'fill-gradients', 'fill-patterns', 'stroke-patterns',
|
||||
// 'lines'. Default: ['objects', 'children']
|
||||
transform: function(matrix /*, applyMatrix */) {
|
||||
transform: function(matrix, _applyMatrix) {
|
||||
// Bail out immediatelly if there is nothing to do
|
||||
if (matrix.isIdentity())
|
||||
return this;
|
||||
// Calling _changed will clear _bounds and _position, but depending
|
||||
// on matrix we can calculate and set them again.
|
||||
var bounds = this._bounds,
|
||||
|
@ -2726,7 +2738,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
this._matrix.preConcatenate(matrix);
|
||||
// Call applyMatrix if we need to directly apply the accumulated
|
||||
// transformations to the item's content.
|
||||
if (this._transformContent || arguments[1])
|
||||
if (this._transformContent || _applyMatrix)
|
||||
this.applyMatrix(true);
|
||||
// We always need to call _changed since we're caching bounds on all
|
||||
// items, including Group.
|
||||
|
@ -2784,7 +2796,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// color styles (only gradients so far) and pivot point:
|
||||
var pivot = this._pivot,
|
||||
style = this._style,
|
||||
// pass true for dontMerge so we don't recursively transform
|
||||
// pass true for _dontMerge so we don't recursively transform
|
||||
// styles on groups' children.
|
||||
fillColor = style.getFillColor(true),
|
||||
strokeColor = style.getStrokeColor(true);
|
||||
|
@ -2796,7 +2808,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
strokeColor.transform(matrix);
|
||||
// Reset the internal matrix to the identity transformation if it
|
||||
// was possible to apply it.
|
||||
matrix.reset();
|
||||
matrix.reset(true);
|
||||
}
|
||||
if (!_dontNotify)
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -244,13 +244,13 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* @type Context
|
||||
* @bean
|
||||
*/
|
||||
getContext: function(/* modify */) {
|
||||
getContext: function(modify) {
|
||||
if (!this._context)
|
||||
this._context = this.getCanvas().getContext('2d');
|
||||
// Support a hidden parameter that indicates if the context will be used
|
||||
// to modify the Raster object. We can notify such changes ahead since
|
||||
// they are only used afterwards for redrawing.
|
||||
if (arguments[0]) {
|
||||
if (modify) {
|
||||
// Also set _image to null since the Raster stops representing it.
|
||||
// NOTE: This should theoretically be in our own _changed() handler
|
||||
// for ChangeFlag.PIXELS, but since it's only happening in one place
|
||||
|
@ -375,9 +375,9 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
*
|
||||
* @return {Canvas} the sub image as a Canvas object
|
||||
*/
|
||||
getSubCanvas: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var ctx = CanvasProvider.getContext(rect.getSize());
|
||||
getSubCanvas: function(rect) { // TODO: Fix argument assignment!
|
||||
var rect = Rectangle.read(arguments),
|
||||
ctx = CanvasProvider.getContext(rect.getSize());
|
||||
ctx.drawImage(this.getCanvas(), rect.x, rect.y,
|
||||
rect.width, rect.height, 0, 0, rect.width, rect.height);
|
||||
return ctx.canvas;
|
||||
|
@ -392,9 +392,9 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
*
|
||||
* @return {Raster} the sub raster as a newly created raster item
|
||||
*/
|
||||
getSubRaster: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var raster = new Raster({
|
||||
getSubRaster: function(rect) { // TODO: Fix argument assignment!
|
||||
var rect = Rectangle.read(arguments),
|
||||
raster = new Raster({
|
||||
canvas: this.getSubCanvas(rect),
|
||||
insert: false
|
||||
});
|
||||
|
@ -434,8 +434,8 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* @param {Point} point the offset of the image as a point in pixel
|
||||
* coordinates
|
||||
*/
|
||||
drawImage: function(image, point) {
|
||||
point = Point.read(arguments, 1);
|
||||
drawImage: function(image /*, point */) {
|
||||
var point = Point.read(arguments, 1);
|
||||
this.getContext(true).drawImage(image, point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -531,8 +531,8 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* @param point the offset of the pixel as a point in pixel coordinates
|
||||
* @return {Color} the color of the pixel
|
||||
*/
|
||||
getPixel: function(point) {
|
||||
point = Point.read(arguments);
|
||||
getPixel: function(point) { // TODO: Fix argument assignment!
|
||||
var point = Point.read(arguments);
|
||||
var data = this.getContext().getImageData(point.x, point.y, 1, 1).data;
|
||||
// Alpha is separate now:
|
||||
return new Color('rgb', [data[0] / 255, data[1] / 255, data[2] / 255],
|
||||
|
@ -577,8 +577,8 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* @param {Size} size
|
||||
* @return {ImageData}
|
||||
*/
|
||||
createImageData: function(size) {
|
||||
size = Size.read(arguments);
|
||||
createImageData: function(/* size */) {
|
||||
var size = Size.read(arguments);
|
||||
return this.getContext().createImageData(size.width, size.height);
|
||||
},
|
||||
|
||||
|
@ -587,8 +587,8 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* @param {Rectangle} rect
|
||||
* @return {ImageData}
|
||||
*/
|
||||
getImageData: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
getImageData: function(rect) { // TODO: Fix argument assignment!
|
||||
var rect = Rectangle.read(arguments);
|
||||
if (rect.isEmpty())
|
||||
rect = new Rectangle(this._size);
|
||||
return this.getContext().getImageData(rect.x, rect.y,
|
||||
|
@ -601,8 +601,8 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
* @param {Point} point
|
||||
* @return {ImageData}
|
||||
*/
|
||||
setImageData: function(data, point) {
|
||||
point = Point.read(arguments, 1);
|
||||
setImageData: function(data /*, point */) {
|
||||
var point = Point.read(arguments, 1);
|
||||
this.getContext(true).putImageData(data, point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -616,7 +616,7 @@ var Raster = Item.extend(/** @lends Raster# */{
|
|||
var that = this;
|
||||
return new HitResult('pixel', that, {
|
||||
offset: point.add(that._size.divide(2)).round(),
|
||||
// Inject as Bootstrap accessor, so #toString renders well too
|
||||
// Inject as Straps.js accessor, so #toString renders well too
|
||||
color: {
|
||||
get: function() {
|
||||
return that.getPixel(this.offset);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
22
src/paper.js
22
src/paper.js
|
@ -2,8 +2,8 @@
|
|||
* Paper.js v*#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -13,16 +13,16 @@
|
|||
*
|
||||
***
|
||||
*
|
||||
* straps.js - Class inheritance library with support for bean-style accessors
|
||||
* Straps.js - Class inheritance library with support for bean-style accessors
|
||||
*
|
||||
* Copyright (c) 2006 - 2013 Juerg Lehni
|
||||
* http://lehni.org/
|
||||
* http://scratchdisk.com/
|
||||
*
|
||||
* Distributed under the MIT license.
|
||||
*
|
||||
***
|
||||
*
|
||||
* acorn.js
|
||||
* Acorn.js
|
||||
* http://marijnhaverbeke.nl/acorn/
|
||||
*
|
||||
* Acorn is a tiny, fast JavaScript parser written in JavaScript,
|
||||
|
@ -33,7 +33,7 @@
|
|||
// Allow the minification of the undefined variable by defining it as a local
|
||||
// parameter inside the paper scope.
|
||||
var paper = new function(undefined) {
|
||||
// Inline Bootstrap core (the Base class) inside the paper scope first:
|
||||
// Inline Straps.js core (the Base class) inside the paper scope first:
|
||||
/*#*/ include('../bower_components/straps/straps.js', { exports: false });
|
||||
|
||||
/*#*/ if (__options.stats) {
|
||||
|
@ -138,12 +138,10 @@ var paper = new function(undefined) {
|
|||
/*#*/ include('svg/SVGImport.js');
|
||||
/*#*/ } // __options.svg
|
||||
|
||||
/*#*/ include('export.js');
|
||||
return paper;
|
||||
};
|
||||
|
||||
// include PaperScript separately outside the main paper scope, due to its use
|
||||
// of with(). This also simplifies making its inclusion optional.
|
||||
/*#*/ if (__options.paperscript) {
|
||||
/*#*/ include('core/PaperScript.js');
|
||||
/*#*/ } // __options.paperscript
|
||||
|
||||
/*#*/ include('export.js');
|
||||
return paper;
|
||||
};
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -103,9 +103,9 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
|
||||
_changed: function _changed(flags) {
|
||||
_changed.base.call(this, flags);
|
||||
// Delete cached native Path
|
||||
// Clear cached native Path
|
||||
if (flags & (/*#=*/ ChangeFlag.HIERARCHY | /*#=*/ ChangeFlag.GEOMETRY))
|
||||
delete this._currentPath;
|
||||
this._currentPath = undefined;
|
||||
},
|
||||
|
||||
insertChildren: function insertChildren(index, items, _preserve) {
|
||||
|
@ -228,11 +228,11 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
|
|||
return area;
|
||||
},
|
||||
|
||||
getPathData: function(/* precision */) {
|
||||
getPathData: function(precision) {
|
||||
var children = this._children,
|
||||
paths = [];
|
||||
for (var i = 0, l = children.length; i < l; i++)
|
||||
paths.push(children[i].getPathData(arguments[0]));
|
||||
paths.push(children[i].getPathData(precision));
|
||||
return paths.join(' ');
|
||||
},
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -98,8 +98,7 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
|
||||
_changed: function() {
|
||||
// Clear cached values.
|
||||
delete this._length;
|
||||
delete this._bounds;
|
||||
this._length = this._bounds = undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -112,8 +111,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
return this._segment1._point;
|
||||
},
|
||||
|
||||
setPoint1: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setPoint1: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this._segment1._point.set(point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -127,8 +126,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
return this._segment2._point;
|
||||
},
|
||||
|
||||
setPoint2: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setPoint2: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this._segment2._point.set(point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -142,8 +141,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
return this._segment1._handleOut;
|
||||
},
|
||||
|
||||
setHandle1: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setHandle1: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this._segment1._handleOut.set(point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -157,8 +156,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
return this._segment2._handleIn;
|
||||
},
|
||||
|
||||
setHandle2: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setHandle2: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this._segment2._handleIn.set(point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -261,24 +260,16 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
return points;
|
||||
},
|
||||
|
||||
// DOCS: document Curve#getLength(from, to)
|
||||
/**
|
||||
* The approximated length of the curve in points.
|
||||
*
|
||||
* @type Number
|
||||
* @bean
|
||||
*/
|
||||
// Hide parameters from Bootstrap so it injects bean too
|
||||
getLength: function(/* from, to */) {
|
||||
var from = arguments[0],
|
||||
to = arguments[1],
|
||||
fullLength = arguments.length === 0 || from === 0 && to === 1;
|
||||
if (fullLength && this._length != null)
|
||||
return this._length;
|
||||
var length = Curve.getLength(this.getValues(), from, to);
|
||||
if (fullLength)
|
||||
this._length = length;
|
||||
return length;
|
||||
getLength: function() {
|
||||
if (this._length == null)
|
||||
this._length = Curve.getLength(this.getValues(), 0, 1);
|
||||
return this._length;
|
||||
},
|
||||
|
||||
getArea: function() {
|
||||
|
@ -289,6 +280,11 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
return new Curve(Curve.getPart(this.getValues(), from, to));
|
||||
},
|
||||
|
||||
// DOCS: document Curve#getPartLength(from, to)
|
||||
getPartLength: function(from, to) {
|
||||
return Curve.getLength(this.getValues(), from, to);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if this curve is linear, meaning it does not define any curve
|
||||
* handle.
|
||||
|
@ -583,7 +579,7 @@ statics: {
|
|||
},
|
||||
|
||||
getParameterOf: function(v, x, y) {
|
||||
// Handle beginnings and end seperately, as they are not detected
|
||||
// Handle beginnings and end separately, as they are not detected
|
||||
// sometimes.
|
||||
var tolerance = /*#=*/ Numerical.TOLERANCE;
|
||||
if (Math.abs(v[0] - x) < tolerance && Math.abs(v[1] - y) < tolerance)
|
||||
|
@ -702,7 +698,7 @@ statics: {
|
|||
c = v1 - v0,
|
||||
count = Numerical.solveQuadratic(a, b, c, roots),
|
||||
// Add some tolerance for good roots, as t = 0 / 1 are added
|
||||
// seperately anyhow, and we don't want joins to be added with
|
||||
// separately anyhow, and we don't want joins to be added with
|
||||
// radiuses in getStrokeBounds()
|
||||
tMin = /*#=*/ Numerical.TOLERANCE,
|
||||
tMax = 1 - tMin;
|
||||
|
@ -816,8 +812,8 @@ statics: {
|
|||
* @param {Point} point the point on the curve.
|
||||
* @return {Number} the curve time parameter of the specified point.
|
||||
*/
|
||||
getParameterOf: function(point) {
|
||||
point = Point.read(arguments);
|
||||
getParameterOf: function(point) { // TODO: Fix argument assignment!
|
||||
var point = Point.read(arguments);
|
||||
return Curve.getParameterOf(this.getValues(), point.x, point.y);
|
||||
},
|
||||
|
||||
|
@ -842,17 +838,17 @@ statics: {
|
|||
* @param {Point} point the point on the curve.
|
||||
* @return {CurveLocation} the curve location of the specified point.
|
||||
*/
|
||||
getLocationOf: function(point) {
|
||||
getLocationOf: function(point) { // TODO: Fix argument assignment!
|
||||
// We need to use point to avoid minification issues and prevent method
|
||||
// from turning into a bean (by removal of the point argument).
|
||||
point = Point.read(arguments);
|
||||
var t = this.getParameterOf(point);
|
||||
var point = Point.read(arguments),
|
||||
t = this.getParameterOf(point);
|
||||
return t != null ? new CurveLocation(this, t) : null;
|
||||
},
|
||||
|
||||
getNearestLocation: function(point) {
|
||||
point = Point.read(arguments);
|
||||
var values = this.getValues(),
|
||||
getNearestLocation: function(point) { // TODO: Fix argument assignment!
|
||||
var point = Point.read(arguments),
|
||||
values = this.getValues(),
|
||||
count = 100,
|
||||
minDist = Infinity,
|
||||
minT = 0;
|
||||
|
@ -886,7 +882,7 @@ statics: {
|
|||
getNearestPoint: function(point) {
|
||||
// We need to use point to avoid minification issues and prevent method
|
||||
// from turning into a bean (by removal of the point argument).
|
||||
point = Point.read(arguments);
|
||||
var point = Point.read(arguments);
|
||||
return this.getNearestLocation(point).getPoint();
|
||||
}
|
||||
|
||||
|
@ -983,12 +979,13 @@ new function() { // Scope for methods that require numerical integration
|
|||
b = 1;
|
||||
var isZero = Numerical.isZero;
|
||||
// See if the curve is linear by checking p1 == c1 and p2 == c2
|
||||
if (isZero(v[0] - v[2]) && isZero(v[1] - v[3])
|
||||
if (a === 0 && b === 1
|
||||
&& isZero(v[0] - v[2]) && isZero(v[1] - v[3])
|
||||
&& isZero(v[6] - v[4]) && isZero(v[7] - v[5])) {
|
||||
// Straight line
|
||||
var dx = v[6] - v[0], // p2x - p1x
|
||||
dy = v[7] - v[1]; // p2y - p1y
|
||||
return (b - a) * Math.sqrt(dx * dx + dy * dy);
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
var ds = getLengthIntegrand(v);
|
||||
return Numerical.integrate(ds, a, b, getIterations(a, b));
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -61,13 +61,13 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
* @type Segment
|
||||
* @bean
|
||||
*/
|
||||
getSegment: function(/* preferFirst */) {
|
||||
getSegment: function(_preferFirst) {
|
||||
if (!this._segment) {
|
||||
var curve = this.getCurve(),
|
||||
parameter = this.getParameter();
|
||||
if (parameter === 1) {
|
||||
this._segment = curve._segment2;
|
||||
} else if (parameter === 0 || arguments[0]) {
|
||||
} else if (parameter === 0 || _preferFirst) {
|
||||
this._segment = curve._segment1;
|
||||
} else if (parameter == null) {
|
||||
return null;
|
||||
|
@ -82,14 +82,21 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
return this._segment;
|
||||
},
|
||||
|
||||
setSegment: function(segment) {
|
||||
// NOTE: We only include this setter so the above getter can declare
|
||||
// the _preferFirst parameter without having to hide it.
|
||||
// See Strap.js beans conventions.
|
||||
this._segment = segment;
|
||||
},
|
||||
|
||||
/**
|
||||
* The curve by which the location is defined.
|
||||
*
|
||||
* @type Curve
|
||||
* @bean
|
||||
*/
|
||||
getCurve: function(/* uncached */) {
|
||||
if (!this._curve || arguments[0]) {
|
||||
getCurve: function(_uncached) {
|
||||
if (!this._curve || _uncached) {
|
||||
// If we're asked to get the curve uncached, access current curve
|
||||
// objects through segment1 / segment2. Since path splitting or
|
||||
// dividing might have happened in the meantime, try segment1's
|
||||
|
@ -102,6 +109,11 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
return this._curve;
|
||||
},
|
||||
|
||||
setCurve: function(curve) {
|
||||
// See #setSegment()
|
||||
this._curve = curve;
|
||||
},
|
||||
|
||||
/**
|
||||
* The curve location on the intersecting curve, if this location is the
|
||||
* result of a call to {@link PathItem#getIntersections(path)} /
|
||||
|
@ -179,14 +191,19 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
* @type Number
|
||||
* @bean
|
||||
*/
|
||||
getParameter: function(/* uncached */) {
|
||||
if ((this._parameter == null || arguments[0]) && this._point) {
|
||||
var curve = this.getCurve(arguments[0] && this._point);
|
||||
getParameter: function(_uncached) {
|
||||
if ((this._parameter == null || _uncached) && this._point) {
|
||||
var curve = this.getCurve(_uncached && this._point);
|
||||
this._parameter = curve && curve.getParameterOf(this._point);
|
||||
}
|
||||
return this._parameter;
|
||||
},
|
||||
|
||||
setParameter: function(parameter) {
|
||||
// See #setSegment()
|
||||
this._parameter = parameter;
|
||||
},
|
||||
|
||||
/**
|
||||
* The point which is defined by the {@link #curve} and
|
||||
* {@link #parameter}.
|
||||
|
@ -194,14 +211,19 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
* @type Point
|
||||
* @bean
|
||||
*/
|
||||
getPoint: function(/* uncached */) {
|
||||
if ((!this._point || arguments[0]) && this._parameter != null) {
|
||||
getPoint: function(_uncached) {
|
||||
if ((!this._point || _uncached) && this._parameter != null) {
|
||||
var curve = this.getCurve();
|
||||
this._point = curve && curve.getPointAt(this._parameter, true);
|
||||
}
|
||||
return this._point;
|
||||
},
|
||||
|
||||
setPoint: function(point) {
|
||||
// See #setSegment()
|
||||
this._point = point;
|
||||
},
|
||||
|
||||
/**
|
||||
* The tangential vector to the {@link #curve} at the given location.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -205,7 +205,7 @@ Path.inject({ statics: new function() {
|
|||
*/
|
||||
Rectangle: function(/* rectangle */) {
|
||||
var rect = Rectangle.readNamed(arguments, 'rectangle'),
|
||||
radius = Size.readNamed(arguments, 'radius', 0, 0,
|
||||
radius = Size.readNamed(arguments, 'radius', 0,
|
||||
{ readNull: true }),
|
||||
bl = rect.getBottomLeft(true),
|
||||
tl = rect.getTopLeft(true),
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -135,11 +135,10 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
_changed: function _changed(flags) {
|
||||
_changed.base.call(this, flags);
|
||||
if (flags & /*#=*/ ChangeFlag.GEOMETRY) {
|
||||
// Delete cached native Path
|
||||
delete (this._compound ? this._parent : this)._currentPath;
|
||||
delete this._length;
|
||||
// Clear cached native Path
|
||||
(this._compound ? this._parent : this)._currentPath = undefined;
|
||||
// Clockwise state becomes undefined as soon as geometry changes.
|
||||
delete this._clockwise;
|
||||
this._length = this._clockwise = undefined;
|
||||
// Curves are no longer valid
|
||||
if (this._curves) {
|
||||
for (var i = 0, l = this._curves.length; i < l; i++)
|
||||
|
@ -151,10 +150,16 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
} else if (flags & /*#=*/ ChangeFlag.STROKE) {
|
||||
// TODO: We could preserve the purely geometric bounds that are not
|
||||
// affected by stroke: _bounds.bounds and _bounds.handleBounds
|
||||
delete this._bounds;
|
||||
this._bounds = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
getStyle: function() {
|
||||
// If this path is part of a CompoundPath, use the paren't style instead
|
||||
var parent = this._parent;
|
||||
return (parent instanceof CompoundPath ? parent : this)._style;
|
||||
},
|
||||
|
||||
/**
|
||||
* The segments contained within the path.
|
||||
*
|
||||
|
@ -170,7 +175,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
this._segments.length = 0;
|
||||
this._selectedSegmentState = 0;
|
||||
// Calculate new curves next time we call getCurves()
|
||||
delete this._curves;
|
||||
this._curves = undefined;
|
||||
this._add(Segment.readAll(segments));
|
||||
if (fullySelected)
|
||||
this.setFullySelected(true);
|
||||
|
@ -243,9 +248,8 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
* @type String
|
||||
* @bean
|
||||
*/
|
||||
getPathData: function(/* precision */) {
|
||||
getPathData: function(precision) {
|
||||
var segments = this._segments,
|
||||
precision = arguments[0],
|
||||
f = Formatter.instance,
|
||||
parts = [];
|
||||
|
||||
|
@ -688,7 +692,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
* // Select the path, so we can see its segments:
|
||||
* path.selected = true;
|
||||
*/
|
||||
removeSegments: function(from, to/*, includeCurves */) {
|
||||
removeSegments: function(from, to, _includeCurves) {
|
||||
from = from || 0;
|
||||
to = Base.pick(to, this._segments.length);
|
||||
var segments = this._segments,
|
||||
|
@ -704,8 +708,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
if (segment._selectionState)
|
||||
this._updateSelection(segment, segment._selectionState, 0);
|
||||
// Clear the indices and path references of the removed segments
|
||||
delete segment._index;
|
||||
delete segment._path;
|
||||
segment._index = segment._path = null;
|
||||
}
|
||||
// Adjust the indices of the segments above.
|
||||
for (var i = from, l = segments.length; i < l; i++)
|
||||
|
@ -723,7 +726,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// Return the removed curves as well, if we're asked to include
|
||||
// them, but exclude the first curve, since that's shared with the
|
||||
// previous segment and does not connect the returned segments.
|
||||
if (arguments[2])
|
||||
if (_includeCurves)
|
||||
removed._curves = curves.slice(1);
|
||||
// Adjust segments for the curves before and after the removed ones
|
||||
this._adjustCurves(index, index);
|
||||
|
@ -1147,7 +1150,7 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
segment._index = i;
|
||||
}
|
||||
// Clear curves since it all has changed.
|
||||
delete this._curves;
|
||||
this._curves = null;
|
||||
// Flip clockwise state if it's defined
|
||||
if (this._clockwise !== undefined)
|
||||
this._clockwise = !this._clockwise;
|
||||
|
@ -1312,9 +1315,9 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
* @param {Point} point the point on the path.
|
||||
* @return {CurveLocation} the curve location of the specified point.
|
||||
*/
|
||||
getLocationOf: function(point) {
|
||||
point = Point.read(arguments);
|
||||
var curves = this.getCurves();
|
||||
getLocationOf: function(point) { // TODO: Fix argument assignment!
|
||||
var point = Point.read(arguments),
|
||||
curves = this.getCurves();
|
||||
for (var i = 0, l = curves.length; i < l; i++) {
|
||||
var loc = curves[i].getLocationOf(point);
|
||||
if (loc)
|
||||
|
@ -1572,9 +1575,9 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
* @return {CurveLocation} the location on the path that's the closest to
|
||||
* the specified point
|
||||
*/
|
||||
getNearestLocation: function(point) {
|
||||
point = Point.read(arguments);
|
||||
var curves = this.getCurves(),
|
||||
getNearestLocation: function(point) { // TODO: Fix argument assignment!
|
||||
var point = Point.read(arguments),
|
||||
curves = this.getCurves(),
|
||||
minDist = Infinity,
|
||||
minLoc = null;
|
||||
for (var i = 0, l = curves.length; i < l; i++) {
|
||||
|
@ -1619,19 +1622,13 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
* circle.position = nearestPoint;
|
||||
* }
|
||||
*/
|
||||
getNearestPoint: function(point) {
|
||||
getNearestPoint: function(point) { // TODO: Fix argument assignment!
|
||||
// We need to use point to avoid minification issues and prevent method
|
||||
// from turning into a bean (by removal of the point argument).
|
||||
point = Point.read(arguments);
|
||||
var point = Point.read(arguments);
|
||||
return this.getNearestLocation(point).getPoint();
|
||||
},
|
||||
|
||||
getStyle: function() {
|
||||
// If this path is part of a CompoundPath, use the paren't style instead
|
||||
var parent = this._parent;
|
||||
return (parent && parent instanceof CompoundPath ? parent : this)._style;
|
||||
},
|
||||
|
||||
// DOCS: toShape
|
||||
|
||||
toShape: function(insert) {
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -15,6 +15,11 @@
|
|||
// from "Graphics Gems", Academic Press, 1990
|
||||
// Modifications and optimisations of original algorithm by Juerg Lehni.
|
||||
|
||||
/**
|
||||
* @name PathFitter
|
||||
* @class
|
||||
* @private
|
||||
*/
|
||||
var PathFitter = Base.extend({
|
||||
initialize: function(path, error) {
|
||||
this.points = [];
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name PathFlattener
|
||||
* @class
|
||||
* @private
|
||||
*/
|
||||
var PathFlattener = Base.extend({
|
||||
initialize: function(path) {
|
||||
this.curves = []; // The curve values as returned by getValues()
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -197,6 +197,8 @@ PathItem.inject(new function() { // FIXME: Is new necessary?
|
|||
// split at intersections.
|
||||
return /** @lends Path# */{
|
||||
/**
|
||||
* {@grouptitle Boolean Path Operations}
|
||||
*
|
||||
* Merges the geometry of the specified path from this path's
|
||||
* geometry and returns the result as a new path item.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -31,7 +31,12 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
|||
* of {@link CurveLocation} objects. {@link CompoundPath} items are also
|
||||
* supported.
|
||||
*
|
||||
* @param {PathItem} path the other item to find the intersections to.
|
||||
* @name PathItem#getIntersections(path, sorted)
|
||||
* @function
|
||||
*
|
||||
* @param {PathItem} path the other item to find the intersections with
|
||||
* @param {Boolean} [sorted=true] controls wether to sort the results by
|
||||
* offset
|
||||
* @return {CurveLocation[]} the locations of all intersection between the
|
||||
* paths
|
||||
* @example {@paperscript}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -181,8 +181,8 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
return this._point;
|
||||
},
|
||||
|
||||
setPoint: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setPoint: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
// Do not replace the internal object but update it instead, so
|
||||
// references to it are kept alive.
|
||||
this._point.set(point.x, point.y);
|
||||
|
@ -199,8 +199,8 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
return this._handleIn;
|
||||
},
|
||||
|
||||
setHandleIn: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setHandleIn: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
// See #setPoint:
|
||||
this._handleIn.set(point.x, point.y);
|
||||
// Update corner accordingly
|
||||
|
@ -218,10 +218,10 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
return this._handleOut;
|
||||
},
|
||||
|
||||
setHandleOut: function(point) {
|
||||
setHandleOut: function(/* point */) {
|
||||
// We need to use point to avoid minification issues and prevent method
|
||||
// from turning into a bean (by removal of the point argument).
|
||||
point = Point.read(arguments);
|
||||
var point = Point.read(arguments);
|
||||
// See #setPoint:
|
||||
this._handleOut.set(point.x, point.y);
|
||||
// Update corner accordingly
|
||||
|
@ -310,26 +310,24 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
* // Select the third segment point:
|
||||
* path.segments[2].selected = true;
|
||||
*/
|
||||
isSelected: function(/* point */) {
|
||||
var point = arguments[0], // Hidden, only used in SegmentPoint
|
||||
state = this._selectionState;
|
||||
return !point ? !!(state & /*#=*/ SelectionState.SEGMENT)
|
||||
: point === this._point ? !!(state & /*#=*/ SelectionState.POINT)
|
||||
: point === this._handleIn ? !!(state & /*#=*/ SelectionState.HANDLE_IN)
|
||||
: point === this._handleOut ? !!(state & /*#=*/ SelectionState.HANDLE_OUT)
|
||||
isSelected: function(_point) {
|
||||
var state = this._selectionState;
|
||||
return !_point ? !!(state & /*#=*/ SelectionState.SEGMENT)
|
||||
: _point === this._point ? !!(state & /*#=*/ SelectionState.POINT)
|
||||
: _point === this._handleIn ? !!(state & /*#=*/ SelectionState.HANDLE_IN)
|
||||
: _point === this._handleOut ? !!(state & /*#=*/ SelectionState.HANDLE_OUT)
|
||||
: false;
|
||||
},
|
||||
|
||||
setSelected: function(selected /*, point */) {
|
||||
var point = arguments[1]; // Hidden, only used in SegmentPoint
|
||||
path = this._path,
|
||||
setSelected: function(selected, _point) {
|
||||
var path = this._path,
|
||||
selected = !!selected, // convert to boolean
|
||||
state = this._selectionState,
|
||||
oldState = state,
|
||||
flag = !point ? /*#=*/ SelectionState.SEGMENT
|
||||
: point === this._point ? /*#=*/ SelectionState.POINT
|
||||
: point === this._handleIn ? /*#=*/ SelectionState.HANDLE_IN
|
||||
: point === this._handleOut ? /*#=*/ SelectionState.HANDLE_OUT
|
||||
flag = !_point ? /*#=*/ SelectionState.SEGMENT
|
||||
: _point === this._point ? /*#=*/ SelectionState.POINT
|
||||
: _point === this._handleIn ? /*#=*/ SelectionState.HANDLE_IN
|
||||
: _point === this._handleOut ? /*#=*/ SelectionState.HANDLE_OUT
|
||||
: 0;
|
||||
if (selected) {
|
||||
state |= flag;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -24,14 +24,17 @@ var SegmentPoint = Point.extend({
|
|||
x = y = 0;
|
||||
} else if ((x = point[0]) !== undefined) { // Array-like
|
||||
y = point[1];
|
||||
} else {
|
||||
} else {
|
||||
// So we don't have to modify the point argument which causes
|
||||
// deoptimization:
|
||||
var pt = point;
|
||||
// If not Point-like already, read Point from arguments
|
||||
if ((x = point.x) === undefined) {
|
||||
point = Point.read(arguments);
|
||||
x = point.x;
|
||||
if ((x = pt.x) === undefined) {
|
||||
pt = Point.read(arguments);
|
||||
x = pt.x;
|
||||
}
|
||||
y = point.y;
|
||||
selected = point.selected;
|
||||
y = pt.y;
|
||||
selected = pt.selected;
|
||||
}
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -290,11 +290,11 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
* information about what exactly was hit or {@code null} if nothing was
|
||||
* hit
|
||||
*/
|
||||
hitTest: function(point, options) {
|
||||
hitTest: function(/* point, options */) {
|
||||
// We don't need to do this here, but it speeds up things since we won't
|
||||
// repeatetly convert in Item#hitTest() then.
|
||||
point = Point.read(arguments);
|
||||
options = HitResult.getOptions(Base.read(arguments));
|
||||
var point = Point.read(arguments),
|
||||
options = HitResult.getOptions(Base.read(arguments));
|
||||
// Loop backwards, so layers that get drawn last are tested first
|
||||
for (var i = this.layers.length - 1; i >= 0; i--) {
|
||||
var res = this.layers[i].hitTest(point, options);
|
||||
|
@ -335,12 +335,15 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
* a JSON data string.
|
||||
*
|
||||
* The options object offers control over some aspects of the SVG export:
|
||||
* <b>options.asString:</b> {@code Boolean} – wether the JSON is returned as
|
||||
* a {@code Object} or a {@code String}.
|
||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||
* digits in numbers used in JSON data.
|
||||
*
|
||||
* @name Project#exportJSON
|
||||
* @function
|
||||
* @param {Object} [options={ precision: 5 }] the serialization options
|
||||
* @param {Object} [options={ asString: true, precision: 5 }] the
|
||||
* serialization options
|
||||
* @return {String} the exported JSON data
|
||||
*/
|
||||
|
||||
|
@ -364,8 +367,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
* all contained in one top level SVG group node.
|
||||
*
|
||||
* The options object offers control over some aspects of the SVG export:
|
||||
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a String
|
||||
* is to be returned.
|
||||
* <b>options.asString:</b> {@code Boolean} – wether a SVG node or a
|
||||
* {@code String} is to be returned.
|
||||
* <b>options.precision:</b> {@code Number} – the amount of fractional
|
||||
* digits in numbers used in SVG data.
|
||||
* <b>options.matchShapes:</b> {@code Boolean} – wether imported path
|
||||
|
@ -379,6 +382,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
* @return {SVGSVGElement} the project converted to an SVG node
|
||||
*/
|
||||
|
||||
// DOCS: Document importSVG('file.svg', callback);
|
||||
/**
|
||||
* Converts the provided SVG content into Paper.js items and adds them to
|
||||
* the active layer of this project.
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -115,19 +115,19 @@ var Symbol = Base.extend(/** @lends Symbol# */{
|
|||
return this._definition;
|
||||
},
|
||||
|
||||
setDefinition: function(item /*, dontCenter */) {
|
||||
setDefinition: function(item, _dontCenter) {
|
||||
// Make sure we're not steatling another symbol's definition
|
||||
if (item._parentSymbol)
|
||||
item = item.clone();
|
||||
// Remove previous definition's reference to this symbol
|
||||
if (this._definition)
|
||||
delete this._definition._parentSymbol;
|
||||
this._definition._parentSymbol = null;
|
||||
this._definition = item;
|
||||
// Remove item from DOM, as it's embedded in Symbol now.
|
||||
item.remove();
|
||||
item.setSelected(false);
|
||||
// Move position to 0, 0, so it's centered when placed.
|
||||
if (!arguments[1])
|
||||
if (!_dontCenter)
|
||||
item.setPosition(new Point());
|
||||
item._parentSymbol = this;
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -132,8 +132,9 @@ var Color = Base.extend(new function() {
|
|||
},
|
||||
|
||||
'hsb-rgb': function(h, s, b) {
|
||||
var h = (h / 60) % 6, // Scale to 0..6
|
||||
i = Math.floor(h), // 0..5
|
||||
// Scale h to 0..6 with modulo for negative values too
|
||||
h = (((h / 60) % 6) + 6) % 6;
|
||||
var i = Math.floor(h), // 0..5
|
||||
f = h - i,
|
||||
i = hsbIndices[i],
|
||||
v = [
|
||||
|
@ -164,7 +165,8 @@ var Color = Base.extend(new function() {
|
|||
},
|
||||
|
||||
'hsl-rgb': function(h, s, l) {
|
||||
h /= 360;
|
||||
// Scale h to 0..1 with modulo for negative values too
|
||||
h = (((h / 360) % 1) + 1) % 1;
|
||||
if (s === 0)
|
||||
return [l, l, l];
|
||||
var t3s = [ h + 1 / 3, h, h - 1 / 3 ],
|
||||
|
@ -236,9 +238,8 @@ var Color = Base.extend(new function() {
|
|||
parser = componentParsers[type][index] = name === 'gradient'
|
||||
? function(value) {
|
||||
var current = this._components[0];
|
||||
value = Gradient.read(
|
||||
Array.isArray(value) ? value : arguments,
|
||||
0, 0, { readNull: true });
|
||||
value = Gradient.read(Array.isArray(value) ? value
|
||||
: arguments, 0, { readNull: true });
|
||||
if (current !== value) {
|
||||
if (current)
|
||||
current._removeOwner(this);
|
||||
|
@ -247,23 +248,20 @@ var Color = Base.extend(new function() {
|
|||
}
|
||||
return value;
|
||||
}
|
||||
: name === 'hue'
|
||||
? function(value) {
|
||||
// Keep negative values within modulo 360 too:
|
||||
return isNaN(value) ? 0
|
||||
: ((value % 360) + 360) % 360;
|
||||
: type === 'gradient'
|
||||
? function(/* value */) {
|
||||
return Point.read(arguments, 0, {
|
||||
readNull: name === 'highlight',
|
||||
clone: true
|
||||
});
|
||||
}
|
||||
: type === 'gradient'
|
||||
? function(/* value */) {
|
||||
return Point.read(arguments, 0, 0, {
|
||||
readNull: name === 'highlight',
|
||||
clone: true
|
||||
});
|
||||
}
|
||||
: function(value) {
|
||||
return isNaN(value) ? 0
|
||||
: Math.min(Math.max(value, 0), 1);
|
||||
};
|
||||
: function(value) {
|
||||
// NOTE: We don't clamp values here, they're only
|
||||
// clamped once the actual CSS values are produced.
|
||||
// Gotta love the fact that isNaN(null) is false,
|
||||
// while isNaN(undefined) is true.
|
||||
return value == null || isNaN(value) ? 0 : value;
|
||||
};
|
||||
|
||||
this['get' + part] = function() {
|
||||
return this._type === type
|
||||
|
@ -401,7 +399,7 @@ var Color = Base.extend(new function() {
|
|||
* // the path and to position the gradient color:
|
||||
* var topLeft = view.center - [80, 80];
|
||||
* var bottomRight = view.center + [80, 80];
|
||||
*
|
||||
*
|
||||
* var path = new Path.Rectangle({
|
||||
* topLeft: topLeft,
|
||||
* bottomRight: bottomRight,
|
||||
|
@ -489,7 +487,6 @@ var Color = Base.extend(new function() {
|
|||
var slice = Array.prototype.slice,
|
||||
args = arguments,
|
||||
read = 0,
|
||||
parse = true,
|
||||
type,
|
||||
components,
|
||||
alpha,
|
||||
|
@ -520,8 +517,6 @@ var Color = Base.extend(new function() {
|
|||
}
|
||||
}
|
||||
if (!components) {
|
||||
// Only parse values if we're not told to not do so
|
||||
parse = !(this.__options && this.__options.dontParse);
|
||||
// Determine if there is a values array
|
||||
values = argType === 'number'
|
||||
? args
|
||||
|
@ -586,7 +581,7 @@ var Color = Base.extend(new function() {
|
|||
: 'rgb';
|
||||
// Convert to array and parse in one loop, for efficiency
|
||||
var properties = types[type];
|
||||
parsers = parse && componentParsers[type];
|
||||
parsers = componentParsers[type];
|
||||
this._components = components = [];
|
||||
for (var i = 0, l = properties.length; i < l; i++) {
|
||||
var value = arg[properties[i]];
|
||||
|
@ -600,8 +595,7 @@ var Color = Base.extend(new function() {
|
|||
radial: arg.radial
|
||||
};
|
||||
}
|
||||
if (parse)
|
||||
value = parsers[i].call(this, value);
|
||||
value = parsers[i].call(this, value);
|
||||
if (value != null)
|
||||
components[i] = value;
|
||||
}
|
||||
|
@ -623,9 +617,7 @@ var Color = Base.extend(new function() {
|
|||
this._components = components = [];
|
||||
var parsers = componentParsers[this._type];
|
||||
for (var i = 0, l = parsers.length; i < l; i++) {
|
||||
var value = values && values[i];
|
||||
if (parse)
|
||||
value = parsers[i].call(this, value);
|
||||
var value = parsers[i].call(this, values && values[i]);
|
||||
if (value != null)
|
||||
components[i] = value;
|
||||
}
|
||||
|
@ -668,7 +660,7 @@ var Color = Base.extend(new function() {
|
|||
// Convert to and from rgb if no direct converter exists
|
||||
: converters['rgb-' + type].apply(this,
|
||||
converters[this._type + '-rgb'].apply(this,
|
||||
this._components));
|
||||
this._components));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -764,17 +756,19 @@ var Color = Base.extend(new function() {
|
|||
* @return {Boolean} {@true if the colors are the same}
|
||||
*/
|
||||
equals: function(color) {
|
||||
if (Base.isPlainValue(color))
|
||||
color = Color.read(arguments);
|
||||
return color === this || color && this._class === color._class
|
||||
&& this._type === color._type
|
||||
&& this._alpha === color._alpha
|
||||
&& Base.equals(this._components, color._components)
|
||||
var col = Base.isPlainValue(color)
|
||||
? Color.read(arguments)
|
||||
: color;
|
||||
return col === this || col && this._class === col._class
|
||||
&& this._type === col._type
|
||||
&& this._alpha === col._alpha
|
||||
&& Base.equals(this._components, col._components)
|
||||
|| false;
|
||||
},
|
||||
|
||||
/**
|
||||
* @name Color#clone
|
||||
* @function
|
||||
*
|
||||
* Returns a copy of the color object.
|
||||
*
|
||||
|
@ -814,13 +808,16 @@ var Color = Base.extend(new function() {
|
|||
// TODO: Support HSL / HSLA CSS3 colors directly, without conversion
|
||||
var components = this._convert('rgb'),
|
||||
alpha = hex || this._alpha == null ? 1 : this._alpha;
|
||||
function convert(val) {
|
||||
return Math.round((val < 0 ? 0 : val > 1 ? 1 : val) * 255);
|
||||
}
|
||||
components = [
|
||||
Math.round(components[0] * 255),
|
||||
Math.round(components[1] * 255),
|
||||
Math.round(components[2] * 255)
|
||||
convert(components[0]),
|
||||
convert(components[1]),
|
||||
convert(components[2])
|
||||
];
|
||||
if (alpha < 1)
|
||||
components.push(alpha);
|
||||
components.push(alpha < 0 ? 0 : alpha);
|
||||
return hex
|
||||
? '#' + ((1 << 24) + (components[0] << 16)
|
||||
+ (components[1] << 8)
|
||||
|
@ -1118,48 +1115,32 @@ var Color = Base.extend(new function() {
|
|||
}
|
||||
});
|
||||
}, new function() {
|
||||
function clamp(value, hue) {
|
||||
return value < 0
|
||||
? 0
|
||||
: hue && value > 360
|
||||
? 360
|
||||
: !hue && value > 1
|
||||
? 1
|
||||
: value;
|
||||
}
|
||||
|
||||
var operators = {
|
||||
add: function(a, b, hue) {
|
||||
return clamp(a + b, hue);
|
||||
add: function(a, b) {
|
||||
return a + b;
|
||||
},
|
||||
|
||||
subtract: function(a, b, hue) {
|
||||
return clamp(a - b, hue);
|
||||
subtract: function(a, b) {
|
||||
return a - b;
|
||||
},
|
||||
|
||||
multiply: function(a, b, hue) {
|
||||
return clamp(a * b, hue);
|
||||
multiply: function(a, b) {
|
||||
return a * b;
|
||||
},
|
||||
|
||||
divide: function(a, b, hue) {
|
||||
return clamp(a / b, hue);
|
||||
divide: function(a, b) {
|
||||
return a / b;
|
||||
}
|
||||
};
|
||||
|
||||
return Base.each(operators, function(operator, name) {
|
||||
// Tell the argument reader not to parse values for multiply and divide,
|
||||
// so the are not clamped yet.
|
||||
var options = { dontParse: /^(multiply|divide)$/.test(name) };
|
||||
|
||||
this[name] = function(color) {
|
||||
color = Color.read(arguments, 0, 0, options);
|
||||
color = Color.read(arguments);
|
||||
var type = this._type,
|
||||
properties = this._properties,
|
||||
components1 = this._components,
|
||||
components2 = color._convert(type);
|
||||
for (var i = 0, l = components1.length; i < l; i++)
|
||||
components2[i] = operator(components1[i], components2[i],
|
||||
properties[i] === 'hue');
|
||||
components2[i] = operator(components1[i], components2[i]);
|
||||
return new Color(type, components2,
|
||||
this._alpha != null
|
||||
? operator(this._alpha, color.getAlpha())
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -113,7 +113,7 @@ var Gradient = Base.extend(/** @lends Gradient# */{
|
|||
if (index != -1) {
|
||||
this._owners.splice(index, 1);
|
||||
if (this._owners.length === 0)
|
||||
delete this._owners;
|
||||
this._owners = undefined;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -142,7 +142,7 @@ var Gradient = Base.extend(/** @lends Gradient# */{
|
|||
// this gradient as their owner.
|
||||
if (this.stops) {
|
||||
for (var i = 0, l = this._stops.length; i < l; i++)
|
||||
delete this._stops[i]._owner;
|
||||
this._stops[i]._owner = undefined;
|
||||
}
|
||||
if (stops.length < 2)
|
||||
throw new Error(
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -147,7 +147,7 @@ var Style = Base.extend(new function() {
|
|||
if (old != value) {
|
||||
if (isColor) {
|
||||
if (old)
|
||||
delete old._owner;
|
||||
old._owner = undefined;
|
||||
if (value && value.constructor === Color) {
|
||||
// Clone color if it already has an owner.
|
||||
// NOTE: If value is not a Color, it is only
|
||||
|
@ -168,13 +168,13 @@ var Style = Base.extend(new function() {
|
|||
}
|
||||
};
|
||||
|
||||
fields[get] = function(/* dontMerge */) {
|
||||
fields[get] = function(_dontMerge) {
|
||||
var value,
|
||||
children = this._item && this._item._children;
|
||||
// If this item has children, walk through all of them and see if
|
||||
// they all have the same style.
|
||||
// If true is passed for dontMerge, don't merge children styles
|
||||
if (!children || children.length === 0 || arguments[0]
|
||||
// If true is passed for _dontMerge, don't merge children styles
|
||||
if (!children || children.length === 0 || _dontMerge
|
||||
|| this._item instanceof CompoundPath) {
|
||||
var value = this._values[key];
|
||||
if (value === undefined) {
|
||||
|
@ -184,8 +184,8 @@ var Style = Base.extend(new function() {
|
|||
this._values[key] = value;
|
||||
} else if (isColor && !(value && value.constructor === Color)) {
|
||||
// Convert to a Color and stored result of conversion.
|
||||
this._values[key] = value = Color.read(
|
||||
[value], 0, 0, { readNull: true, clone: true });
|
||||
this._values[key] = value = Color.read([value], 0,
|
||||
{ readNull: true, clone: true });
|
||||
if (value)
|
||||
value._owner = this._item;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -55,24 +55,25 @@ new function() {
|
|||
attrs[center ? 'cy' : 'y'] = point.y;
|
||||
trans = null;
|
||||
}
|
||||
if (matrix.isIdentity())
|
||||
return attrs;
|
||||
// See if we can decompose the matrix and can formulate it as a simple
|
||||
// translate/scale/rotate command sequence.
|
||||
var decomposed = matrix.decompose();
|
||||
if (decomposed && !decomposed.shearing) {
|
||||
var parts = [],
|
||||
angle = decomposed.rotation,
|
||||
scale = decomposed.scaling;
|
||||
if (trans && !trans.isZero())
|
||||
parts.push('translate(' + formatter.point(trans) + ')');
|
||||
if (angle)
|
||||
parts.push('rotate(' + formatter.number(angle) + ')');
|
||||
if (!Numerical.isZero(scale.x - 1) || !Numerical.isZero(scale.y - 1))
|
||||
parts.push('scale(' + formatter.point(scale) +')');
|
||||
attrs.transform = parts.join(' ');
|
||||
} else {
|
||||
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
|
||||
if (!matrix.isIdentity()) {
|
||||
// See if we can decompose the matrix and can formulate it as a
|
||||
// simple translate/scale/rotate command sequence.
|
||||
var decomposed = matrix.decompose();
|
||||
if (decomposed && !decomposed.shearing) {
|
||||
var parts = [],
|
||||
angle = decomposed.rotation,
|
||||
scale = decomposed.scaling;
|
||||
if (trans && !trans.isZero())
|
||||
parts.push('translate(' + formatter.point(trans) + ')');
|
||||
if (angle)
|
||||
parts.push('rotate(' + formatter.number(angle) + ')');
|
||||
if (!Numerical.isZero(scale.x - 1)
|
||||
|| !Numerical.isZero(scale.y - 1))
|
||||
parts.push('scale(' + formatter.point(scale) +')');
|
||||
attrs.transform = parts.join(' ');
|
||||
} else {
|
||||
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -534,13 +534,14 @@ new function() {
|
|||
}
|
||||
|
||||
if (isRoot) {
|
||||
// See if it's a string but handle markup separately
|
||||
if (typeof source === 'string' && !/^.*</.test(source)) {
|
||||
/*#*/ if (__options.environment == 'browser') {
|
||||
// First see if we're meant to import an element with the given
|
||||
// id.
|
||||
node = document.getElementById(source);
|
||||
// Check if the string does not represent SVG data, in which
|
||||
// case it must be a url of a SVG to be loaded.
|
||||
// case it must be the URL of a SVG to be loaded.
|
||||
if (node) {
|
||||
source = null;
|
||||
} else {
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -75,8 +75,8 @@ var PointText = TextItem.extend(/** @lends PointText# */{
|
|||
return new LinkedPoint(point.x, point.y, this, 'setPoint');
|
||||
},
|
||||
|
||||
setPoint: function(point) {
|
||||
point = Point.read(arguments);
|
||||
setPoint: function(/* point */) {
|
||||
var point = Point.read(arguments);
|
||||
this.translate(point.subtract(this._matrix.getTranslation()));
|
||||
},
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -45,7 +45,7 @@
|
|||
var Tool = PaperScopeItem.extend(/** @lends Tool# */{
|
||||
_class: 'Tool',
|
||||
_list: 'tools',
|
||||
_reference: '_tool', // PaperScope has accessor for #tool
|
||||
_reference: 'tool',
|
||||
_events: [ 'onActivate', 'onDeactivate', 'onEditOptions',
|
||||
'onMouseDown', 'onMouseUp', 'onMouseDrag', 'onMouseMove',
|
||||
'onKeyDown', 'onKeyUp' ],
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -143,7 +143,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
|||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
return /** @lends CanvasView# */{
|
||||
/**
|
||||
* Returns true if event was stopped, false otherwise, whether handler
|
||||
* was called or not!
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -74,7 +74,7 @@ var Key = new function() {
|
|||
type = down ? 'keydown' : 'keyup',
|
||||
view = View._focused,
|
||||
scope = view && view.isVisible() && view._scope,
|
||||
tool = scope && scope._tool,
|
||||
tool = scope && scope.tool,
|
||||
name;
|
||||
keyMap[key] = down;
|
||||
// Detect modifiers and mark them as pressed / released
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -290,9 +290,9 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
return new LinkedSize(size.width, size.height, this, 'setViewSize');
|
||||
},
|
||||
|
||||
setViewSize: function(size) {
|
||||
size = Size.read(arguments);
|
||||
var delta = size.subtract(this._viewSize);
|
||||
setViewSize: function(/* size */) {
|
||||
var size = Size.read(arguments),
|
||||
delta = size.subtract(this._viewSize);
|
||||
if (delta.isZero())
|
||||
return;
|
||||
this._viewSize.set(size.width, size.height);
|
||||
|
@ -334,8 +334,8 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
* @type Size
|
||||
* @bean
|
||||
*/
|
||||
getSize: function(/* dontLink */) {
|
||||
return this.getBounds().getSize(arguments[0]);
|
||||
getSize: function() {
|
||||
return this.getBounds().getSize();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -344,8 +344,8 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
* @type Point
|
||||
* @bean
|
||||
*/
|
||||
getCenter: function(/* dontLink */) {
|
||||
return this.getBounds().getCenter(arguments[0]);
|
||||
getCenter: function() {
|
||||
return this.getBounds().getCenter();
|
||||
},
|
||||
|
||||
setCenter: function(center) {
|
||||
|
@ -447,7 +447,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
|
||||
viewToProject: function(/* point */) {
|
||||
return this._matrix._inverseTransform(Point.read(arguments));
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* {@grouptitle Event Handlers}
|
||||
|
@ -664,7 +664,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
// Always first call the view's mouse handlers, as required by
|
||||
// CanvasView, and then handle the active tool, if any.
|
||||
view._handleEvent('mousedown', point, event);
|
||||
if (tool = view._scope._tool)
|
||||
if (tool = view._scope.tool)
|
||||
tool._handleEvent('mousedown', point, event);
|
||||
// In the end we always call update(), which only updates the view if
|
||||
// anything has changed in the above calls.
|
||||
|
@ -673,7 +673,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
|
||||
function handleMouseMove(view, point, event) {
|
||||
view._handleEvent('mousemove', point, event);
|
||||
var tool = view._scope._tool;
|
||||
var tool = view._scope.tool;
|
||||
if (tool) {
|
||||
// If there's no onMouseDrag, fire onMouseMove while dragging.
|
||||
tool._handleEvent(dragging && tool.responds('mousedrag')
|
||||
|
@ -706,8 +706,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
}
|
||||
if (view) {
|
||||
var point = viewToProject(view, event);
|
||||
if (dragging || new Rectangle(new Point(),
|
||||
view.getViewSize()).contains(point))
|
||||
if (dragging || view.getBounds().contains(point))
|
||||
tool = handleMouseMove(view, point, event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -12,9 +12,10 @@
|
|||
|
||||
/**
|
||||
* @name Formatter
|
||||
* @class
|
||||
* @private
|
||||
*/
|
||||
var Formatter = Base.extend({
|
||||
var Formatter = Base.extend(/** @lends Formatter# */{
|
||||
/**
|
||||
* @param {Number} [precision=5] the amount of fractional digits.
|
||||
*/
|
||||
|
|
|
@ -2,14 +2,19 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name Numerical
|
||||
* @namespace
|
||||
* @private
|
||||
*/
|
||||
var Numerical = new function() {
|
||||
|
||||
// Lookup tables for abscissas and weights with values for n = 2 .. 16.
|
||||
|
@ -75,7 +80,7 @@ var Numerical = new function() {
|
|||
};
|
||||
}
|
||||
|
||||
return {
|
||||
return /** @lends Numerical */{
|
||||
TOLERANCE: TOLERANCE,
|
||||
// Precision when comparing against 0
|
||||
EPSILON: EPSILON,
|
||||
|
@ -114,13 +119,13 @@ var Numerical = new function() {
|
|||
findRoot: function(f, df, x, a, b, n, tolerance) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
var fx = f(x),
|
||||
dx = fx / df(x);
|
||||
// Calculate a new candidate with the Newton-Raphson method.
|
||||
dx = fx / df(x),
|
||||
nx = x - dx;
|
||||
// See if we can trust the Newton-Raphson result. If not we use
|
||||
// bisection to find another candiate for Newton's method.
|
||||
if (abs(dx) < tolerance)
|
||||
return x;
|
||||
// Generate a candidate for Newton's method.
|
||||
var nx = x - dx;
|
||||
return nx;
|
||||
// Update the root-bounding interval and test for containment of
|
||||
// the candidate. If candidate is outside the root-bounding
|
||||
// interval, use bisection instead.
|
||||
|
@ -135,6 +140,9 @@ var Numerical = new function() {
|
|||
x = nx >= b ? 0.5 * (a + b) : nx;
|
||||
}
|
||||
}
|
||||
// Return the best result even though we haven't gotten close
|
||||
// enough to the root... (In paper.js this never seems to happen).
|
||||
return x;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -401,5 +401,5 @@ function compareProjects(project, project2) {
|
|||
function createSVG(xml) {
|
||||
return new DOMParser().parseFromString(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg">' + xml + '</svg>',
|
||||
'application/xml');
|
||||
'text/xml');
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
@ -51,6 +51,14 @@ test('Set color to array', function() {
|
|||
});
|
||||
|
||||
test('Creating Colors', function() {
|
||||
compareColors(new Color(), new Color(0, 0, 0),
|
||||
'Color with no arguments should be black');
|
||||
|
||||
compareColors(new Color('black'), new Color(0, 0, 0),
|
||||
'Color from name (black)');
|
||||
|
||||
compareColors(new Color('red'), new Color(1, 0, 0),
|
||||
'Color from name (red)');
|
||||
|
||||
compareColors(new Color('#ff0000'), new Color(1, 0, 0),
|
||||
'Color from hex code');
|
||||
|
@ -203,7 +211,7 @@ test('Saturation from black rgb', function() {
|
|||
test('Color#add', function() {
|
||||
var color = new Color(0, 1, 1);
|
||||
compareColors(color.add([1, 0, 0]), [1, 1, 1]);
|
||||
compareColors(color.add([1, 0.5, 0]), [1, 1, 1]);
|
||||
compareColors(color.add([1, 0.5, 0]), [1, 1.5, 1]);
|
||||
var color = new Color(0, 0.5, 0);
|
||||
compareColors(color.add(0.5), [0.5, 1, 0.5]);
|
||||
});
|
||||
|
@ -229,7 +237,7 @@ test('Color#divide', function() {
|
|||
var color = new Color(1, 1, 1);
|
||||
compareColors(color.divide([1, 2, 4]), [1, 0.5, 0.25]);
|
||||
var color = new Color(1, 0.5, 0.25);
|
||||
compareColors(color.divide(0.25), [1, 1, 1]);
|
||||
compareColors(color.divide(0.25), [4, 2, 1]);
|
||||
var color = new Color(1, 1, 1);
|
||||
compareColors(color.divide(4), [0.25, 0.25, 0.25]);
|
||||
});
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
||||
* http://paperjs.org/
|
||||
*
|
||||
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
||||
* http://lehni.org/ & http://jonathanpuckey.com/
|
||||
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
|
||||
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
||||
*
|
||||
* Distributed under the MIT license. See LICENSE file for details.
|
||||
*
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue