1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved. 21e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// Redistribution and use in source and binary forms, with or without 31e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// modification, are permitted provided that the following conditions are 41e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// met: 51e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// 61e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Redistributions of source code must retain the above copyright 71e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// notice, this list of conditions and the following disclaimer. 81e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Redistributions in binary form must reproduce the above 91e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// copyright notice, this list of conditions and the following 101e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// disclaimer in the documentation and/or other materials provided 111e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// with the distribution. 121e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Neither the name of Google Inc. nor the names of its 131e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// contributors may be used to endorse or promote products derived 141e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// from this software without specific prior written permission. 151e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// 161e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block 283fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Flags: --allow-natives-syntax 291e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block 30b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar gdpRatio = 16/9; 313fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 32b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction Foo(initialX, initialY, initialScale, initialMapHeight) { 33b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch this.ORIGIN = { x: initialX, y: initialY }; 34b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch this.scale = initialScale; 35b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch this.mapHeight = initialMapHeight; 361e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block} 37e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch 38b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochFoo.prototype.bar = function (x, y, xOffset, yOffset) { 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var tileHeight = 64 * 0.25 * this.scale, 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch tileWidth = 128 * 0.25 * this.scale, 41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch xOffset = xOffset * 0.5 || 0, 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch yOffset = yOffset * 0.5 || 0; 43b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var xPos = ((xOffset) * gdpRatio) + this.ORIGIN.x * this.scale - 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ((y * tileWidth ) * gdpRatio) + ((x * tileWidth ) * gdpRatio); 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var yPos = ((yOffset) * gdpRatio) + this.ORIGIN.y * this.scale + 46b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch ((y * tileHeight) * gdpRatio) + ((x * tileHeight) * gdpRatio); 47b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch xPos = xPos - Math.round(((tileWidth) * gdpRatio)) + 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch this.mapHeight * Math.round(((tileWidth) * gdpRatio)); 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return { 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch x: Math.floor(xPos), 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch y: Math.floor(yPos) 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch }; 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar f = new Foo(10, 20, 2.5, 400); 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction baz() { 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch var b = f.bar(1.1, 2.2, 3.3, 4.4); 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch assertEquals(56529, b.x); 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch assertEquals(288, b.y); 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochbaz(); 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochbaz(); 65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(Foo.prototype.bar); 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochbaz(); 67