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