mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Add Base.formatNumber() to format numbers in the same way as Scriptographer (precision of up to 5 fractional digits) and use it in the various #toString() functions.
This commit is contained in:
parent
fb6955e509
commit
bc80c58558
8 changed files with 31 additions and 20 deletions
|
@ -193,9 +193,11 @@ var Matrix = this.Matrix = Base.extend({
|
||||||
* @return {string} A string representation of this transform.
|
* @return {string} A string representation of this transform.
|
||||||
*/
|
*/
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '[['
|
var format = Base.formatNumber;
|
||||||
+ [this._m00, this._m01, this._m02].join(', ') + '], ['
|
return '[[' + [format(this._m00), format(this._m01),
|
||||||
+ [this._m10, this._m11, this._m12].join(', ') + ']]';
|
format(this._m02)].join(', ') + '], ['
|
||||||
|
+ [format(this._m10), format(this._m11),
|
||||||
|
format(this._m12)].join(', ') + ']]';
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -454,7 +454,8 @@ var Point = this.Point = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '{ x: ' + this.x + ', y: ' + this.y + ' }';
|
var format = Base.formatNumber;
|
||||||
|
return '{ x: ' + format(this.x) + ', y: ' + format(this.y) + ' }';
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
|
|
@ -221,10 +221,11 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '{ x: ' + this.x
|
var format = Base.formatNumber;
|
||||||
+ ', y: ' + this.y
|
return '{ x: ' + format(this.x)
|
||||||
+ ', width: ' + this.width
|
+ ', y: ' + format(this.y)
|
||||||
+ ', height: ' + this.height
|
+ ', width: ' + format(this.width)
|
||||||
|
+ ', height: ' + format(this.height)
|
||||||
+ ' }';
|
+ ' }';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,9 @@ var Size = this.Size = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '{ x: ' + this.width + ', y: ' + this.height + ' }';
|
var format = Base.formatNumber;
|
||||||
|
return '{ x: ' + format(this.width)
|
||||||
|
+ ', y: ' + format(this.height) + ' }';
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
|
|
@ -173,13 +173,14 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
var parts = [];
|
var parts = [],
|
||||||
|
format = Base.formatNumber;
|
||||||
for (var i = 0, l = this._components.length; i < l; i++) {
|
for (var i = 0, l = this._components.length; i < l; i++) {
|
||||||
var component = this._components[i];
|
var component = this._components[i],
|
||||||
var value = this['_' + component];
|
value = this['_' + component];
|
||||||
if (component === 'alpha' && value == null)
|
if (component === 'alpha' && value == null)
|
||||||
value = 1;
|
value = 1;
|
||||||
parts.push(component + ': ' + value);
|
parts.push(component + ': ' + format(value));
|
||||||
}
|
}
|
||||||
return '{ ' + parts.join(', ') + ' }';
|
return '{ ' + parts.join(', ') + ' }';
|
||||||
},
|
},
|
||||||
|
|
|
@ -83,6 +83,10 @@ Base.inject({
|
||||||
return str.replace(/\b[a-z]/g, function(match) {
|
return str.replace(/\b[a-z]/g, function(match) {
|
||||||
return match.toUpperCase();
|
return match.toUpperCase();
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
formatNumber: function(num) {
|
||||||
|
return (Math.round(num * 100000) / 100000).toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,8 @@ CurveLocation = Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
var parts = [];
|
var parts = [],
|
||||||
var point = this.getPoint();
|
point = this.getPoint();
|
||||||
if (point)
|
if (point)
|
||||||
parts.push('point: ' + point);
|
parts.push('point: ' + point);
|
||||||
var index = this.getIndex();
|
var index = this.getIndex();
|
||||||
|
@ -138,7 +138,7 @@ CurveLocation = Base.extend({
|
||||||
parts.push('index: ' + index);
|
parts.push('index: ' + index);
|
||||||
var parameter = this.getParameter();
|
var parameter = this.getParameter();
|
||||||
if (parameter != null)
|
if (parameter != null)
|
||||||
parts.push('parameter: ' + parameter);
|
parts.push('parameter: ' + Base.formatNumber(parameter));
|
||||||
return '{ ' + parts.join(', ') + ' }';
|
return '{ ' + parts.join(', ') + ' }';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,10 +42,10 @@ var ToolEvent = this.ToolEvent = Base.extend({
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return '{ type: ' + this.type
|
return '{ type: ' + this.type
|
||||||
+ ', point: ' + this.point
|
+ ', point: ' + this.point
|
||||||
+ ', count: ' + this.count
|
+ ', count: ' + this.count
|
||||||
+ ', modifiers: ' + this.modifiers
|
+ ', modifiers: ' + this.modifiers
|
||||||
+ ' }';
|
+ ' }';
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue