Skip to content

Commit 2abefee

Browse files
committed
Merge Base.readValue() with Base.read() and rename Base.peekValue() to Base.peek().
When called directly on Base, read() reads values, otherwise the specific type of the subclass it is called on.
1 parent 1b53930 commit 2abefee

8 files changed

Lines changed: 30 additions & 29 deletions

File tree

src/basic/Line.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var Line = this.Line = Base.extend(/** @lends Line# */{
3636
// is automatially true, since we're describing an infinite line.
3737
var _point1 = Point.read(arguments),
3838
_point2 = Point.read(arguments),
39-
_infinite = Base.readValue(arguments);
39+
_infinite = Base.read(arguments);
4040
if (_infinite !== undefined) {
4141
this.point = _point1;
4242
this.vector = _point2.subtract(_point1);

src/basic/Rectangle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
7777
// Read a point argument and look at the next value to see wether
7878
// it's a size or a point, then read accordingly
7979
var point = Point.read(arguments),
80-
next = Base.peekValue(arguments);
80+
next = Base.peek(arguments);
8181
this.x = point.x;
8282
this.y = point.y;
8383
if (next && next.x !== undefined) {

src/core/Base.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,27 @@ this.Base = Base.inject(/** @lends Base# */{
110110
},
111111

112112
/**
113-
* Reads arguments of the type of the class on which it is called on
114-
* from the passed arguments list or array, at the given index, up to
115-
* the specified length. This is used in argument conversion, e.g. by
116-
* all basic types (Point, Size, Rectangle) and also higher classes such
117-
* as Color and Segment.
113+
* When called on a subclass of Base, it reads arguments of the type of
114+
* the subclass from the passed arguments list or array, at the given
115+
* index, up to the specified length.
116+
* When called directly on Base, it reads any value without conversion
117+
* from the apssed arguments list or array.
118+
* This is used in argument conversion, e.g. by all basic types (Point,
119+
* Size, Rectangle) and also higher classes such as Color and Segment.
118120
* @param {Number} start the index at which to start reading in the list
119121
* @param {Number} length the amount of elements that can be read
120122
* @param {Boolean} clone controls wether passed objects should be
121123
* cloned if they are already provided in the required type
122124
*/
123125
read: function(list, start, length, clone, readNull) {
126+
// See if it's called directly on Base, and if so, read value and
127+
// return without object conversion.
128+
if (this === Base) {
129+
var value = this.peek(list, start);
130+
list._index++;
131+
list._read = 1;
132+
return value;
133+
}
124134
var proto = this.prototype,
125135
readIndex = proto._readIndex,
126136
index = start || readIndex && list._index || 0;
@@ -151,17 +161,10 @@ this.Base = Base.inject(/** @lends Base# */{
151161
return obj;
152162
},
153163

154-
peekValue: function(list, start) {
164+
peek: function(list, start) {
155165
return list[list._index = start || list._index || 0];
156166
},
157167

158-
readValue: function(list, start) {
159-
var value = this.peekValue(list, start);
160-
list._index++;
161-
list._read = 1;
162-
return value;
163-
},
164-
165168
/**
166169
* Reads all readable arguments from the list, handling nested arrays
167170
* seperately.

src/item/Item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
11191119
*/
11201120
hitTest: function(point, options) {
11211121
point = Point.read(arguments);
1122-
options = HitResult.getOptions(Base.readValue(arguments));
1122+
options = HitResult.getOptions(Base.read(arguments));
11231123
// Check if the point is withing roughBounds + tolerance, but only if
11241124
// this item does not have children, since we'd have to travel up the
11251125
// chain already to determine the rough bounds.

src/path/Curve.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,6 @@ statics: {
463463
}
464464
}
465465
// The normal is simply the rotated tangent:
466-
// TODO: Rotate normals the other way in Scriptographer too?
467-
// (Depending on orientation, I guess?)
468466
return type == 2 ? new Point(y, -x) : new Point(x, y);
469467
},
470468

@@ -574,7 +572,7 @@ statics: {
574572
},
575573

576574
getBounds: function(v) {
577-
var min = v.slice(0, 2),
575+
var min = v.slice(0, 2), // Start with values of point1
578576
max = min.slice(0), // clone
579577
roots = new Array(2);
580578
for (var i = 0; i < 2; i++)

src/path/Path.Constructors.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Path.inject({ statics: new function() {
211211
*/
212212
Circle: function(center, radius) {
213213
var _center = Point.read(arguments),
214-
_radius = Base.readValue(arguments);
214+
_radius = Base.read(arguments);
215215
return createEllipse(new Rectangle(_center.subtract(_radius),
216216
Size.create(_radius * 2, _radius * 2)));
217217
},
@@ -264,8 +264,8 @@ Path.inject({ statics: new function() {
264264
*/
265265
RegularPolygon: function(center, numSides, radius) {
266266
var _center = Point.read(arguments),
267-
_numSides = Base.readValue(arguments),
268-
_radius = Base.readValue(arguments),
267+
_numSides = Base.read(arguments),
268+
_radius = Base.read(arguments),
269269
path = new Path(),
270270
step = 360 / _numSides,
271271
three = !(_numSides % 3),
@@ -304,9 +304,9 @@ Path.inject({ statics: new function() {
304304
*/
305305
Star: function(center, numPoints, radius1, radius2) {
306306
var _center = Point.read(arguments),
307-
_numPoints = Base.readValue(arguments) * 2,
308-
_radius1 = Base.readValue(arguments),
309-
_radius2 = Base.readValue(arguments),
307+
_numPoints = Base.read(arguments) * 2,
308+
_radius1 = Base.read(arguments),
309+
_radius2 = Base.read(arguments),
310310
path = new Path(),
311311
step = 360 / _numPoints,
312312
vector = new Point(0, -1),

src/path/Path.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
17251725
curveTo: function(through, to, parameter) {
17261726
var _through = Point.read(arguments),
17271727
_to = Point.read(arguments),
1728-
t = Base.pick(Base.readValue(arguments), 0.5),
1728+
t = Base.pick(Base.read(arguments), 0.5),
17291729
t1 = 1 - t,
17301730
current = getCurrentSegment(this)._point,
17311731
// handle = (through - (1 - t)^2 * current - t^2 * to) /
@@ -1746,7 +1746,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
17461746
point = Point.read(arguments),
17471747
// Peek at next value to see if it's clockwise,
17481748
// with true as default value.
1749-
next = Base.pick(Base.peekValue(arguments), true);
1749+
next = Base.pick(Base.peek(arguments), true);
17501750
if (typeof next === 'boolean') {
17511751
// arcTo(to, clockwise)
17521752
to = point;
@@ -1872,7 +1872,7 @@ statics: {
18721872
var coords = new Array(6),
18731873
// Make coordinates for first segment available in prevCoords.
18741874
prevCoords = first._transformCoordinates(matrix, new Array(6), false),
1875-
min = prevCoords.slice(0, 2),
1875+
min = prevCoords.slice(0, 2), // Start with values of first point
18761876
max = min.slice(0), // clone
18771877
roots = new Array(2);
18781878

src/project/Project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
226226
// We don't need to do this here, but it speeds up things since we won't
227227
// repeatetly convert in Item#hitTest() then.
228228
point = Point.read(arguments);
229-
options = HitResult.getOptions(Base.readValue(arguments));
229+
options = HitResult.getOptions(Base.read(arguments));
230230
// Loop backwards, so layers that get drawn last are tested first
231231
for (var i = this.layers.length - 1; i >= 0; i--) {
232232
var res = this.layers[i].hitTest(point, options);

0 commit comments

Comments
 (0)