Chromium Code Reviews| Index: chrome/browser/resources/print_preview/data/coordinate2d.js |
| diff --git a/chrome/browser/resources/print_preview/data/coordinate2d.js b/chrome/browser/resources/print_preview/data/coordinate2d.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e061e3e9cc934841a9b298a39928fbb673676692 |
| --- /dev/null |
| +++ b/chrome/browser/resources/print_preview/data/coordinate2d.js |
| @@ -0,0 +1,79 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('print_preview', function() { |
| + 'use strict'; |
| + |
| + /** |
| + * Immutable two dimensional point in space. The units of the dimensions are |
| + * undefined. |
| + * |
| + * @param {number} x X-dimension of the point. |
| + * @param {number} y Y-dimension of the point. |
| + * @constructor |
| + */ |
| + function Coordinate2d(x, y) { |
| + /** |
| + * X-dimension of the point. |
| + * @type {number} |
| + * @private |
| + */ |
| + this.x_ = x; |
| + |
| + /** |
| + * Y-dimension of the point. |
| + * @type {number} |
| + * @private |
| + */ |
| + this.y_ = y; |
| + }; |
| + |
| + Coordinate2d.prototype = { |
| + /** @return {number} X-dimension of the point. */ |
| + get x() { |
| + return this.x_; |
| + }, |
| + |
| + /** @return {number} Y-dimension of the point. */ |
| + get y() { |
| + return this.y_; |
| + }, |
| + |
| + /** |
| + * @param {number} x Amount to translate in the X dimension. |
| + * @param {number} y Amount to translate in the Y dimension. |
| + * @return {!print_preview.Coordinate2d} A new two-dimensional point |
| + * translated along the X and Y dimensions. |
|
dpapad
2012/04/24 01:24:56
Nit: "translated" might fit in previous line, not
Robert Toscano
2012/04/24 22:29:56
3 chars too long.
|
| + */ |
| + translate: function(x, y) { |
| + return new Coordinate2d(this.x_ + x, this.y_ + y); |
| + }, |
| + |
| + /** |
| + * @param {number} factor Amount to scale the X and Y dimensions. |
| + * @return {!print_preview.Coordinate2d} A new two-dimensional point scaled |
| + * by the given factor. |
|
dpapad
2012/04/24 01:24:56
Nit: "by" can fit in previous line.
Robert Toscano
2012/04/24 22:29:56
No more room :(
|
| + */ |
| + scale: function(factor) { |
| + return new Coordinate2d(this.x_ * factor, this.y_ * factor); |
| + }, |
| + |
| + /** |
| + * @param {print_preview.Coordinate2d} other The other two-dimensional |
|
dpapad
2012/04/24 01:24:56
Nit: Shorter comment
The point to compare against.
Robert Toscano
2012/04/24 22:29:56
Nice, saved me a couple of lines.
|
| + * coordinate to compare this coordinate against. |
| + * @return {boolean} Whether another two-dimensional point is equal to |
| + * this one. |
| + */ |
| + equals: function(other) { |
| + return other != null && |
| + this.x_ == other.x_ && |
| + this.y_ == other.y_; |
| + } |
| + }; |
| + |
| + // Export |
| + return { |
| + Coordinate2d: Coordinate2d |
| + }; |
| +}); |