Permalink
Browse files

Merge pull request #44 from jacobmesu/master

Fixed Frame.Merge should now calculate the size right
  • Loading branch information...
koenbok committed Oct 15, 2013
2 parents bad5a94 + 28510eb commit 78f3d911cbe90b2d84f8d7d69c0ae93ef9753e21
Showing with 44 additions and 15 deletions.
  1. +7 −5 build/framer.js
  2. +8 −4 src/primitives/frame.coffee
  3. +7 −5 template/framer.js
  4. +22 −1 test/tests/view.coffee
View
@@ -3632,13 +3632,15 @@ require.define("/src/primitives/frame.coffee",function(require,module,exports,__
});
Frame.prototype.merge = function(r2) {
var frame, r1;
var frame, r1, xmin, ymin;
r1 = this;
xmin = Math.min(r1.x, r2.x);
ymin = Math.min(r1.y, r2.y);
frame = {
x: Math.min(r1.x, r2.x),
y: Math.min(r1.y, r2.y),
width: Math.max(r1.width, (r2.x - r1.x) + r2.width),
height: Math.max(r1.height, (r2.y - r1.y) + r2.height)
x: xmin,
y: ymin,
width: Math.max(r1.x + r1.width, r2.x + r2.width) - xmin,
height: Math.max(r1.y + r1.height, r2.y + r2.height) - ymin
};
return new Frame(frame);
};
@@ -66,11 +66,15 @@ class Frame extends EventEmitter
merge: (r2) ->
r1 = @
xmin = Math.min(r1.x, r2.x)
ymin = Math.min(r1.y, r2.y)
frame =
x: Math.min(r1.x, r2.x)
y: Math.min(r1.y, r2.y)
width: Math.max(r1.width, (r2.x - r1.x) + r2.width),
height: Math.max(r1.height, (r2.y - r1.y) + r2.height)
x: xmin
y: ymin
width: Math.max(r1.x + r1.width, r2.x + r2.width) - xmin
height: Math.max(r1.y + r1.height, r2.y + r2.height) - ymin
return new Frame frame
View
@@ -3632,13 +3632,15 @@ require.define("/src/primitives/frame.coffee",function(require,module,exports,__
});
Frame.prototype.merge = function(r2) {
var frame, r1;
var frame, r1, xmin, ymin;
r1 = this;
xmin = Math.min(r1.x, r2.x);
ymin = Math.min(r1.y, r2.y);
frame = {
x: Math.min(r1.x, r2.x),
y: Math.min(r1.y, r2.y),
width: Math.max(r1.width, (r2.x - r1.x) + r2.width),
height: Math.max(r1.height, (r2.y - r1.y) + r2.height)
x: xmin,
y: ymin,
width: Math.max(r1.x + r1.width, r2.x + r2.width) - xmin,
height: Math.max(r1.y + r1.height, r2.y + r2.height) - ymin
};
return new Frame(frame);
};
View
@@ -58,7 +58,28 @@ describe "View", ->
view.y.should.equal frame.y
view.width.should.equal frame.width
view.height.should.equal frame.height
it "should merge view with frame", ->
view = createView()
frameB = {x:200, y:200, width:200, height:200}
frameTest = view.merge(frameB)
frameTest.x.should.equal 0
frameTest.y.should.equal 0
frameTest.width.should.equal 400
frameTest.height.should.equal 400
viewB = new View width:500, height:500
frameTest = viewB.merge(frameB)
frameTest.x.should.equal 0
frameTest.y.should.equal 0
frameTest.width.should.equal 500
frameTest.height.should.equal 500
frameC = {x:-30, y:-40, width:200, height:200}
frameTest = viewB.merge(frameC)
frameTest.x.should.equal -30
frameTest.y.should.equal -40
frameTest.width.should.equal 530
frameTest.height.should.equal 540
describe "Visual", ->
["scaleX", "scaleY", "scaleZ"].map (p) ->

0 comments on commit 78f3d91

Please sign in to comment.