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