Point.st
author Stefan Vogel <sv@exept.de>
Wed, 30 Aug 2000 14:35:40 +0200
changeset 5567 2cc43ea7394f
parent 5361 dbf17a65f6bd
child 6624 886265eff14c
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    13
"{ Package: 'stx:libbasic' }"
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
ArithmeticValue subclass:#Point
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	instanceVariableNames:'x y'
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	classVariableNames:'PointZero PointOne'
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	poolDictionaries:''
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	category:'Graphics-Geometry'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    22
!Point class methodsFor:'documentation'!
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    23
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
    27
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    38
documentation
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    39
"
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    40
    I represent a point in 2D space. Or I can be used to represent
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    41
    an extent (of a rectangle, for example), in which case my x-coordinate 
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    42
    represents the width, and y-coordinate the height of something.
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    43
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    44
    The x and y coordinate are usually numbers.
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    45
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    46
    [Instance variables:]
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    47
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    48
	x              <Number>        the x-coordinate of myself
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    49
	y              <Number>        the y-coordinate of myself
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    50
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    51
    [author:]
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    52
	Claus Gittinger
1314
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    53
18fabbc0e0a6 examples
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
    54
    [see also:]
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    55
	Rectangle Polygon
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    56
	LayoutOrigin LayoutFrame AlignmentOrigin Layout 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    57
	View GraphicsContext
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    58
"
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    59
! !
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
    60
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    61
!Point class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
initialize
302
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    64
    PointZero isNil ifTrue:[
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    65
	PointZero := 0 @ 0.
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    66
	PointOne  := 1 @ 1
1f76060d58a4 *** empty log message ***
claus
parents: 293
diff changeset
    67
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    70
!Point class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
3238
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    72
decodeFromLiteralArray:anArray
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    73
    "create & return a new instance from information encoded in anArray.
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    74
     Redefined for faster creation."
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    75
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    76
    ^ self x:(anArray at:2) y:(anArray at:3)
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    77
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    78
    "
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    79
     Point
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
    80
	decodeFromLiteralArray:#(Point 10 10)
3238
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    81
    "
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    82
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    83
    "Created: / 28.1.1998 / 17:44:08 / cg"
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    84
!
f96eaf89d55d faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents: 2894
diff changeset
    85
1354
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    86
r:distance angle:angle
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    87
    "create and return a new point given polar coordinates.
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    88
     The angle is given in degrees"
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    89
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    90
    |x y rad|
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    91
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    92
    rad := angle degreesToRadians.
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    93
    x := distance * rad cos.
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    94
    y := distance * rad sin.
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    95
    ^ x @ y
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    96
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    97
    "
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    98
     Point r:100 angle:0  
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
    99
     Point r:100 angle:90  
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   100
     Point r:100 angle:45  
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   101
     Point r:100 angle:180  
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   102
    "
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   103
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   104
    "Modified: 8.5.1996 / 20:01:50 / cg"
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   105
!
Claus Gittinger <cg@exept.de>
parents: 1339
diff changeset
   106
4893
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   107
r:distance degrees:angle
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   108
    "create and return a new point given polar coordinates.
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   109
     The angle is given in degrees.
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   110
     Added for Squeak compatibility"
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   111
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   112
    ^ self r:distance angle:angle
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   113
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   114
    "
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   115
     Point r:100 degrees:90  
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   116
    "
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   117
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   118
    "Modified: 8.5.1996 / 20:01:50 / cg"
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   119
!
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
   120
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   121
r:distance theta:angleInRadians
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   122
    "create and return a new point given polar coordinates.
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   123
     The angle is given in radians"
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   124
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   125
    |x y|
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   126
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   127
    x := distance * angleInRadians cos.
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   128
    y := distance * angleInRadians sin.
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   129
    ^ x @ y
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   130
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   131
    "
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   132
     Point r:100 theta:0  
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   133
    "
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   134
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   135
    "Modified: 2.4.1997 / 00:01:40 / cg"
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   136
!
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   137
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   138
readFrom:aStringOrStream onError:exceptionBlock
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
    "return the next Point from the (character-)stream aStream;
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 180
diff changeset
   140
     skipping all whitespace first; return the value of exceptionBlock,
40ca7cc6fb9c *** empty log message ***
claus
parents: 180
diff changeset
   141
     if no point can be read."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1354
diff changeset
   143
    ErrorSignal handle:[:ex |
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   144
	^ exceptionBlock value
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1354
diff changeset
   145
    ] do:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   146
	|str newX newY|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   147
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   148
	str := aStringOrStream readStream.
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   149
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   150
	newX := Number readFrom:str onError:nil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   151
	newX notNil ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   152
	    (str skipSeparators == $@) ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   153
		str  next.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   154
		newY := Number readFrom:str onError:nil.
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   155
		newY notNil ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   156
		    ^ self x:newX y:newY
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   157
		]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   158
	    ]
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   159
	].
345
claus
parents: 339
diff changeset
   160
    ].
claus
parents: 339
diff changeset
   161
    ^ exceptionBlock value
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   162
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 180
diff changeset
   163
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 180
diff changeset
   164
     Point readFrom:('1.234 @ 5.678' readStream)
345
claus
parents: 339
diff changeset
   165
     Point readFrom:('1' readStream)
