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