Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paperjs: update documentation on Mathematical Operations #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions tutorials/geometry/mathematical-operations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,45 @@ <h1>Mathematical Operations</h1><p>
// Create a second point that is 4 times the first one.
// This is the same as creating a new point with x and y
// of point1 multiplied by 4:
var point2 = point1 * 4;
var point2 = point1.multiply(4);
console.log(point2); // { x: 40, y: 80 }

// Now we calculate the difference between the two.
var point3 = point2 - point1;
var point3 = point2.subtract(point1);
console.log(point3); // { x: 30, y: 60 }

// Create yet another point, with a numeric value added to point3:
var point4 = point3 + 30;
var point4 = point3.add(30);
console.log(point4); // { x: 60, y: 90 }

// How about a third of that?
var point5 = point4 / 3;
var point5 = point4.divide(3);
console.log(point5); // { x: 20, y: 30 }

// Multiplying two points with each other multiplies each
// coordinate seperately
var point6 = point5 * new Point(3, 2);
var point6 = point5.multiply(new Point(3, 2));
console.log(point6); // { x: 60, y: 60 }
</pre>
<p>
These operators work just fine in conjunction with the feature of object conversion as described in the <a href="/tutorials/geometry/object-conversion/">Object Conversion</a> tutorial, as long as the object the operation is performed on is a real basic type:
</p>
<pre class="code">
var point1 = new Point(10, 20);
var point2 = point1 + { x: 100, y: 100 };
var point2 = point1.add({ x: 100, y: 100 });
console.log(point2); // { x: 110, y: 120 }

// Adding size objects to points work too,
// forcing them to be converted to a point first
var point3 = point2 + new Size(50, 100);
var point3 = point2.add(new Size(50, 100));
console.log(point3); // { x: 160, y: 220 }

// And using the object notation for size works just as well:
var point4 = point3 + { width: 40, height: 80 };
var point4 = point3.add({ width: 40, height: 80 });
console.log(point4); // { x: 200, y: 300 }

// How about adding a point in array notation instead?
var point5 = point4 + [100, 0];
var point5 = point4.add([100, 0]);
console.log(point5); // { x: 300, y: 300 }
</pre>
<section id="math-functions"><a name="math-functions" title="Math Functions" class="anchor"><h2>Math Functions</h2></a></section>
Expand Down Expand Up @@ -141,11 +141,11 @@ <h1>Mathematical Operations</h1><p>
<pre class="code">
// Create a point whose x is between 0 and 50,
// and y is between 0 and 100
var point = new Point(50, 100) * Point.random();
var point = new Point(50, 100).multiply(Point.random());

// Create a size whose width is between 0 and 50,
// and height is between 0 and 100
var size = new Size(50, 100) * Size.random();
var size = new Size(50, 100).multiply(Size.random());
</pre>
</article>
<aside>
Expand Down