claus
parents: 339
diff changeset
   166
     Point readFrom:('1' readStream) onError:[1@1]
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 180
diff changeset
   167
     Point readFrom:('fooBar' readStream) onError:[0@0]
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   168
    "
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   169
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1354
diff changeset
   170
    "Modified: 8.10.1996 / 19:31:39 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   171
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   172
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   173
x:newX y:newY
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   174
    "create and return a new point with coordinates newX and newY"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   175
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   176
%{  /* NOCONTEXT */
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   177
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   178
    /*
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   179
     * claus: I am no longer certain, if this primitive is worth the effort
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   180
     */
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   181
    if (__CanDoQuickNew(sizeof(struct __Point))) {      /* OBJECT ALLOCATION */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   182
	if (self == @global(Point)) {
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   183
	    OBJ newPoint;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   184
	    int spc;
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   185
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   186
	    __qCheckedAlignedNew(newPoint, sizeof(struct __Point));
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   187
	    __InstPtr(newPoint)->o_class = self;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   188
	    __PointInstPtr(newPoint)->p_x = newX;
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   189
	    __PointInstPtr(newPoint)->p_y = newY;
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   190
	    if (! __bothSmallInteger(newX, newY)) {
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   191
		spc = __qSpace(newPoint);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   192
		__STORE_SPC(newPoint, newX, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   193
		__STORE_SPC(newPoint, newY, spc);
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   194
	    }
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   195
	    RETURN ( newPoint );
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   196
	}
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   197
    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   198
%}.
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   199
    ^ (self basicNew) x:newX y:newY
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   200
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   201
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   202
!Point class methodsFor:'constants'!
356
claus
parents: 345
diff changeset
   203
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   204
unity
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   205
    "return the neutral element for multiplication"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   206
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   207
    ^ PointOne
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   208
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   209
356
claus
parents: 345
diff changeset
   210
zero
claus
parents: 345
diff changeset
   211
    "return the neutral element for addition"
claus
parents: 345
diff changeset
   212
claus
parents: 345
diff changeset
   213
    ^ PointZero
claus
parents: 345
diff changeset
   214
! !
claus
parents: 345
diff changeset
   215
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   216
!Point class methodsFor:'queries'!
356
claus
parents: 345
diff changeset
   217
claus
parents: 345
diff changeset
   218
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
   219
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
   220
     Here, true is returned for myself, false for subclasses."
356
claus
parents: 345
diff changeset
   221
claus
parents: 345
diff changeset
   222
    ^ self == Point
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
   223
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1245
diff changeset
   224
    "Modified: 23.4.1996 / 16:00:18 / cg"
356
claus
parents: 345
diff changeset
   225
! !
claus
parents: 345
diff changeset
   226
4984
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   227
!Point methodsFor:'Compatibility - Squeak'!
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   228
5006
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   229
adhereTo: aRectangle
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   230
    "If the receiver lies outside aRectangle, return the nearest point on the boundary of the rectangle, otherwise return self."
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   231
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   232
    (aRectangle containsPoint: self) ifTrue: [^ self].
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   233
    ^ ((x max: aRectangle left) min: aRectangle right)
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   234
      @
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   235
      ((y max: aRectangle top) min: aRectangle bottom)
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   236
!
8a211e38846d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4984
diff changeset
   237
4984
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   238
asFloatPoint
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   239
    "Squeak mimicri return the receiver as Point - this is the receiver"
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   240
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   241
    ^ self
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   242
! !
e20cd6bdc182 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4893
diff changeset
   243
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   244
!Point methodsFor:'accessing'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   245
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   246
x
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   247
    "return the x coordinate"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   248
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   249
    ^ x
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   250
!
356
claus
parents: 345
diff changeset
   251
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   252
x:newX
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   253
    "set the x coordinate to be the argument, aNumber.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   254
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   255
     should only be used if you know, that you are the exclusive owner 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   256
     of the receiver."
356
claus
parents: 345
diff changeset
   257
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   258
    x := newX
356
claus
parents: 345
diff changeset
   259
!
claus
parents: 345
diff changeset
   260
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   261
x:newX y:newY
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   262
    "set both the x and y coordinates.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   263
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   264
     should only be used if you know, that you are the exclusive owner 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   265
     of the receiver."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   266
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   267
    x := newX.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   268
    y := newY
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   269
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   270
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   271
y
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   272
    "return the y coordinate"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   273
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   274
    ^ y
356
claus
parents: 345
diff changeset
   275
!
claus
parents: 345
diff changeset
   276
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   277
y:newY
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   278
    "set the y coordinate to be the argument, aNumber.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   279
     This is destructive (modifies the receiver, not a copy) and 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   280
     should only be used if you know, that you are the exclusive owner 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   281
     of the receiver."
356
claus
parents: 345
diff changeset
   282
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   283
    y := newY
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   284
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   285
5567
2cc43ea7394f *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5361
diff changeset
   286
!Point methodsFor:'coercing & converting'!
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   287
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   288
coerce:anObject
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   289
    "return aNumber converted into receivers type"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   290
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   291
    ^ anObject asPoint
356
claus
parents: 345
diff changeset
   292
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   293
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   294
generality
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   295
    "return the generality value - see ArithmeticValue>>retry:coercing:"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   296
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   297
    ^ 120
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   298
! !
356
claus
parents: 345
diff changeset
   299
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   300
!Point methodsFor:'comparing'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   301
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   302
< aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   303
    "return true if the receiver is above and to the left
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   304
     of the argument, aPoint"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   305
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   306
    |p|
356
claus
parents: 345
diff changeset
   307
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   308
    p := aPoint asPoint.
1339
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   309
    x < (p x) ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   310
	y < (p y) ifTrue:[^ true].
1339
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   311
    ].
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   312
    ^ false
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   313
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   314
    "notice the funny result if one coordinate has the same value ...
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   315
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   316
     (3@4) < (4@4)    
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   317
     (3@4) <= (4@4)    
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   318
     (3@4) > (4@4) 
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   319
     (4@4) >= (3@4)   
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   320
     (4@4) > (3@4)   
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   321
    "
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   322
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   323
    "Modified: 7.5.1996 / 12:14:25 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   324
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   325
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   326
= aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   327
    "return true if the receiver represents the same point as
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   328
     the argument, aPoint"
356
claus
parents: 345
diff changeset
   329
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   330
    |p|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   331
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   332
    (aPoint isMemberOf:Point) ifTrue:[     "this is a hint to STC"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
	x ~= (aPoint x) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   334
	y ~= (aPoint y) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   335
	^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   336
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   337
    aPoint respondsToArithmetic ifFalse:[ ^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   338
    p := aPoint asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   339
    x ~= (p x) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   340
    y ~= (p y) ifTrue:[^ false].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   341
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   342
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   343
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   344
> aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   345
    "return true if  the receiver is below and to the right
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   346
     of the argument, aPoint"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   347
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   348
    |p|
356
claus
parents: 345
diff changeset
   349
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   350
    p := aPoint asPoint.
1339
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   351
    (p x) < x ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   352
	(p y) < y ifTrue:[^ true].
1339
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   353
    ].
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   354
    ^ false
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   355
e65288686de2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
   356
    "Modified: 7.5.1996 / 12:11:15 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   357
!
356
claus
parents: 345
diff changeset
   358
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   359
hash
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   360
    "return a number for hashing"
356
claus
parents: 345
diff changeset
   361
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   362
    x = y ifTrue:[^ x hash].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
 used to be:
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   365
    ^ (x hash) bitXor:(y hash)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   366
 the following handles 1@x vs. x@1 better:
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   367
"
4857
c29c6910114b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3636
diff changeset
   368
    ^ (x hash) bitXor:(y hash bitShift:16)
c29c6910114b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3636
diff changeset
   369
c29c6910114b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3636
diff changeset
   370
c29c6910114b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3636
diff changeset
   371
c29c6910114b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3636
diff changeset
   372
c29c6910114b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3636
diff changeset
   373
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   374
!
356
claus
parents: 345
diff changeset
   375
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   376
max:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   377
    "return the lower right corner of the rectangle uniquely defined by
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   378
     the receiver and the argument, aPoint"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   379
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   380
    |p maxX maxY|
356
claus
parents: 345
diff changeset
   381
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   382
    p := aPoint asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   383
    maxX := x max:(p x).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   384
    maxY := y max:(p y).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   385
    ^ maxX @ maxY
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   386
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   387
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   388
min:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   389
    "return the upper left corner of the rectangle uniquely defined by
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   390
     the receiver and the argument, aPoint"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   391
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   392
    |p minX minY|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   393
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   394
    p := aPoint asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   395
    minX := x min:(p x).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   396
    minY := y min:(p y).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   397
    ^ minX @ minY
356
claus
parents: 345
diff changeset
   398
! !
claus
parents: 345
diff changeset
   399
claus
parents: 345
diff changeset
   400
!Point methodsFor:'converting'!
claus
parents: 345
diff changeset
   401
3636
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   402
asComplex
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   403
    "Return a complex number whose real and imaginary components are the x and y
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   404
     coordinates of the receiver."
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   405
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   406
    ^ x % y
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   407
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   408
    "Modified: / 9.7.1998 / 10:21:10 / cg"
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   409
!
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   410
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   411
asFractionalLayout
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   412
    "return a LayoutOrigin from the receiver,
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   413
     treating the receiver coordinates as fractional parts 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   414
     (i.e. relative to superview).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   415
     Notice: in 10.5.x LayoutOrigin is not yet officially released."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   416
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   417
    ^ LayoutOrigin fractionalFromPoint:self
356
claus
parents: 345
diff changeset
   418
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   419
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   420
     (0@0.5) asFractionalLayout 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   421
     (0@0.5) asLayout           
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   422
     (0@10) asLayout             
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   423
     (0@10) asOffsetLayout      
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   424
    "
356
claus
parents: 345
diff changeset
   425
claus
parents: 345
diff changeset
   426
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
4865
55da20740fcd added #asIntegerPoint.
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   428
asIntegerPoint
55da20740fcd added #asIntegerPoint.
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   429
    (x isInteger and:[y isInteger]) ifTrue:[ ^ self].
55da20740fcd added #asIntegerPoint.
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   430
    ^ x asInteger @ y asInteger
55da20740fcd added #asIntegerPoint.
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   431
!
55da20740fcd added #asIntegerPoint.
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   432
356
claus
parents: 345
diff changeset
   433
asLayout
claus
parents: 345
diff changeset
   434
    "return a LayoutOrigin from the receiver.
claus
parents: 345
diff changeset
   435
     If the receiver coordinates are between 0 and 1, take
claus
parents: 345
diff changeset
   436
     them as fractional parts (relative to superview).
claus
parents: 345
diff changeset
   437
     Otherwise, treat them as absolute offsets.
claus
parents: 345
diff changeset
   438
     Notice: in 10.5.x LayoutOrigin is not yet released."
claus
parents: 345
diff changeset
   439
claus
parents: 345
diff changeset
   440
    ^ LayoutOrigin fromPoint:self
claus
parents: 345
diff changeset
   441
claus
parents: 345
diff changeset
   442
    "
claus
parents: 345
diff changeset
   443
     (0@0.5) asFractionalLayout 
claus
parents: 345
diff changeset
   444
     (0@0.5) asLayout           
claus
parents: 345
diff changeset
   445
     (0@10) asLayout             
claus
parents: 345
diff changeset
   446
     (0@10) asOffsetLayout      
claus
parents: 345
diff changeset
   447
    "
claus
parents: 345
diff changeset
   448
claus
parents: 345
diff changeset
   449
!
claus
parents: 345
diff changeset
   450
claus
parents: 345
diff changeset
   451
asOffsetLayout
claus
parents: 345
diff changeset
   452
    "return a LayoutOrigin from the receiver,
claus
parents: 345
diff changeset
   453
     treating the receiver coordinates as absolute offsets. 
claus
parents: 345
diff changeset
   454
     Notice: in 10.5.x LayoutOrigin is not yet released."
claus
parents: 345
diff changeset
   455
claus
parents: 345
diff changeset
   456
    ^ LayoutOrigin offsetFromPoint:self
claus
parents: 345
diff changeset
   457
claus
parents: 345
diff changeset
   458
    "
claus
parents: 345
diff changeset
   459
     (0@0.5) asFractionalLayout 
claus
parents: 345
diff changeset
   460
     (0@0.5) asLayout           
claus
parents: 345
diff changeset
   461
     (0@10) asLayout             
claus
parents: 345
diff changeset
   462
     (0@10) asOffsetLayout      
claus
parents: 345
diff changeset
   463
    "
claus
parents: 345
diff changeset
   464
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   466
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   467
asPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   468
    "return the receiver as Point - this is the receiver"
356
claus
parents: 345
diff changeset
   469
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   470
    ^ self
356
claus
parents: 345
diff changeset
   471
!
claus
parents: 345
diff changeset
   472
claus
parents: 345
diff changeset
   473
asRectangle
claus
parents: 345
diff changeset
   474
    "return a zero-width rectangle consisting of origin 
claus
parents: 345
diff changeset
   475
     and corner being the receiver"
claus
parents: 345
diff changeset
   476
claus
parents: 345
diff changeset
   477
    ^ self corner:self
claus
parents: 345
diff changeset
   478
claus
parents: 345
diff changeset
   479
    "
claus
parents: 345
diff changeset
   480
     (0@10) asRectangle             
claus
parents: 345
diff changeset
   481
    "
claus
parents: 345
diff changeset
   482
!
claus
parents: 345
diff changeset
   483
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   484
corner:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   485
    "return a rectangle whose origin is self and corner is aPoint"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   486
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   487
    ^ Rectangle origin:self corner:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   488
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   489
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   490
extent:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   491
    "return a rectangle whose origin is self and extent is aPoint"
356
claus
parents: 345
diff changeset
   492
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   493
    ^ Rectangle origin:self extent:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   494
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   495
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   496
fromLiteralArrayEncoding:encoding
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   497
    "read my values from an encoding.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   498
     The encoding is supposed to be of the form: (Point xValue yValue)"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   499
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   500
    x := encoding at:2.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   501
    y := encoding at:3.
356
claus
parents: 345
diff changeset
   502
claus
parents: 345
diff changeset
   503
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   504
     Point new fromLiteralArrayEncoding:#(Point 10 20)
356
claus
parents: 345
diff changeset
   505
    "
379
5b5a130ccd09 revision added
claus
parents: 359
diff changeset
   506
!
5b5a130ccd09 revision added
claus
parents: 359
diff changeset
   507
421
claus
parents: 384
diff changeset
   508
literalArrayEncoding
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   509
    "encode myself as an array, from which a copy of the receiver
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   510
     can be reconstructed with #decodeAsLiteralArray.
421
claus
parents: 384
diff changeset
   511
     The encoding is: (Point xValue yValue)"
claus
parents: 384
diff changeset
   512
claus
parents: 384
diff changeset
   513
    ^ Array
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   514
	with:#Point 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   515
	with:x 
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   516
	with:y 
421
claus
parents: 384
diff changeset
   517
claus
parents: 384
diff changeset
   518
claus
parents: 384
diff changeset
   519
    "
claus
parents: 384
diff changeset
   520
     Point new fromLiteralArrayEncoding:#(Point 10 20) 
claus
parents: 384
diff changeset
   521
     (10@20) literalArrayEncoding  
claus
parents: 384
diff changeset
   522
    "
claus
parents: 384
diff changeset
   523
claus
parents: 384
diff changeset
   524
    "Modified: 1.9.1995 / 02:18:29 / claus"
1245
c8afea3d5af0 commentary
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   525
    "Modified: 22.4.1996 / 13:00:32 / cg"
421
claus
parents: 384
diff changeset
   526
!
claus
parents: 384
diff changeset
   527
3488
6e1feb9ead68 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 3238
diff changeset
   528
rectangleRelativeTo:aRectangle preferred:prefRectHolder
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   529
    "compute a displayRectangle, treating the receiver like a
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   530
     layoutorigin. This allows point to be used interchangable with
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   531
     LayoutOrigins."
379
5b5a130ccd09 revision added
claus
parents: 359
diff changeset
   532
3488
6e1feb9ead68 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 3238
diff changeset
   533
    ^ (self asLayout) rectangleRelativeTo:aRectangle preferred:prefRectHolder
379
5b5a130ccd09 revision added
claus
parents: 359
diff changeset
   534
5b5a130ccd09 revision added
claus
parents: 359
diff changeset
   535
    "
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   536
     consider the case, where a view has a preferred extent of 50@50
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   537
     and is to be positioned in its superview which has size 100@100.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   538
     For absolute origin:
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   539
	 (10@20) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) 
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   541
     for relative origin:
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   542
	 (0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) 
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   543
    "
3488
6e1feb9ead68 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 3238
diff changeset
   544
6e1feb9ead68 prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents: 3238
diff changeset
   545
    "Modified: / 27.5.1998 / 10:20:13 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   548
!Point methodsFor:'destructive transformations'!
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   549
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   550
scaleBy:aScale
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   551
    "scale the receiver, by replacing coordinates by the product
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   552
     of the receivers coordinates and the scale (a Point or Number).
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   553
     This is destructive (modifies the receiver, not a copy) and 
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   554
     should only be used if you know, that you are the exclusive owner 
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   555
     of the receiver."
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   556
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   557
    |scalePoint|
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   558
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   559
    (aScale isMemberOf:Point) ifTrue:[  "type hint to stc"  
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   560
	x := x * aScale x.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   561
	y := y * aScale y.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   562
	^ self
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   563
    ].
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   564
    aScale isNumber ifTrue:[
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   565
	x := x * aScale.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   566
	y := y * aScale.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   567
	^ self
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   568
    ].
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   569
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   570
    "this is the general (& clean) code ..."
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   571
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   572
    scalePoint := aScale asPoint.
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   573
    x := x * scalePoint x.
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   574
    y := y * scalePoint y
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   575
!
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   576
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   577
translateBy:anOffset
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   578
    "translate the receiver, by replacing coordinates by the sum
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   579
     of the receivers coordinated and the scale (a Point or Number).
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   580
     This is destructive (modifies the receiver, not a copy) and 
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   581
     should only be used if you know, that you are the exclusive owner 
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   582
     of the receiver."
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   583
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   584
    |offsetPoint|
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   585
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   586
    (anOffset isMemberOf:Point) ifTrue:[ "type hint to stc"   
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   587
	x := x + anOffset x.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   588
	y := y + anOffset y.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   589
	^ self
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   590
    ].
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   591
    anOffset isNumber ifTrue:[
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   592
	x := x + anOffset.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   593
	y := y + anOffset.
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   594
	^ self
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   595
    ].
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   596
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   597
    "this is the general (& clean) code ..."
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   598
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   599
    offsetPoint := anOffset asPoint.
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   600
    x := x + anOffset x.
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   601
    y := y + anOffset y
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   602
! !
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   603
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   604
!Point methodsFor:'interpolating'!
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   605
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   606
interpolateTo: end at: amountDone
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   607
    "Interpolate between the instance and end after the specified amount has been done (0 - 1)."
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   608
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   609
    ^ self + ((end - self) * amountDone).
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   610
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   611
    "
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   612
     (10@10) interpolateTo:(20@20) at:0.5 
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   613
     (10@10) interpolateTo:(20@20) at:0.3 
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   614
     (0@0) interpolateTo:(0@20) at:0.5 
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   615
    "
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   616
! !
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   617
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   618
!Point methodsFor:'misc'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   619
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   620
abs
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   621
    "return a new point with my coordinates taken from the absolute values."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   622
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   623
    ^ (x abs) @ (y abs)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   624
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   625
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   626
ceiling
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   627
    "return a new point with my coordinates truncated towards positive infinity.
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   628
     Return the receiver if its coordinates are already integral."
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   629
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   630
    (x isInteger and:[y isInteger]) ifTrue: [
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   631
        ^ self
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   632
    ].
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   633
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   634
    ^ (x ceiling) @ (y ceiling)
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   635
!
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   636
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   637
floor
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   638
    "return a new point with my coordinates truncated towards negative infinity.
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   639
     Return the receiver if its coordinates are already integral."
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   640
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   641
    (x isInteger and:[y isInteger]) ifTrue: [
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   642
        ^ self
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   643
    ].
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   644
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   645
    ^ (x floor) @ (y floor)
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   646
!
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   647
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   648
quadrant
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   649
    "return the number of the quadrant containing the receiver.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   650
     quadrants are named as follows:
356
claus
parents: 345
diff changeset
   651
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   652
	   ^    2  |  3
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   653
	   Y    ------
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   654
		1  |  0
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   655
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   656
		X >
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   657
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   658
     Q: what is to be returned if any coordinate is 0 ?
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   659
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   660
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   661
    ^ 0@0 quadrantContaining:self
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   662
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   663
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   664
     (0@0) quadrant   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   665
     (1@1) quadrant    
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   666
     (-1@1) quadrant    
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   667
     (-1@-1) quadrant 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   668
     (1@-1) quadrant   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   669
    "
356
claus
parents: 345
diff changeset
   670
!
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   671
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   672
quadrantContaining:aPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   673
    "return the number of the quadrant containing aPoint placing  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   674
     the receiver at the origin, where the quadrants are numbered as  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   675
     follows:
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   676
	   ^    2  |  3
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   677
	   Y    ------
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   678
		1  |  0
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   679
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   680
		X >
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   681
     This can be used for polygon operations (see Foley for examples).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   682
    "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   683
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   684
     aPoint x > x ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   685
	 aPoint y >= y ifTrue:[^ 3].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   686
	 ^ 0
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   687
     ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   688
     aPoint y >= y ifTrue: [^ 2].     
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   689
     ^ 1
356
claus
parents: 345
diff changeset
   690
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   691
     "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   692
      (10 @ 10) quadrantContaining:(15 @ 15)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   693
      (10 @ 10) quadrantContaining:(5 @ 5)    
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   694
      (10 @ 10) quadrantContaining:(5 @ 15)   
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   695
      (10 @ 10) quadrantContaining:(15 @ 5)  
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   696
     "
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   697
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   698
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   699
roundTo:aNumber
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   700
    "return a new point with my coordinates rounded towards the next
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   701
     multiple of aNumber."
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   702
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   703
    ^ (self / aNumber) rounded * aNumber
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   704
!
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   705
3636
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   706
rounded
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   707
    "return a new point with my coordinates rounded to the next integer.
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   708
     Return the receiver if its coordinates are already integral."
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   709
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   710
    (x isInteger and:[y isInteger]) ifTrue: [
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   711
        ^ self
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   712
    ].
3636
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   713
    ^ (x rounded) @ (y rounded)
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   714
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   715
    "
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   716
     (1.5 @ 2.6) rounded
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   717
     (1 @ 2) rounded
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   718
    "
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   719
!
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   720
3562
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   721
truncateTo:aNumber
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   722
    "return a new point with my coordinates truncated towards zero to the next
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   723
     multiple of aNumber."
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   724
813c3f1e99d7 more point truncation-type messages.
Claus Gittinger <cg@exept.de>
parents: 3488
diff changeset
   725
    ^ (self quo:aNumber) rounded * aNumber
3636
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   726
!
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   727
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   728
truncated
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   729
    "return a new point with my coordinates truncated as integer.
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   730
     Return the receiver if its coordinates are already integral."
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   731
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   732
    (x isInteger and:[y isInteger]) ifTrue: [
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   733
        ^ self
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   734
    ].
3636
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   735
cba3cd259b32 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3562
diff changeset
   736
    ^ (x truncated) @ (y truncated)
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   737
! !
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   738
356
claus
parents: 345
diff changeset
   739
!Point methodsFor:'point functions'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   740
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   741
crossProduct: aPoint 
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   742
    "Return a number that is the cross product of the receiver and the 
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   743
     argument, aPoint."
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   744
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   745
    ^ (x * aPoint y) - (y * aPoint x)
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   746
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   747
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   748
!
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   749
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   750
dist:aPoint 
a27a279701f8 Initial revision
claus
parents:
diff changeset
   751
    "return the distance between aPoint and the receiver."
a27a279701f8 Initial revision
claus
parents:
diff changeset
   752
a27a279701f8 Initial revision
claus
parents:
diff changeset
   753
    ^ (aPoint - self) r
a27a279701f8 Initial revision
claus
parents:
diff changeset
   754
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   755
a27a279701f8 Initial revision
claus
parents:
diff changeset
   756
dotProduct:aPoint 
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
   757
    "return a number that is the dot product of the receiver and
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   758
     the argument, aPoint.  That is, the two points are
57
db9677479d35 *** empty log message ***
claus
parents: 44
diff changeset
   759
     multiplied and the coordinates of the result summed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   760
a27a279701f8 Initial revision
claus
parents:
diff changeset
   761
    |temp|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   762
a27a279701f8 Initial revision
claus
parents:
diff changeset
   763
    temp := self * aPoint.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   764
    ^ temp x abs + temp y abs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   765
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   766
a27a279701f8 Initial revision
claus
parents:
diff changeset
   767
grid:gridPoint
a27a279701f8 Initial revision
claus
parents:
diff changeset
   768
    "return a new point with coordinates grided (i.e. rounded to the
a27a279701f8 Initial revision
claus
parents:
diff changeset
   769
     nearest point on the grid)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   770
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
    |newX newY gridX gridY|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   772
