--- a/Point.st Fri Apr 07 10:10:40 2000 +0200
+++ b/Point.st Fri Apr 07 10:12:55 2000 +0200
@@ -10,6 +10,8 @@
hereby transferred.
"
+"{ Package: 'stx:libbasic' }"
+
ArithmeticValue subclass:#Point
instanceVariableNames:'x y'
classVariableNames:'PointZero PointOne'
@@ -599,6 +601,20 @@
y := y + anOffset y
! !
+!Point methodsFor:'interpolating'!
+
+interpolateTo: end at: amountDone
+ "Interpolate between the instance and end after the specified amount has been done (0 - 1)."
+
+ ^ 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
+ "
+! !
+
!Point methodsFor:'misc'!
abs
@@ -608,13 +624,23 @@
!
ceiling
- "return a new point with my coordinates truncated towards positive infinity."
+ "return a new point with my coordinates truncated towards positive infinity.
+ Return the receiver if its coordinates are already integral."
+
+ (x isInteger and:[y isInteger]) ifTrue: [
+ ^ self
+ ].
^ (x ceiling) @ (y ceiling)
!
floor
- "return a new point with my coordinates truncated towards negative infinity."
+ "return a new point with my coordinates truncated towards negative infinity.
+ Return the receiver if its coordinates are already integral."
+
+ (x isInteger and:[y isInteger]) ifTrue: [
+ ^ self
+ ].
^ (x floor) @ (y floor)
!
@@ -678,9 +704,18 @@
!
rounded
- "return a new point with my coordinates rounded to the next integer."
+ "return a new point with my coordinates rounded to the next integer.
+ Return the receiver if its coordinates are already integral."
+ (x isInteger and:[y isInteger]) ifTrue: [
+ ^ self
+ ].
^ (x rounded) @ (y rounded)
+
+ "
+ (1.5 @ 2.6) rounded
+ (1 @ 2) rounded
+ "
!
truncateTo:aNumber
@@ -691,13 +726,27 @@
!
truncated
- "return a new point with my coordinates truncated as integer."
+ "return a new point with my coordinates truncated as integer.
+ Return the receiver if its coordinates are already integral."
+
+ (x isInteger and:[y isInteger]) ifTrue: [
+ ^ self
+ ].
^ (x truncated) @ (y truncated)
! !
!Point methodsFor:'point functions'!
+crossProduct: aPoint
+ "Return a number that is the cross product of the receiver and the
+ argument, aPoint."
+
+ ^ (x * aPoint y) - (y * aPoint x)
+
+
+!
+
dist:aPoint
"return the distance between aPoint and the receiver."
@@ -787,6 +836,30 @@
120@40 nearestIntegerPointOnLineFrom: 30@120 to: 100@120
0@0 nearestIntegerPointOnLineFrom: 10@10 to: 100@100
"
+!
+
+normalized
+ "interpreting myself as the endPoint of a 0@0 based vector,
+ return the endPoint of the corresponding normalized vector.
+ (that is the endPoint of a vector with the same direction but length 1)"
+
+ ^ self / self r
+
+ "
+ (10 @ 10) normalized
+ (1 @ 1) normalized
+ (10 @ 0) normalized
+ (0 @ 10) normalized
+ (-10 @ 0) normalized
+ (0 @ -10) normalized
+ (0 @ 0) normalized
+ "
+!
+
+transposed
+ "return a new point with x and y coordinates exchanged"
+
+ ^ y@x
! !
!Point methodsFor:'polar coordinates'!
@@ -1061,6 +1134,6 @@
!Point class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.54 2000-03-24 11:54:42 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.55 2000-04-07 08:12:55 cg Exp $'
! !
Point initialize!