forked from jamesshore/quixote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsize.js
57 lines (43 loc) · 1.5 KB
/
size.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file.
"use strict";
var ensure = require("../util/ensure.js");
var Value = require("./value.js");
var Pixels = require("./pixels.js");
var Me = module.exports = function Size(value) {
ensure.signature(arguments, [ [Number, Pixels] ]);
this._value = (typeof value === "number") ? Pixels.create(value) : value;
};
Value.extend(Me);
Me.create = function create(value) {
return new Me(value);
};
Me.prototype.compatibility = function compatibility() {
return [ Me ];
};
Me.prototype.plus = Value.safe(function plus(operand) {
return new Me(this._value.plus(operand._value));
});
Me.prototype.minus = Value.safe(function minus(operand) {
return new Me(this._value.minus(operand._value));
});
Me.prototype.times = function times(operand) {
return new Me(this._value.times(operand));
};
Me.prototype.compare = Value.safe(function compare(that) {
return this._value.compare(that._value);
});
Me.prototype.diff = Value.safe(function diff(expected) {
var actualValue = this._value;
var expectedValue = expected._value;
if (actualValue.equals(expectedValue)) return "";
var desc = actualValue.compare(expectedValue) > 0 ? " larger" : " smaller";
return actualValue.diff(expectedValue) + desc;
});
Me.prototype.toString = function toString() {
ensure.signature(arguments, []);
return this._value.toString();
};
Me.prototype.toPixels = function toPixels() {
ensure.signature(arguments, []);
return this._value;
};