a27a279701f8 Initial revision
claus
parents:
diff changeset
   773
    gridX := gridPoint x.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   774
    (gridX <= 1) ifTrue:[
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   775
	newX := x asInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   776
    ] ifFalse:[
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   777
	newX := ((x + (gridX // 2)) // gridX) * gridX
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   778
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   779
    gridY := gridPoint y.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   780
    (gridY <= 1) ifTrue:[
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   781
	newY := y asInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   782
    ] ifFalse:[
180
c488255bd0be *** empty log message ***
claus
parents: 93
diff changeset
   783
	newY := ((y + (gridY // 2)) // gridY) * gridY
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   784
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   785
    ^ newX @ newY
77
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   786
!
6c38ca59927f *** empty log message ***
claus
parents: 57
diff changeset
   787
276
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   788
nearestIntegerPointOnLineFrom: point1 to: point2 
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   789
    "return the closest integer point to the receiver on the line 
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   790
     determined by (point1, point2)--much faster than the more 
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   791
     accurate version if the receiver and arguments are integer points.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   792
     This method was found in the Manchester goody library."
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   793
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   794
    | dX dY newX newY dX2 dY2 intersect scale coeff |
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   795
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   796
    dX := point2 x - point1 x.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   797
    dY := point2 y - point1 y.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   798
    (dX = 0)ifTrue: [
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   799
	(dY = 0) ifTrue: [
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   800
	    intersect := point1
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   801
	] ifFalse: [
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   802
	    newX := point1 x.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   803
	    scale := (y - point1 y) / dY.
359
claus
parents: 356
diff changeset
   804
	    scale > 1 ifTrue:[
claus
parents: 356
diff changeset
   805
		newY := point2 y
claus
parents: 356
diff changeset
   806
	    ] ifFalse: [
claus
parents: 356
diff changeset
   807
		scale < 0 ifTrue: [
claus
parents: 356
diff changeset
   808
		    newY := point1 y
claus
parents: 356
diff changeset
   809
		] ifFalse: [
claus
parents: 356
diff changeset
   810
		    newY := y
claus
parents: 356
diff changeset
   811
		]
claus
parents: 356
diff changeset
   812
	    ].
276
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   813
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   814
	    ^ (newX @ newY) rounded
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   815
	]
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   816
    ] ifFalse: [
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   817
	(dY = 0) ifTrue: [
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   818
	    intersect := x @ point1 y
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   819
	] ifFalse:[
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   820
	    dX2 := dX * dX.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   821
	    dY2 := dY * dY.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   822
	    coeff := ((dX * (y - point1 y)) - 
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   823
		     ((x - point1 x) * dY)) / (dX2 + dY2).
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   824
	    newX := x + (dY * coeff).
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   825
	    newY := y - (dX * coeff).
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   826
	    intersect := newX @ newY
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   827
	]
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   828
    ].
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   829
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   830
    scale := (intersect x - point1 x) / dX.
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   831
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   832
    ^ (scale > 1 ifTrue: [point2] ifFalse: [
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   833
      scale < 0 ifTrue: [point1] ifFalse: [intersect]]) rounded
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   834
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   835
    "
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   836
     120@40 nearestIntegerPointOnLineFrom: 30@120 to: 100@120 
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   837
     0@0 nearestIntegerPointOnLineFrom: 10@10 to: 100@100 
3b6d97620494 *** empty log message ***
claus
parents: 217
diff changeset
   838
    "
5361
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   839
!
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   840
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   841
normalized
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   842
    "interpreting myself as the endPoint of a 0@0 based vector,
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   843
     return the endPoint of the corresponding normalized vector.
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   844
     (that is the endPoint of a vector with the same direction but length 1)"
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   845
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   846
    ^ self / self r
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   847
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   848
    "
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   849
     (10 @ 10) normalized   
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   850
     (1 @ 1) normalized  
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   851
     (10 @ 0) normalized    
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   852
     (0 @ 10) normalized    
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   853
     (-10 @ 0) normalized    
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   854
     (0 @ -10) normalized    
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   855
     (0 @ 0) normalized    
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   856
    "
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   857
!
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   858
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   859
transposed
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   860
    "return a new point with x and y coordinates exchanged"
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   861
dbf17a65f6bd more point functions; better #rounded, #truncated, #floor and #ceiling
Claus Gittinger <cg@exept.de>
parents: 5322
diff changeset
   862
    ^ y@x
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   863
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   864
356
claus
parents: 345
diff changeset
   865
!Point methodsFor:'polar coordinates'!
claus
parents: 345
diff changeset
   866
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   867
angle 
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   868
    "return the receiver's angle (in degrees) in a polar coordinate system.
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   869
     (i.e. the angle of a vector from 0@0 to the receiver).
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   870
    OBSOLETE ST/X interface; use theta for ST-80 compatibility."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   871
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   872
    ^ self theta radiansToDegrees
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   873
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   874
    "
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   875
     (1@1) angle    
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   876
     (2@1) angle   
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   877
    "
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   878
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   879
    "Modified: 2.4.1997 / 00:02:17 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   880
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   881
4891
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   882
degrees
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   883
    "return the receiver's angle (in degrees) in a polar coordinate system.
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   884
     (i.e. the angle of a vector from 0@0 to the receiver).
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   885
    Added for Squeak compatibility."
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   886
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   887
    ^ self theta radiansToDegrees
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   888
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   889
    "
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   890
     (1@1) degrees    
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   891
     (2@1) degrees   
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   892
    "
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   893
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   894
!
56cd253f920b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4865
diff changeset
   895
356
claus
parents: 345
diff changeset
   896
r
claus
parents: 345
diff changeset
   897
    "return the receiver's radius in a polar coordinate system.
claus
parents: 345
diff changeset
   898
     (i.e. the length of a vector from 0@0 to the receiver)"
claus
parents: 345
diff changeset
   899
2578
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   900
    ^ ((x*x) + (y*y)) sqrt
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   901
356
claus
parents: 345
diff changeset
   902
    "
2578
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   903
     (1@1) r 
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   904
     (2@1) r  
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   905
     (2@0) r 
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   906
     (0@2) r 
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   907
     (-2@-2) r 
9fa5d20c0bf0 inline #dotProduct into #r
Claus Gittinger <cg@exept.de>
parents: 2517
diff changeset
   908
     (2@2) r  
356
claus
parents: 345
diff changeset
   909
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   910
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   911
356
claus
parents: 345
diff changeset
   912
theta 
claus
parents: 345
diff changeset
   913
    "return the receiver's angle (in radians) in a polar coordinate system.
claus
parents: 345
diff changeset
   914
     (i.e. the angle of a vector from 0@0 to the receiver)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   915
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   916
    |theta t|
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   917
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   918
    x = 0 ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   919
	y >= 0 ifTrue:[
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   920
	    ^ Float pi * 0.5
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   921
	].
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   922
	^ Float pi * 1.5.
356
claus
parents: 345
diff changeset
   923
    ].
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   924
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   925
    t := y asFloat / x asFloat.
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   926
    theta := t arcTan.
356
claus
parents: 345
diff changeset
   927
    x < 0 ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   928
	^ theta +Float pi
356
claus
parents: 345
diff changeset
   929
    ].
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   930
    theta < 0 ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   931
	^ theta + (Float pi * 2.0)
356
claus
parents: 345
diff changeset
   932
    ].
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   933
    ^ theta.
356
claus
parents: 345
diff changeset
   934
    "
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   935
     (1@1) theta    
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   936
     (2@1) theta   
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   937
     (-2@1) theta   
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   938
     (-2@-1) theta   
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   939
     (0@-1) theta   
356
claus
parents: 345
diff changeset
   940
    "
2517
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   941
e8d65844587e fixed radians/degrees confusion in r:angle: / r:theta
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
   942
    "Modified: 2.4.1997 / 00:15:12 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   943
! !
356
claus
parents: 345
diff changeset
   944
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   945
!Point methodsFor:'printing & storing'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   946
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   947
printOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   948
    "append a printed representation of the receiver to aStream"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   949
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   950
    x printOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   951
    aStream nextPut:$@.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   952
    y printOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   953
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   954
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   955
storeOn:aStream
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   956
    "append my storeString to aStream"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   957
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   958
    aStream nextPut:$(.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   959
    x storeOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   960
    aStream nextPut:$@.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   961
    y storeOn:aStream.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   962
    aStream nextPut:$)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   963
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   964
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   965
!Point methodsFor:'queries'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   966
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   967
isPoint
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   968
    "return true, if the receiver is some kind of point"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   969
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   970
    ^ true
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   971
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   972
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   973
!Point methodsFor:'transformations'!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   974
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   975
* scale 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   976
    "Return a new Point that is the product of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   977
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   978
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   979
    |scalePoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   980
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   981
    "speedup for common cases ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   982
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   983
    (scale isMemberOf:Point) ifTrue:[    
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   984
	^ Point x:(x * scale x) y:(y * scale y)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   985
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   986
    (scale isMemberOf:SmallInteger) ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   987
	^ Point x:(x * scale) y:(y * scale)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   988
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   989
    scale isNumber ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
   990
	^ Point x:(x * scale) y:(y * scale)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   991
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   992
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   993
    "this is the general (& clean) code ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   994
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   995
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   996
    ^ (x * scalePoint x) @ (y * scalePoint y)
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   997
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   998
    "Modified: 25.1.1997 / 17:28:11 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   999
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1000
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1001
+ scale 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1002
    "Return a new Point that is the sum of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1003
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1004
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1005
    |scalePoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1006
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1007
    "speedup for common cases ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1008
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1009
    (scale isMemberOf:Point) ifTrue:[     
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1010
	^ Point x:(x + scale x) y:(y + scale y)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1011
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1012
    (scale isMemberOf:SmallInteger) ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1013
	"/ same as below, but stc can do better here
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1014
	^ Point x:(x + scale) y:(y + scale)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1015
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1016
    scale isNumber ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1017
	^ Point x:(x + scale) y:(y + scale)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1018
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1019
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1020
    "this is the general (& clean) code ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1021
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1022
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1023
    ^ (x + scalePoint x) @ (y + scalePoint y)
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1024
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1025
    "Modified: 25.1.1997 / 17:27:46 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1026
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1027
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1028
- scale 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1029
    "Return a new Point that is the difference of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1030
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1031
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1032
    |scalePoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1033
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1034
    "speedup for common cases ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1035
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1036
    (scale isMemberOf:Point) ifTrue:[     
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1037
	^ Point x:(x - scale x) y:(y - scale y)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1038
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1039
    (scale isMemberOf:SmallInteger) ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1040
	"/ same as below, but stc can do better here
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1041
	^ Point x:(x - scale) y:(y - scale)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1042
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1043
    scale isNumber ifTrue:[
5322
411b6c0f7250 renamed sone structures;
Claus Gittinger <cg@exept.de>
parents: 5006
diff changeset
  1044
	^ Point x:(x - scale) y:(y - scale)
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1045
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1046
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1047
    "this is the general (& clean) code ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1048
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1049
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1050
    ^ (x - scalePoint x) @ (y - scalePoint y)
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1051
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1052
    "Modified: 25.1.1997 / 17:27:40 / cg"
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1053
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1054
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1055
/ scale 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1056
    "Return a new Point that is the integer quotient of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1057
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1058
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1059
    |scalePoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1060
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1061
    "speedup for common cases ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1062
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1063
    (scale isMemberOf:Point) ifTrue:[    
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1064
	^ (x / scale x) @ (y / scale y)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1065
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1066
    scale isNumber ifTrue:[
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1067
	^ (x / scale) @ (y / scale)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1068
    ].
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1069
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1070
    "this is the general (& clean) code ..."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1071
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1072
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1073
    ^ (x / scalePoint x) @ (y / scalePoint y)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1074
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1075
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1076
// scale 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1077
    "Return a new Point that is the quotient of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1078
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1079
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1080
    |scalePoint|
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1081
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1082
    scalePoint := scale asPoint.
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1083
    ^ (x // scalePoint x) @ (y // scalePoint y)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1084
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1085
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1086
negated
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1087
    "return a new point with my coordinates negated 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1088
     i.e. the receiver mirrored at the origin"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1089
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1090
    ^ (x negated) @ (y negated)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1091
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1092
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1093
reciprocal
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1094
    "return a new point where the coordinates are
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1095
     the reciproce of mine"
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1096
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1097
    ^ (1 / x) @ (1 / y)
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1098
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1099
4893
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1100
rotateBy:angle about:center
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1101
    "Return a new point, generated by rotating the receiver
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1102
     counterClockWise by some angle in radians around the given center point.
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1103
     Even though Point.theta is measured CW, 
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1104
     this rotates with the more conventional CCW interpretateion of angle."
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1105
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1106
    |p r theta|
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1107
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1108
    p := self - center.
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1109
    r := p r.
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1110
    theta := angle asFloat - p theta.
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1111
    ^ (center x asFloat + (r * theta cos)) @
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1112
      (center y asFloat - (r * theta sin))
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1113
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1114
    "
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1115
     (10@10) rotateBy:Float pi about:0@0  
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1116
     (10@0) rotateBy:Float pi about:0@0  
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1117
    "
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1118
!
a645a54ced2a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4891
diff changeset
  1119
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1120
scaledBy:aScale
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1121
    "return a new Point that is the product of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1122
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1123
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1124
    ^ self * aScale
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1125
!
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1126
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1127
translatedBy:anOffset
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1128
    "return a new Point that is the sum of the 
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1129
     receiver and scale (which is a Point or Number)."
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1130
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1131
    ^ self + anOffset
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1132
! !
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1133
2273
96cc7384fe80 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
  1134
!Point class methodsFor:'documentation'!
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1135
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1136
version
5567
2cc43ea7394f *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 5361
diff changeset
  1137
    ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.56 2000-08-30 12:35:40 stefan Exp $'
637
f71df465819c version at the end
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1138
! !
356
claus
parents: 345
diff changeset
  1139
Point initialize!