2011-07-01 06:17:45 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2020-05-23 16:24:42 -04:00
|
|
|
* Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
|
|
|
|
* http://juerglehni.com/ & https://puckey.studio/
|
2011-07-01 06:17:45 -04:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-01-27 13:57:07 -05:00
|
|
|
QUnit.module('Segment');
|
|
|
|
|
2016-07-03 07:30:56 -04:00
|
|
|
test('new Segment()', function() {
|
|
|
|
var segment = new Segment(null, null, null);
|
|
|
|
equals(segment.toString(), '{ point: { x: 0, y: 0 } }');
|
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Segment(point)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(new Point(10, 10));
|
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 } }');
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Segment(x, y)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(10, 10);
|
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 } }');
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2016-07-03 07:30:56 -04:00
|
|
|
test('new Segment(undefined)', function() {
|
|
|
|
var segment = new Segment(undefined);
|
|
|
|
equals(segment.toString(), '{ point: { x: 0, y: 0 } }');
|
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Segment(object)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment({ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } });
|
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }');
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Segment(point, handleIn, handleOut)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
|
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }');
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2016-07-03 07:30:56 -04:00
|
|
|
test('new Segment(null, null, null)', function() {
|
|
|
|
var segment = new Segment(null, null, null);
|
|
|
|
equals(segment.toString(), '{ point: { x: 0, y: 0 } }');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('new Segment(undefined, null, null)', function() {
|
|
|
|
var segment = new Segment(undefined, null, null);
|
|
|
|
equals(segment.toString(), '{ point: { x: 0, y: 0 } }');
|
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('new Segment(x, y, inX, inY, outX, outY)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(10, 10, 5, 5, 15, 15);
|
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }');
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-07-13 06:55:25 -04:00
|
|
|
test('new Segment(size)', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(new Size(10, 10));
|
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 } }');
|
2011-07-13 06:55:25 -04:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('segment.reverse()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
|
2015-09-16 12:16:48 -04:00
|
|
|
segment.reverse();
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } }');
|
2011-02-07 13:28:09 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('segment.clone()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
|
|
|
|
var clone = segment.clone();
|
|
|
|
equals(function() {
|
|
|
|
return segment == clone;
|
|
|
|
}, false);
|
2011-05-07 12:46:06 -04:00
|
|
|
|
2014-08-16 13:24:54 -04:00
|
|
|
equals(function() {
|
|
|
|
return segment.toString();
|
|
|
|
}, clone.toString());
|
2011-02-12 13:10:19 -05:00
|
|
|
});
|
|
|
|
|
2011-02-13 11:26:24 -05:00
|
|
|
test('segment.remove()', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path([10, 10], [5, 5], [10, 10]);
|
|
|
|
path.segments[1].remove();
|
|
|
|
equals(path.segments.toString(), '{ point: { x: 10, y: 10 } },{ point: { x: 10, y: 10 } }');
|
2011-04-22 05:42:07 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('segment.selected', function() {
|
2014-08-16 13:24:54 -04:00
|
|
|
var path = new Path([10, 20], [50, 100]);
|
|
|
|
path.segments[0].point.selected = true;
|
|
|
|
equals(function() {
|
|
|
|
return path.segments[0].point.selected;
|
|
|
|
}, true);
|
|
|
|
path.segments[0].point.selected = false;
|
|
|
|
equals(function() {
|
|
|
|
return path.segments[0].point.selected;
|
|
|
|
}, false);});
|