mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
340a1e2a5f
And create separate versions of methods that receive curve-time arguments instead of offsets. Curve#getNormalAt(time, true) -> #getNormalAtTime(true) Curve#divide() -> #divideAt(offset) / #divideAtTime(time) Curve#split() -> #splitAt(offset) / #splitAtTime(time) Curve#getParameterAt(offset) -> #getTimeAt(offset) Curve#getParameterOf(point) -> getTimeOf(point) Curve#getPointAt(time, true) -> #getPointAtTime(time) Curve#getTangentAt(time, true) -> #getTangenttTime(time) Curve#getNormalAt(time, true) -> #getNormalAtTime(time) Curve#getCurvatureAt(time, true) -> #getCurvatureAtTime(time) CurveLocation#parameter -> #time Path#split(offset/location) -> #splitAt(offset/location) Closes #563
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
/*
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
* http://paperjs.org/
|
|
*
|
|
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
|
*
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
*
|
|
* All rights reserved.
|
|
*/
|
|
|
|
QUnit.module('Path Length');
|
|
|
|
test('path.length', function() {
|
|
var path = new Path([
|
|
new Segment(new Point(121, 334), new Point(-19, 38), new Point(30.7666015625, -61.53369140625)),
|
|
new Segment(new Point(248, 320), new Point(-42, -74), new Point(42, 74))
|
|
]);
|
|
|
|
var length = path.length;
|
|
equals(length, 172.10112809179614, 'path.length');
|
|
|
|
var t = path.curves[0].getTimeAt(length / 4);
|
|
equals(t, 0.2255849553116685, 'path.curves[0].getTimeAt(length / 4)');
|
|
});
|
|
|
|
test('curve.getTimeAt() with straight curve', function() {
|
|
var path = new Path();
|
|
path.moveTo(100, 100);
|
|
path.lineTo(500, 500);
|
|
var curve = path.curves[0];
|
|
var length = curve.length;
|
|
var t = curve.getTimeAt(length / 3);
|
|
equals(t, 0.3869631475722452);
|
|
});
|