You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<preclass="docs-method-signature"><code>g.Rect(x, y, width, height)</code></pre>
2
2
<p>Return a new rectangle object with top left corner at point with coordinates <code>x</code>, <code>y</code> and dimensions <code>width</code> and <code>height</code>.</p>
3
3
4
-
<p>Also accepts as a single argument an object in the form <code>{ x: [number], y: [number], width: [number], height: [number] }</code>.</p>
4
+
<p>Also accepts a single argument in the form of an object<code>{ x: [number], y: [number], width: [number], height: [number] }</code>.</p>
<p>Returns a new rectangle object that is large enough to contain given <code>points</code>, where each point is an object with <code>x</code> and <code>y</code> properties. Examples:</p>
3
+
<pre><code>const rect = g.Rect.fromPointUnion(new g.Point(0, 0), new g.Point(20, 20));
<p>Returns a new rectangle object that is large enough to contain given <code>rects</code>, where each rect is an object with <code>x</code>, <code>y</code>, <code>width</code> and <code>height</code> properties. Examples:</p>
3
+
<pre><code>const rect = g.Rect.fromRectUnion(new g.Rect(0, 0, 10, 10), new g.Rect(10, 10, 10, 10));
<p>Update the rect's <code>x</code>, <code>y</code>, <code>width</code> and <code>height</code> properties with new values and return the rect itself. Useful for chaining.</p>
4
+
<p>Also accepts a single argument in the form of an object <code>{ x: [number], y: [number], width: [number], height: [number] }</code>.</p>
QUnit.test('returns null if no arguments are passed',function(assert){
35
+
assert.ok(g.Rect.fromPointUnion()===null);
36
+
});
37
+
38
+
QUnit.test('creates a new Rect object from points',function(assert){
39
+
varr0=newg.Rect(10,20,5,5);
40
+
vartopRightR0=r0.topRight();
41
+
varbottomLeftR0=r0.bottomLeft();
42
+
varoriginR0=r0.origin();
43
+
varcornerR0=r0.corner();
44
+
45
+
varr1=newg.Rect(-10,-20,40,60);
46
+
varoriginR1=r1.origin();
47
+
varcornerR1=r1.corner();
48
+
49
+
varr2=newg.Rect();
50
+
51
+
varunionR0R1=newg.Rect(-10,-20,40,60);
52
+
varunionR0R2=newg.Rect(0,0,15,25);
53
+
54
+
assert.ok(g.Rect.fromPointUnion(originR0,cornerR0).equals(r0),'rect from g.Points');
55
+
assert.ok(g.Rect.fromPointUnion(topRightR0,bottomLeftR0).equals(r0),'rect from g.Points 2');
56
+
assert.ok(g.Rect.fromPointUnion({x: r0.x,y: r0.y},{x: r0.x+r0.width,y: r0.y+r0.height}).equals(r0),'rect from PlainPoints');
57
+
assert.ok(g.Rect.fromPointUnion(cornerR1,{x: r0.x,y: r0.y},{x: r0.x+r0.width,y: r0.y+r0.height},originR1).equals(unionR0R1),'rect from g.Points and PlainPoints');
58
+
assert.ok(g.Rect.fromPointUnion(originR0).equals(newg.Rect(r0.x,r0.y,0,0)),'rect from single g.Point has width and height equal to 0');
59
+
assert.ok(g.Rect.fromPointUnion({x: r0.x,y: r0.y}).equals(newg.Rect(r0.x,r0.y,0,0)),'rect from single PlainPoint has width and height equal to 0');
60
+
assert.ok(g.Rect.fromPointUnion(originR0,cornerR1,cornerR0,originR1).equals(unionR0R1),'rect from multiple g.Points');
61
+
assert.ok(g.Rect.fromPointUnion({x: r1.x+r1.width,y: r1.y+r1.height},originR0,{x: r0.x,y: r0.y},originR1).equals(unionR0R1),'rect from multiple g.Points and PlainPoints');
62
+
assert.ok(g.Rect.fromPointUnion({},{}).equals(r2),'creates default rect if cannot read x and y from arguments');
63
+
assert.ok(g.Rect.fromPointUnion({},topRightR0,bottomLeftR0).equals(unionR0R2),'creates default rect if cannot read x and y from argument');
64
+
});
65
+
});
66
+
67
+
QUnit.module('fromRectUnion(rects)',function(){
68
+
69
+
QUnit.test('returns null if no arguments are passed',function(assert){
70
+
assert.ok(g.Rect.fromRectUnion()===null);
71
+
});
72
+
73
+
QUnit.test('creates a new Rect object from rects',function(assert){
74
+
varr0=newg.Rect();
75
+
assert.ok(g.Rect.fromRectUnion(r0).equals(r0),'rect from g.Rect');
76
+
assert.ok(g.Rect.fromRectUnion({x: r0.x,y: r0.y,width: r0.width,height: r0.height}).equals(r0),'rect from PlainRect');
assert.equal((newg.Rect(20,20,150,150)).union(newg.Rect(50,50,200,200)).toString(),(newg.Rect(20,20,230,230)).toString(),'union of intersecting rectangles');
297
374
});
298
375
});
376
+
377
+
QUnit.module('update(x, y, width, height)',function(){
378
+
379
+
QUnit.test('changes the values of x, y, width and height',function(assert){
380
+
381
+
varrect=newg.Rect(12,25);
382
+
rect.update(1,2,3,4);
383
+
assert.equal(rect.toString(),'1@2 4@6');
384
+
385
+
rect.update(5,6);
386
+
assert.equal(rect.toString(),'5@6 5@6');
387
+
388
+
rect.update();
389
+
assert.equal(rect.toString(),'0@0 0@0');
390
+
});
391
+
392
+
QUnit.test('changes the values of x, y, width and height with object arg',function(assert){
0 commit comments