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