2015-09-19 18:56:32 +03:00
|
|
|
describe("TransformUtils suite", function() {
|
2014-11-23 17:03:35 +03:00
|
|
|
var A = '#000000';
|
|
|
|
var B = '#ff0000';
|
|
|
|
var O = Constants.TRANSPARENT_COLOR;
|
|
|
|
|
2015-09-19 18:56:32 +03:00
|
|
|
var HORIZONTAL = pskl.tools.transform.TransformUtils.HORIZONTAL;
|
|
|
|
var VERTICAL = pskl.tools.transform.TransformUtils.VERTICAL;
|
2014-11-23 17:03:35 +03:00
|
|
|
|
2015-09-19 18:56:32 +03:00
|
|
|
var CLOCKWISE = pskl.tools.transform.TransformUtils.CLOCKWISE;
|
|
|
|
var COUNTERCLOCKWISE = pskl.tools.transform.TransformUtils.COUNTERCLOCKWISE;
|
2014-11-23 17:03:35 +03:00
|
|
|
|
2014-12-27 17:02:41 +03:00
|
|
|
// shortcuts
|
|
|
|
var frameEqualsGrid = test.testutils.frameEqualsGrid;
|
|
|
|
var toFrameGrid = test.testutils.toFrameGrid;
|
2014-11-23 17:03:35 +03:00
|
|
|
|
|
|
|
/*******************************/
|
|
|
|
/************ FLIP *************/
|
|
|
|
/*******************************/
|
|
|
|
|
|
|
|
it("flips a frame vertically", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[A, O],
|
|
|
|
[O, B]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// should have flipped
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.flip(frame, VERTICAL);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, A],
|
|
|
|
[B, O]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("flips a frame horizontally", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[A, O],
|
|
|
|
[O, B]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// should have flipped
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.flip(frame, HORIZONTAL);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, B],
|
|
|
|
[A, O]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("flips rectangular frame", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[A, O],
|
|
|
|
[A, O],
|
|
|
|
[A, O]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// should have flipped
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.flip(frame, VERTICAL);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, A],
|
|
|
|
[O, A],
|
|
|
|
[O, A]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// should be the same
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.flip(frame, HORIZONTAL);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, A],
|
|
|
|
[O, A],
|
|
|
|
[O, A]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
/*******************************/
|
|
|
|
/*********** ROTATE ************/
|
|
|
|
/*******************************/
|
|
|
|
|
|
|
|
it("rotates a frame counterclockwise", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[A, O],
|
|
|
|
[O, B]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// rotate once
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, B],
|
|
|
|
[A, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate twice
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[B, O],
|
|
|
|
[O, A]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 3
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, A],
|
|
|
|
[B, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 4 - back to initial state
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, COUNTERCLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[A, O],
|
|
|
|
[O, B]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rotates a frame clockwise", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[A, O],
|
|
|
|
[O, B]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// rotate once
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, A],
|
|
|
|
[B, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate twice
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[B, O],
|
|
|
|
[O, A]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 3
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, B],
|
|
|
|
[A, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 4 - back to initial state
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[A, O],
|
|
|
|
[O, B]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rotates a rectangular frame", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[A, O],
|
|
|
|
[A, O],
|
|
|
|
[B, O],
|
|
|
|
[B, O]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// rotate once
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, O],
|
|
|
|
[B, A],
|
|
|
|
[O, O],
|
|
|
|
[O, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate twice
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, O],
|
|
|
|
[O, B],
|
|
|
|
[O, A],
|
|
|
|
[O, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 3
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, O],
|
|
|
|
[O, O],
|
|
|
|
[A, B],
|
|
|
|
[O, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 4
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, O],
|
|
|
|
[A, O],
|
|
|
|
[B, O],
|
|
|
|
[O, O]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("rotates a rectangular (horizontal) frame", function () {
|
|
|
|
// create frame
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
|
|
|
[O, O, O, O],
|
|
|
|
[A, A, B, B]
|
|
|
|
]));
|
|
|
|
|
|
|
|
// rotate once
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, A, O, O],
|
|
|
|
[O, B, O, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate twice
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, B, A, O],
|
|
|
|
[O, O, O, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 3
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, O, B, O],
|
|
|
|
[O, O, A, O]
|
|
|
|
]);
|
|
|
|
|
|
|
|
// rotate 4
|
2015-09-19 18:56:32 +03:00
|
|
|
pskl.tools.transform.TransformUtils.rotate(frame, CLOCKWISE);
|
2014-11-23 17:03:35 +03:00
|
|
|
frameEqualsGrid(frame, [
|
|
|
|
[O, O, O, O],
|
|
|
|
[O, A, B, O]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|