--- a/Point.st Thu Aug 25 11:28:17 2016 +0100
+++ b/Point.st Wed Aug 31 22:45:49 2016 +0100
@@ -39,23 +39,23 @@
documentation
"
I represent a point in 2D space. Or I can be used to represent
- an extent (of a rectangle, for example), in which case my x-coordinate
+ an extent (of a rectangle, for example), in which case my x-coordinate
represents the width, and y-coordinate the height of something.
The x and y coordinates are usually numbers.
[Instance variables:]
- x <Number> the x-coordinate of myself
- y <Number> the y-coordinate of myself
+ x <Number> the x-coordinate of myself
+ y <Number> the y-coordinate of myself
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- Rectangle Polygon
- LayoutOrigin LayoutFrame AlignmentOrigin Layout
- View GraphicsContext
+ Rectangle Polygon
+ LayoutOrigin LayoutFrame AlignmentOrigin Layout
+ View GraphicsContext
"
! !
@@ -95,10 +95,10 @@
^ self r:distance theta:angle degreesToRadians
"
- Point r:100 angle:0
- Point r:100 angle:90
- Point r:100 angle:45
- Point r:100 angle:180
+ Point r:100 angle:0
+ Point r:100 angle:90
+ Point r:100 angle:45
+ Point r:100 angle:180
"
"Modified: 8.5.1996 / 20:01:50 / cg"
@@ -112,7 +112,7 @@
^ self r:distance theta:angle degreesToRadians
"
- Point r:100 degrees:90
+ Point r:100 degrees:90
"
"Modified: 8.5.1996 / 20:01:50 / cg"
@@ -129,8 +129,8 @@
^ x @ y
"
- Point r:100 theta:0
- Point r:100 theta:Float pi/2
+ Point r:100 theta:0
+ Point r:100 theta:Float pi/2
"
"Modified: 2.4.1997 / 00:01:40 / cg"
@@ -142,31 +142,31 @@
if no point can be read."
^ [
- |str newX newY hasParen|
+ |str newX newY hasParen|
- str := aStringOrStream readStream.
- str skipSeparators.
- (hasParen := str peek) == $( ifTrue:[
- str next.
- ].
- newX := Number readFrom:str onError:nil.
- newX notNil ifTrue:[
- (str skipSeparators == $@) ifTrue:[
- str next.
- newY := Number readFrom:str onError:nil.
- newY notNil ifTrue:[
- hasParen ifTrue:[
- str skipSeparators.
- str peek == $) ifTrue:[
- str next.
- ]
- ].
+ str := aStringOrStream readStream.
+ str skipSeparators.
+ (hasParen := str peek) == $( ifTrue:[
+ str next.
+ ].
+ newX := Number readFrom:str onError:nil.
+ newX notNil ifTrue:[
+ (str skipSeparators == $@) ifTrue:[
+ str next.
+ newY := Number readFrom:str onError:nil.
+ newY notNil ifTrue:[
+ hasParen ifTrue:[
+ str skipSeparators.
+ str peek == $) ifTrue:[
+ str next.
+ ]
+ ].
- ^ self x:newX y:newY
- ]
- ]
- ].
- ^ exceptionBlock value
+ ^ self x:newX y:newY
+ ]
+ ]
+ ].
+ ^ exceptionBlock value
] on:Error do:exceptionBlock.
"
@@ -188,21 +188,21 @@
* claus: I am no longer certain, if this primitive is worth the effort
*/
if (__CanDoQuickNew(sizeof(struct __Point))) { /* OBJECT ALLOCATION */
- if (self == @global(Point)) {
- OBJ newPoint;
- int spc;
+ if (self == @global(Point)) {
+ OBJ newPoint;
+ int spc;
- __qCheckedAlignedNew(newPoint, sizeof(struct __Point));
- __InstPtr(newPoint)->o_class = self; __qSTORE(newPoint, self);
- __PointInstPtr(newPoint)->p_x = newX;
- __PointInstPtr(newPoint)->p_y = newY;
- if (! __bothSmallInteger(newX, newY)) {
- spc = __qSpace(newPoint);
- __STORE_SPC(newPoint, newX, spc);
- __STORE_SPC(newPoint, newY, spc);
- }
- RETURN ( newPoint );
- }
+ __qCheckedNew(newPoint, sizeof(struct __Point));
+ __InstPtr(newPoint)->o_class = self; __qSTORE(newPoint, self);
+ __PointInstPtr(newPoint)->p_x = newX;
+ __PointInstPtr(newPoint)->p_y = newY;
+ if (! __bothSmallInteger(newX, newY)) {
+ spc = __qSpace(newPoint);
+ __STORE_SPC(newPoint, newX, spc);
+ __STORE_SPC(newPoint, newY, spc);
+ }
+ RETURN ( newPoint );
+ }
}
%}.
^ (self basicNew) x:newX y:newY
@@ -280,8 +280,8 @@
x:newX
"set the x coordinate to be the argument, aNumber.
- This is destructive (modifies the receiver, not a copy) and
- should only be used if you know, that you are the exclusive owner
+ This is destructive (modifies the receiver, not a copy) and
+ should only be used if you know, that you are the exclusive owner
of the receiver."
x := newX
@@ -289,8 +289,8 @@
x:newX y:newY
"set both the x and y coordinates.
- This is destructive (modifies the receiver, not a copy) and
- should only be used if you know, that you are the exclusive owner
+ This is destructive (modifies the receiver, not a copy) and
+ should only be used if you know, that you are the exclusive owner
of the receiver."
x := newX.
@@ -305,8 +305,8 @@
y:newY
"set the y coordinate to be the argument, aNumber.
- This is destructive (modifies the receiver, not a copy) and
- should only be used if you know, that you are the exclusive owner
+ This is destructive (modifies the receiver, not a copy) and
+ should only be used if you know, that you are the exclusive owner
of the receiver."
y := newY
@@ -342,11 +342,11 @@
"notice the funny result if one coordinate has the same value ...
- (3@4) < (4@4)
- (3@4) <= (4@4)
- (3@4) > (4@4)
- (4@4) >= (3@4)
- (4@4) > (3@4)
+ (3@4) < (4@4)
+ (3@4) <= (4@4)
+ (3@4) > (4@4)
+ (4@4) >= (3@4)
+ (4@4) > (3@4)
"
"Modified: 7.5.1996 / 12:14:25 / cg"
@@ -450,17 +450,17 @@
asFractionalLayout
"return a LayoutOrigin from the receiver,
- treating the receiver coordinates as fractional parts
+ treating the receiver coordinates as fractional parts
(i.e. relative to superview).
Notice: in 10.5.x LayoutOrigin is not yet officially released."
^ LayoutOrigin fractionalFromPoint:self
"
- (0@0.5) asFractionalLayout
- (0@0.5) asLayout
- (0@10) asLayout
- (0@10) asOffsetLayout
+ (0@0.5) asFractionalLayout
+ (0@0.5) asLayout
+ (0@10) asLayout
+ (0@10) asOffsetLayout
"
!
@@ -480,26 +480,26 @@
^ LayoutOrigin fromPoint:self
"
- (0@0.5) asFractionalLayout
- (0@0.5) asLayout
- (0@10) asLayout
- (0@10) asOffsetLayout
+ (0@0.5) asFractionalLayout
+ (0@0.5) asLayout
+ (0@10) asLayout
+ (0@10) asOffsetLayout
"
!
asOffsetLayout
"return a LayoutOrigin from the receiver,
- treating the receiver coordinates as absolute offsets.
+ treating the receiver coordinates as absolute offsets.
Notice: in 10.5.x LayoutOrigin is not yet released."
^ LayoutOrigin offsetFromPoint:self
"
- (0@0.5) asFractionalLayout
- (0@0.5) asLayout
- (0@10) asLayout
- (0@10) asOffsetLayout
+ (0@0.5) asFractionalLayout
+ (0@0.5) asLayout
+ (0@10) asLayout
+ (0@10) asOffsetLayout
"
!
@@ -511,13 +511,13 @@
!
asRectangle
- "return a zero-width rectangle consisting of origin
+ "return a zero-width rectangle consisting of origin
and corner being the receiver"
^ self corner:self
"
- (0@10) asRectangle
+ (0@10) asRectangle
"
!
@@ -551,14 +551,14 @@
The encoding is: (Point xValue yValue)"
^ Array
- with:#Point
- with:x
- with:y
+ with:#Point
+ with:x
+ with:y
"
- Point new fromLiteralArrayEncoding:#(Point 10 20)
- (10@20) literalArrayEncoding
+ Point new fromLiteralArrayEncoding:#(Point 10 20)
+ (10@20) literalArrayEncoding
"
"Modified: 1.9.1995 / 02:18:29 / claus"
@@ -576,10 +576,10 @@
consider the case, where a view has a preferred extent of 50@50
and is to be positioned in its superview which has size 100@100.
For absolute origin:
- (10@20) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50)
+ (10@20) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50)
for relative origin:
- (0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50)
+ (0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50)
"
"Modified: / 27.5.1998 / 10:20:13 / cg"
@@ -590,21 +590,21 @@
scaleBy:aScale
"scale the receiver, by replacing coordinates by the product
of the receiver's coordinates and the scale (a Point or Number).
- This is destructive (modifies the receiver, not a copy) and
- should only be used if you know, that you are the exclusive owner
+ This is destructive (modifies the receiver, not a copy) and
+ should only be used if you know, that you are the exclusive owner
of the receiver."
|scalePoint|
- (aScale isMemberOf:Point) ifTrue:[ "type hint to stc"
- x := x * aScale x.
- y := y * aScale y.
- ^ self
+ (aScale isMemberOf:Point) ifTrue:[ "type hint to stc"
+ x := x * aScale x.
+ y := y * aScale y.
+ ^ self
].
aScale isNumber ifTrue:[
- x := x * aScale.
- y := y * aScale.
- ^ self
+ x := x * aScale.
+ y := y * aScale.
+ ^ self
].
"this is the general (& clean) code ..."
@@ -617,21 +617,21 @@
translateBy:anOffset
"translate the receiver, by replacing coordinates by the sum
of the receiver's coordinated and the scale (a Point or Number).
- This is destructive (modifies the receiver, not a copy) and
- should only be used if you know, that you are the exclusive owner
+ This is destructive (modifies the receiver, not a copy) and
+ should only be used if you know, that you are the exclusive owner
of the receiver."
|offsetPoint|
- (anOffset isMemberOf:Point) ifTrue:[ "type hint to stc"
- x := x + anOffset x.
- y := y + anOffset y.
- ^ self
+ (anOffset isMemberOf:Point) ifTrue:[ "type hint to stc"
+ x := x + anOffset x.
+ y := y + anOffset y.
+ ^ self
].
anOffset isNumber ifTrue:[
- x := x + anOffset.
- y := y + anOffset.
- ^ self
+ x := x + anOffset.
+ y := y + anOffset.
+ ^ self
].
"this is the general (& clean) code ..."
@@ -650,9 +650,9 @@
^ self + ((end - self) * amountDone).
"
- (10@10) interpolateTo:(20@20) at:0.5
- (10@10) interpolateTo:(20@20) at:0.3
- (0@0) interpolateTo:(0@20) at:0.5
+ (10@10) interpolateTo:(20@20) at:0.5
+ (10@10) interpolateTo:(20@20) at:0.3
+ (0@0) interpolateTo:(0@20) at:0.5
"
! !
@@ -669,7 +669,7 @@
Return the receiver if its coordinates are already integral."
(x isInteger and:[y isInteger]) ifTrue: [
- ^ self
+ ^ self
].
^ self class x:x ceiling y:y ceiling.
@@ -680,7 +680,7 @@
Return the receiver if its coordinates are already integral."
(x isInteger and:[y isInteger]) ifTrue: [
- ^ self
+ ^ self
].
^ self class x:(x floor) y:(y floor)
@@ -690,11 +690,11 @@
"return the number of the quadrant containing the receiver.
quadrants are named as follows:
- ^ 2 | 3
- Y ------
- 1 | 0
+ ^ 2 | 3
+ Y ------
+ 1 | 0
- X >
+ X >
Q: what is to be returned if any coordinate is 0 ?
"
@@ -702,17 +702,17 @@
^ 0@0 quadrantContaining:self
"
- (1@1) quadrant
- (-1@1) quadrant
- (-1@-1) quadrant
- (1@-1) quadrant
- (0@0) quadrant
+ (1@1) quadrant
+ (-1@1) quadrant
+ (-1@-1) quadrant
+ (1@-1) quadrant
+ (0@0) quadrant
"
!
quadrantContaining:aPoint
- "return the number of the quadrant containing aPoint placing
- the receiver at the origin, where the quadrants are numbered as
+ "return the number of the quadrant containing aPoint placing
+ the receiver at the origin, where the quadrants are numbered as
follows:
^ 2 | 3
Y ------
@@ -726,14 +726,14 @@
aPoint y >= y ifTrue:[^ 3].
^ 0
].
- aPoint y >= y ifTrue: [^ 2].
+ aPoint y >= y ifTrue: [^ 2].
^ 1
"
(10 @ 10) quadrantContaining:(15 @ 15)
- (10 @ 10) quadrantContaining:(5 @ 5)
- (10 @ 10) quadrantContaining:(5 @ 15)
- (10 @ 10) quadrantContaining:(15 @ 5)
+ (10 @ 10) quadrantContaining:(5 @ 5)
+ (10 @ 10) quadrantContaining:(5 @ 15)
+ (10 @ 10) quadrantContaining:(15 @ 5)
"
!
@@ -742,7 +742,7 @@
Return the receiver if its coordinates are already integral."
(x isInteger and:[y isInteger]) ifTrue: [
- ^ self
+ ^ self
].
^ self class x:(x rounded) y:(y rounded)
@@ -764,7 +764,7 @@
Return the receiver if its coordinates are already integral."
(x isInteger and:[y isInteger]) ifTrue: [
- ^ self
+ ^ self
].
^ self class x:(x truncated) y:(y truncated)
@@ -772,8 +772,8 @@
!Point methodsFor:'point functions'!
-crossProduct: aPoint
- "Return a number that is the cross product of the receiver and the
+crossProduct: aPoint
+ "Return a number that is the cross product of the receiver and the
argument, aPoint."
^ (x * aPoint y) - (y * aPoint x)
@@ -781,13 +781,13 @@
!
-dist:aPoint
+dist:aPoint
"return the distance between aPoint and the receiver."
^ (aPoint - self) r
!
-dotProduct:aPoint
+dotProduct:aPoint
"return a number that is the dot product of the receiver and
the argument, aPoint. That is, the two points are
multiplied and the coordinates of the result summed."
@@ -796,11 +796,11 @@
!
fourNeighbors
- ^ Array
- with: self + (1@0)
- with: self + (0@1)
- with: self + (-1@0)
- with: self + (0@-1)
+ ^ Array
+ with: self + (1@0)
+ with: self + (0@1)
+ with: self + (-1@0)
+ with: self + (0@-1)
!
grid:gridPoint
@@ -824,9 +824,9 @@
^ newX @ newY
!
-nearestIntegerPointOnLineFrom: point1 to: point2
- "return the closest integer point to the receiver on the line
- determined by (point1, point2)--much faster than the more
+nearestIntegerPointOnLineFrom: point1 to: point2
+ "return the closest integer point to the receiver on the line
+ determined by (point1, point2)--much faster than the more
accurate version if the receiver and arguments are integer points.
This method was found in the Manchester goody library."
@@ -858,7 +858,7 @@
] ifFalse:[
dX2 := dX * dX.
dY2 := dY * dY.
- coeff := ((dX * (y - point1 y)) -
+ coeff := ((dX * (y - point1 y)) -
((x - point1 x) * dY)) / (dX2 + dY2).
newX := x + (dY * coeff).
newY := y - (dX * coeff).
@@ -872,8 +872,8 @@
scale < 0 ifTrue: [point1] ifFalse: [intersect]]) rounded
"
- 120@40 nearestIntegerPointOnLineFrom: 30@120 to: 100@120
- 0@0 nearestIntegerPointOnLineFrom: 10@10 to: 100@100
+ 120@40 nearestIntegerPointOnLineFrom: 30@120 to: 100@120
+ 0@0 nearestIntegerPointOnLineFrom: 10@10 to: 100@100
"
!
@@ -885,13 +885,13 @@
^ self / self r
"
- (10 @ 10) normalized
- (1 @ 1) normalized
- (10 @ 0) normalized
- (0 @ 10) normalized
- (-10 @ 0) normalized
- (0 @ -10) normalized
- (0 @ 0) normalized
+ (10 @ 10) normalized
+ (1 @ 1) normalized
+ (10 @ 0) normalized
+ (0 @ 10) normalized
+ (-10 @ 0) normalized
+ (0 @ -10) normalized
+ (0 @ 0) normalized
"
!
@@ -903,7 +903,7 @@
!Point methodsFor:'polar coordinates'!
-angle
+angle
"return the receiver's angle (in degrees) in a polar coordinate system.
(i.e. the angle of a vector from 0@0 to the receiver).
OBSOLETE ST/X interface; use theta for ST-80 compatibility."
@@ -913,9 +913,9 @@
^ self theta radiansToDegrees
"
- (1@1) angle
- (1@0) angle
- (2@1) angle
+ (1@1) angle
+ (1@0) angle
+ (2@1) angle
"
"Modified: 2.4.1997 / 00:02:17 / cg"
@@ -931,8 +931,8 @@
^ self theta radiansToDegrees
"
- (1@1) degrees
- (2@1) degrees
+ (1@1) degrees
+ (2@1) degrees
"
!
@@ -943,43 +943,43 @@
^ ((x*x) + (y*y)) sqrt
"
- (1@1) r
- (2@1) r
- (2@0) r
- (0@2) r
- (-2@-2) r
- (2@2) r
+ (1@1) r
+ (2@1) r
+ (2@0) r
+ (0@2) r
+ (-2@-2) r
+ (2@2) r
"
!
-theta
+theta
"return the receiver's angle (in radians) in a polar coordinate system.
(i.e. the angle of a vector from 0@0 to the receiver)"
|theta t|
x = 0 ifTrue:[
- y >= 0 ifTrue:[
- ^ Float pi * 0.5
- ].
- ^ Float pi * 1.5.
+ y >= 0 ifTrue:[
+ ^ Float pi * 0.5
+ ].
+ ^ Float pi * 1.5.
].
t := y asFloat / x asFloat.
theta := t arcTan.
x < 0 ifTrue:[
- ^ theta + Float pi
+ ^ theta + Float pi
].
theta < 0 ifTrue:[
- ^ theta + (Float pi * 2.0)
+ ^ theta + (Float pi * 2.0)
].
^ theta.
"
- (1@1) theta
- (2@1) theta
- (-2@1) theta
- (-2@-1) theta
- (0@-1) theta
+ (1@1) theta
+ (2@1) theta
+ (-2@1) theta
+ (-2@-1) theta
+ (0@-1) theta
"
"Modified: 2.4.1997 / 00:15:12 / cg"
@@ -1025,22 +1025,22 @@
!Point methodsFor:'transformations'!
-* scale
- "Return a new Point that is the product of the
+* scale
+ "Return a new Point that is the product of the
receiver and scale (which is a Point or Number)."
|scalePoint|
"speedup for common cases ..."
- (scale isMemberOf:Point) ifTrue:[
- ^ self class x:(x * scale x) y:(y * scale y)
+ (scale isMemberOf:Point) ifTrue:[
+ ^ self class x:(x * scale x) y:(y * scale y)
].
(scale isMemberOf:SmallInteger) ifTrue:[
- ^ self class x:(x * scale) y:(y * scale)
+ ^ self class x:(x * scale) y:(y * scale)
].
scale isNumber ifTrue:[
- ^ self class x:(x * scale) y:(y * scale)
+ ^ self class x:(x * scale) y:(y * scale)
].
"this is the general (& clean) code ..."
@@ -1051,23 +1051,23 @@
"Modified: 25.1.1997 / 17:28:11 / cg"
!
-+ translation
- "Return a new Point that is the sum of the
++ translation
+ "Return a new Point that is the sum of the
receiver and translation (which is a Point or Number)."
|translationPoint|
"speedup for common cases ..."
- (translation isMemberOf:Point) ifTrue:[
- ^ self class x:(x + translation x) y:(y + translation y)
+ (translation isMemberOf:Point) ifTrue:[
+ ^ self class x:(x + translation x) y:(y + translation y)
].
(translation isMemberOf:SmallInteger) ifTrue:[
- "/ same as below, but stc can do better here
- ^ self class x:(x + translation) y:(y + translation)
+ "/ same as below, but stc can do better here
+ ^ self class x:(x + translation) y:(y + translation)
].
translation isNumber ifTrue:[
- ^ self class x:(x + translation) y:(y + translation)
+ ^ self class x:(x + translation) y:(y + translation)
].
"this is the general (& clean) code ..."
@@ -1078,23 +1078,23 @@
"Modified: 25.1.1997 / 17:27:46 / cg"
!
-- translation
- "Return a new Point that is the difference of the
+- translation
+ "Return a new Point that is the difference of the
receiver and translation (which is a Point or Number)."
|translationPoint|
"speedup for common cases ..."
- (translation isMemberOf:Point) ifTrue:[
- ^ self class x:(x - translation x) y:(y - translation y)
+ (translation isMemberOf:Point) ifTrue:[
+ ^ self class x:(x - translation x) y:(y - translation y)
].
(translation isMemberOf:SmallInteger) ifTrue:[
- "/ same as below, but stc can do better here
- ^ self class x:(x - translation) y:(y - translation)
+ "/ same as below, but stc can do better here
+ ^ self class x:(x - translation) y:(y - translation)
].
translation isNumber ifTrue:[
- ^ self class x:(x - translation) y:(y - translation)
+ ^ self class x:(x - translation) y:(y - translation)
].
"this is the general (& clean) code ..."
@@ -1105,19 +1105,19 @@
"Modified: 25.1.1997 / 17:27:46 / cg"
!
-/ scale
- "Return a new Point that is the integer quotient of the
+/ scale
+ "Return a new Point that is the integer quotient of the
receiver and scale (which is a Point or Number)."
|scalePoint|
"speedup for common cases ..."
- (scale isMemberOf:Point) ifTrue:[
- self class x:(x / scale x) y:(y / scale y)
+ (scale isMemberOf:Point) ifTrue:[
+ self class x:(x / scale x) y:(y / scale y)
].
scale isNumber ifTrue:[
- ^ self class x:(x / scale) y:(y / scale)
+ ^ self class x:(x / scale) y:(y / scale)
].
"this is the general (& clean) code ..."
@@ -1126,8 +1126,8 @@
^ self class x:(x / scalePoint x) y:(y / scalePoint y)
!
-// scale
- "Return a new Point that is the quotient of the
+// scale
+ "Return a new Point that is the quotient of the
receiver and scale (which is a Point or Number)."
|scalePoint|
@@ -1137,13 +1137,13 @@
!
negated
- "return a new point with my coordinates negated
+ "return a new point with my coordinates negated
i.e. the receiver mirrored at the origin"
^ self class x:x negated y:y negated
"
- (1 @ 1) negated
+ (1 @ 1) negated
"
!
@@ -1157,7 +1157,7 @@
rotateBy:angle about:center
"Return a new point, generated by rotating the receiver
counterClockWise by some angle in radians around the given center point.
- Even though Point.theta is measured CW,
+ Even though Point.theta is measured CW,
this rotates with the more conventional CCW interpretateion of angle."
|p r theta|
@@ -1166,23 +1166,23 @@
r := p r.
theta := angle asFloat - p theta.
^ self class x:(center x asFloat + (r * theta cos))
- y:(center y asFloat - (r * theta sin))
+ y:(center y asFloat - (r * theta sin))
"
- (10@10) rotateBy:Float pi about:0@0
- (10@0) rotateBy:Float pi about:0@0
+ (10@10) rotateBy:Float pi about:0@0
+ (10@0) rotateBy:Float pi about:0@0
"
!
scaledBy:aScale
- "return a new Point that is the product of the
+ "return a new Point that is the product of the
receiver and scale (which is a Point or Number)."
^ self * aScale
!
translatedBy:anOffset
- "return a new Point that is the sum of the
+ "return a new Point that is the sum of the
receiver and scale (which is a Point or Number)."
^ self + anOffset