Skip to content

Commit

Permalink
add x and y to center of rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-wells committed Aug 19, 2019
1 parent 889ccec commit 913a6f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export module Serial {
// Initialize with defaults
let current: Key = new Key();
let kbd = new Keyboard();
let cluster = { x: 0, y: 0 };
var align = 4;

for (var r = 0; r < rows.length; ++r) {
Expand Down Expand Up @@ -150,6 +151,16 @@ export module Serial {
);
}
if (item.r != null) current.rotation_angle = item.r;
if (item.rx != null) {
current.rotation_x = cluster.x = item.rx;
current.x = cluster.x;
current.y = cluster.y;
}
if (item.ry != null) {
current.rotation_y = cluster.y = item.ry;
current.x = cluster.x;
current.y = cluster.y;
}
if (item.rx != null) current.rotation_x = item.rx;
if (item.ry != null) current.rotation_y = item.ry;
if (item.a != null) align = item.a;
Expand Down
8 changes: 8 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ describe("deserialization", function() {
expect(result.keys[0].x2).to.not.equal(0);
expect(result.keys[0].y2).to.not.equal(0);
});

it("should add x and y to center of rotation", function() {
var result = kbd.Serial.deserialize([[{r:10,rx:1,ry:1,y:-1.1,x:2},"E"]]);
expect(result).to.be.an.instanceOf(kbd.Keyboard);
expect(result.keys).to.have.length(1);
expect(result.keys[0].x).to.equal(3);
expect(result.keys[0].y).to.be.closeTo(-0.1, 0.0001);
});
});

describe("of key sizes", function() {
Expand Down

0 comments on commit 913a6f4

Please sign in to comment.