4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
9 <script src=
"base.js"></script>
11 base
.require('base.unittest');
12 base
.require('base.bbox2');
13 base
.require('quad_view_viewport');
20 var QuadViewViewport
= ccfv
.QuadViewViewport
;
22 function testBasicsHighDPI() {
23 var bbox
= new base
.BBox2();
25 bbox
.addXY(4000, 2000);
27 var vp
= new QuadViewViewport(bbox
, 0.125, true, 2);
28 assertEquals(500, vp
.deviceWidth
);
29 assertEquals(250, vp
.deviceHeight
);
31 assertEquals(250, vp
.layoutWidth
);
32 assertEquals(125, vp
.layoutHeight
);
35 var tmp
= vp
.layoutPixelsToWorldPixels2(vec2
.createXY(0, 0))
36 assertEquals(0, tmp
[0]);
37 assertEquals(0, tmp
[1]);
40 var tmp
= vp
.layoutPixelsToWorldPixels2(vec2
.createXY(125, 62.5))
41 assertEquals(2000, tmp
[0]);
42 assertEquals(1000, tmp
[1]);
45 var tmp
= vp
.layoutPixelsToWorldPixels2(vec2
.createXY(250, 125))
46 assertEquals(4000, tmp
[0]);
47 assertEquals(2000, tmp
[1]);
50 function testBasicsHighDPIUnpadded() {
51 var bbox
= new base
.BBox2();
53 bbox
.addXY(4000, 2000);
55 var vp
= new QuadViewViewport(bbox
, 0.125, false, 2);
56 assertEquals(550, vp
.deviceWidth
);
57 assertEquals(300, vp
.deviceHeight
);
59 assertEquals(275, vp
.layoutWidth
);
60 assertEquals(150, vp
.layoutHeight
);
63 var tmp
= vp
.layoutPixelsToWorldPixels2(vec2
.createXY(0, 0))
64 assertEquals(-200, tmp
[0]);
65 assertEquals(-200, tmp
[1]);
68 var tmp
= vp
.layoutPixelsToWorldPixels2(vec2
.createXY(137.5, 75))
69 assertEquals(2000, tmp
[0]);
70 assertEquals(1000, tmp
[1]);
73 var tmp
= vp
.layoutPixelsToWorldPixels2(vec2
.createXY(275, 150))
74 assertEquals(4200, tmp
[0]);
75 assertEquals(2200, tmp
[1]);