mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Optimise read() functions to only convert if argument is not of desired type already.
This commit is contained in:
parent
d67055b09b
commit
0ac19a8e82
4 changed files with 14 additions and 4 deletions
|
@ -273,12 +273,15 @@ var Point = Base.extend({
|
|||
|
||||
statics: {
|
||||
read: function(args) {
|
||||
if(args.length) {
|
||||
if (args.length == 1 && args[0] instanceof Point) {
|
||||
return args[0];
|
||||
} else if (args.length) {
|
||||
var point = new Point();
|
||||
point.initialize.apply(point, args);
|
||||
return point;
|
||||
}
|
||||
},
|
||||
|
||||
min: function(point1, point2) {
|
||||
return new Point(
|
||||
Math.min(point1.x, point2.x),
|
||||
|
|
|
@ -278,7 +278,9 @@ Rectangle = Base.extend({
|
|||
|
||||
statics: {
|
||||
read: function(args) {
|
||||
if(args.length) {
|
||||
if (args.length == 1 && args[0] instanceof Rectangle) {
|
||||
return args[0];
|
||||
} else if (args.length) {
|
||||
var rect = new Rectangle();
|
||||
rect.initialize.apply(rect, args);
|
||||
return rect;
|
||||
|
|
|
@ -88,12 +88,15 @@ var Size = Base.extend({
|
|||
|
||||
statics: {
|
||||
read: function(args) {
|
||||
if(args.length) {
|
||||
if (args.length == 1 && args[0] instanceof Size) {
|
||||
return args[0];
|
||||
} else if (args.length) {
|
||||
var size = new Size();
|
||||
size.initialize.apply(size, args);
|
||||
return size;
|
||||
}
|
||||
},
|
||||
|
||||
min: function(Size1, Size2) {
|
||||
return new Size(
|
||||
Math.min(Size1.width, Size2.width),
|
||||
|
|
|
@ -135,7 +135,9 @@ Segment = Base.extend({
|
|||
|
||||
statics: {
|
||||
read: function(args) {
|
||||
if(args.length && args[0] != null) {
|
||||
if (args.length == 1 && args[0] instanceof Segment) {
|
||||
return args[0];
|
||||
} else if (args.length && args[0] != null) {
|
||||
var segment = new Segment();
|
||||
segment.initialize.apply(segment, args);
|
||||
return segment;
|
||||
|
|
Loading…
Reference in a new issue