2020-05-08 22:59:35 +08:00
|
|
|
suite('Spline', function () {
|
2017-02-24 22:15:33 +08:00
|
|
|
// ======================================================
|
2020-05-08 22:59:35 +08:00
|
|
|
test('add splines', function () {
|
2017-02-24 22:15:33 +08:00
|
|
|
var stage = addStage();
|
|
|
|
var layer = new Konva.Layer();
|
|
|
|
|
|
|
|
var line1 = new Konva.Line({
|
|
|
|
points: [73, 160, 340, 23, 500, 109, 300, 109],
|
|
|
|
stroke: 'blue',
|
|
|
|
strokeWidth: 10,
|
|
|
|
lineCap: 'round',
|
|
|
|
lineJoin: 'round',
|
|
|
|
draggable: true,
|
2020-05-08 22:59:35 +08:00
|
|
|
tension: 1,
|
2013-09-08 08:57:48 +08:00
|
|
|
});
|
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
var line2 = new Konva.Line({
|
|
|
|
points: [73, 160, 340, 23, 500, 109],
|
|
|
|
stroke: 'red',
|
|
|
|
strokeWidth: 10,
|
|
|
|
lineCap: 'round',
|
|
|
|
lineJoin: 'round',
|
|
|
|
draggable: true,
|
2020-05-08 22:59:35 +08:00
|
|
|
tension: 1,
|
2017-02-24 22:15:33 +08:00
|
|
|
});
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
var line3 = new Konva.Line({
|
|
|
|
points: [73, 160, 340, 23],
|
|
|
|
stroke: 'green',
|
|
|
|
strokeWidth: 10,
|
|
|
|
lineCap: 'round',
|
|
|
|
lineJoin: 'round',
|
|
|
|
draggable: true,
|
2020-05-08 22:59:35 +08:00
|
|
|
tension: 1,
|
2017-02-24 22:15:33 +08:00
|
|
|
});
|
2013-07-25 12:57:45 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
layer.add(line1);
|
|
|
|
layer.add(line2);
|
|
|
|
layer.add(line3);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
assert.equal(line1.getClassName(), 'Line');
|
|
|
|
|
|
|
|
var trace = layer.getContext().getTrace();
|
|
|
|
|
|
|
|
//console.log(trace);
|
|
|
|
assert.equal(
|
|
|
|
trace,
|
|
|
|
'clearRect(0,0,578,200);save();lineJoin=round;transform(1,0,0,1,0,0);beginPath();moveTo(73,160);quadraticCurveTo(74.006,54.77,340,23);bezierCurveTo(501.006,3.77,519.038,68.068,500,109);quadraticCurveTo(479.038,154.068,300,109);lineCap=round;lineWidth=10;strokeStyle=blue;stroke();restore();save();lineJoin=round;transform(1,0,0,1,0,0);beginPath();moveTo(73,160);quadraticCurveTo(74.006,54.77,340,23);quadraticCurveTo(501.006,3.77,500,109);lineCap=round;lineWidth=10;strokeStyle=red;stroke();restore();save();lineJoin=round;transform(1,0,0,1,0,0);beginPath();moveTo(73,160);lineTo(340,23);lineCap=round;lineWidth=10;strokeStyle=green;stroke();restore();'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
// ======================================================
|
2020-05-08 22:59:35 +08:00
|
|
|
test('update spline points', function () {
|
2017-02-24 22:15:33 +08:00
|
|
|
var stage = addStage();
|
|
|
|
var layer = new Konva.Layer();
|
|
|
|
|
|
|
|
var spline = new Konva.Line({
|
|
|
|
points: [73, 160, 340, 23, 500, 109, 300, 109],
|
|
|
|
stroke: 'blue',
|
|
|
|
strokeWidth: 10,
|
|
|
|
lineCap: 'round',
|
|
|
|
lineJoin: 'round',
|
|
|
|
draggable: true,
|
2020-05-08 22:59:35 +08:00
|
|
|
tension: 1,
|
2017-02-24 22:15:33 +08:00
|
|
|
});
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
layer.add(spline);
|
|
|
|
stage.add(layer);
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
assert.equal(spline.getTensionPoints().length, 12);
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
spline.setPoints([73, 160, 340, 23, 500, 109]);
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
assert.equal(spline.getTensionPoints().length, 6);
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
layer.draw();
|
|
|
|
});
|
2013-07-25 12:57:45 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
// ======================================================
|
2020-05-08 22:59:35 +08:00
|
|
|
test('add point to spline points', function () {
|
2017-02-24 22:15:33 +08:00
|
|
|
var stage = addStage();
|
|
|
|
var layer = new Konva.Layer();
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
var spline = new Konva.Line({
|
|
|
|
points: [73, 160, 340, 23, 500, 109, 300, 109],
|
|
|
|
stroke: 'blue',
|
|
|
|
strokeWidth: 10,
|
|
|
|
lineCap: 'round',
|
|
|
|
lineJoin: 'round',
|
|
|
|
draggable: true,
|
2020-05-08 22:59:35 +08:00
|
|
|
tension: 1,
|
2013-09-08 08:57:48 +08:00
|
|
|
});
|
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
layer.add(spline);
|
|
|
|
stage.add(layer);
|
2013-07-25 12:57:45 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
assert.equal(spline.getPoints().length, 8);
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
var points = spline.getPoints();
|
|
|
|
points.push(300);
|
|
|
|
points.push(200);
|
|
|
|
spline.clearCache();
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
assert.equal(spline.getPoints().length, 10);
|
2013-06-28 14:28:57 +08:00
|
|
|
|
2017-02-24 22:15:33 +08:00
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
});
|