Polygon.st
author Claus Gittinger <cg@exept.de>
Thu, 22 Jan 2009 00:22:24 +0100
changeset 2091 24965fa2be83
parent 1430 baf6bfed6d56
child 2158 cc8120b2afc9
permissions -rw-r--r--
+containsPoint:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     1
"
4
1f66800df351 *** empty log message ***
claus
parents: 2
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
68
6650e0d50a1a *** empty log message ***
claus
parents: 36
diff changeset
     3
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     4
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1cf8d1747859 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    11
"
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    13
78
claus
parents: 68
diff changeset
    14
Geometric subclass:#Polygon
252
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    15
	instanceVariableNames:'vertices'
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    16
	classVariableNames:''
d52b05d6637a commentary
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    17
	poolDictionaries:''
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 490
diff changeset
    18
	category:'Graphics-Geometry-Objects'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    19
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    20
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    21
!Polygon class methodsFor:'documentation'!
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    22
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    23
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    24
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    25
 COPYRIGHT (c) 1988 by Claus Gittinger
68
6650e0d50a1a *** empty log message ***
claus
parents: 36
diff changeset
    26
	      All Rights Reserved
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    27
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    28
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    29
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    31
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    32
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    33
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    34
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    35
!
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    36
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    37
documentation
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    38
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    39
    Polygon - an array of points
78
claus
parents: 68
diff changeset
    40
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    41
    Adds simple boundary checking methods to Array.
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
    42
    (needs much more - such as inside check, area computation etc.)
255
69a34808bf99 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    43
69a34808bf99 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    44
    [author:]
69a34808bf99 documentation
Claus Gittinger <cg@exept.de>
parents: 252
diff changeset
    45
        Claus Gittinger
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
    46
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
    47
    [see also:]
331
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    48
        Rectangle EllipticalArc Spline Circle Point LineSegment Curve
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    49
        Arrow ArroedSpline
Claus Gittinger <cg@exept.de>
parents: 284
diff changeset
    50
        GraphicsContext StrokingWrapper FillingWrapper
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    51
"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    52
!
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    53
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    54
examples
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    55
"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    56
  simple polygon; filled & unfilled:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    57
                                                                        [exBegin]
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    58
    |v p|
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    59
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    60
    v := (View extent:200@200) openAndWait.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    61
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    62
    p := Polygon vertices:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    63
                (Array with:(10@10)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    64
                       with:(90@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    65
                       with:(10@90)).
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    66
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    67
    v scale:2.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    68
    v paint:Color blue.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    69
    p displayFilledOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    70
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    71
    v paint:Color red.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    72
    p displayStrokedOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    73
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    74
    v scale:1; translation:100@0.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    75
    v paint:Color green.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    76
    p displayFilledOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    77
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    78
    v paint:Color black.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    79
    p displayStrokedOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    80
                                                                        [exEnd]
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    81
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    82
  arbitrary polygon; filled & unfilled:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    83
                                                                        [exBegin]
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    84
    |v p|
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    85
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    86
    v := (View extent:200@200) openAndWait.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    87
    v scale:2.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    88
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    89
    p := Polygon vertices:
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    90
                (Array with:(10@10)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    91
                       with:(90@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    92
                       with:(50@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    93
                       with:(90@10)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    94
                       with:(10@90)
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    95
                                   ).
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    96
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    97
    v paint:Color blue.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    98
    p displayFilledOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
    99
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   100
    v paint:Color red.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   101
    p displayStrokedOn:v.
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   102
                                                                        [exEnd]
31
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
   103
"
e223f3cf2995 *** empty log message ***
claus
parents: 14
diff changeset
   104
! !
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   105
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   106
!Polygon class methodsFor:'instance creation'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   107
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   108
fromRectangle:aRectangle
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   109
    "return a new polygon, taking the rectangles vertices"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   110
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   111
    ^ self new vertices:(aRectangle asPointArray)
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   112
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   113
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   114
     Polygon fromRectangle:(50@50 corner:100@100)
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   115
    "
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   116
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   117
    "Modified: 8.5.1996 / 20:15:18 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   118
!
78
claus
parents: 68
diff changeset
   119
claus
parents: 68
diff changeset
   120
vertices:anArrayOfPoints
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   121
    "return a new polygon, given a collection of vertices"
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   122
78
claus
parents: 68
diff changeset
   123
    ^ self new vertices:anArrayOfPoints
claus
parents: 68
diff changeset
   124
claus
parents: 68
diff changeset
   125
    "
claus
parents: 68
diff changeset
   126
     Polygon vertices:(Array with:10@10
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   127
                             with:20@20
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   128
                             with:30@30)
78
claus
parents: 68
diff changeset
   129
1430
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   130
     Polygon vertices:(#(10 10  100 0  50 50) pairWiseCollect:[:x :y | x @ y]).
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   131
    "
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   132
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   133
    "
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   134
     |p v|
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   135
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   136
     v := View new openAndWait.
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   137
     p := Polygon 
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   138
            vertices:(Array with:10@10
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   139
                            with:20@10
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   140
                            with:20@30).
baf6bfed6d56 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1303
diff changeset
   141
     p displayOn:v
78
claus
parents: 68
diff changeset
   142
    "
280
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   143
Claus Gittinger <cg@exept.de>
parents: 276
diff changeset
   144
    "Modified: 8.5.1996 / 20:11:31 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   145
! !
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   146
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   147
!Polygon methodsFor:'accessing'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   148
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   149
vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   150
    "return the array containing my points"
78
claus
parents: 68
diff changeset
   151
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   152
    ^ vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   153
!
78
claus
parents: 68
diff changeset
   154
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   155
vertices:anArrayOfPoints
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   156
    "set the array containing my points"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   157
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   158
    vertices := anArrayOfPoints
78
claus
parents: 68
diff changeset
   159
! !
claus
parents: 68
diff changeset
   160
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   161
!Polygon methodsFor:'converting'!
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   162
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   163
asPointArray
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   164
    "return an array containing my vertex points.
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   165
     Notice, that no copy of my vertices is created - you should not
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   166
     modify the returned collections points (unless you want to affect
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   167
     the polygon ...)."
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   168
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   169
    ^ vertices
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   170
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   171
    "Modified: 8.5.1996 / 20:43:39 / cg"
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   172
! !
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   173
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   174
!Polygon methodsFor:'displaying'!
78
claus
parents: 68
diff changeset
   175
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   176
displayFilledOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   177
    "display a filled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   178
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   179
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   180
    aGC fillPolygon:vertices 
78
claus
parents: 68
diff changeset
   181
claus
parents: 68
diff changeset
   182
    "
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   183
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   184
     v := View new openAndWait.
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   185
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   186
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   187
          Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   188
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   189
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   190
            with:35@60)) displayFilledOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   191
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   192
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   193
     v := View new openAndWait.
78
claus
parents: 68
diff changeset
   194
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   195
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   196
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   197
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   198
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   199
            with:35@60
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   200
            with:10@10)) displayStrokedOn:v
78
claus
parents: 68
diff changeset
   201
    "
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   202
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   203
    "Modified: 8.5.1996 / 14:41:47 / cg"
78
claus
parents: 68
diff changeset
   204
!
claus
parents: 68
diff changeset
   205
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   206
displayStrokedOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   207
    "display an unfilled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   208
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   209
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   210
    aGC displayPolygon:vertices 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   211
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   212
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   213
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   214
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   215
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   216
     [v shown] whileFalse:[Processor yield].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   217
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   218
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   219
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   220
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   221
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   222
            with:35@60)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   223
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   224
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   225
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   226
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   227
     [v shown] whileFalse:[Processor yield].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   228
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   229
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   230
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   231
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   232
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   233
            with:35@60
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   234
            with:10@10)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   235
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   236
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   237
    "Modified: 27.4.1996 / 14:52:29 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   238
! !
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   239
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   240
!Polygon methodsFor:'enumerating'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   241
78
claus
parents: 68
diff changeset
   242
edgesDo:aTwoArgBlock
claus
parents: 68
diff changeset
   243
    "evaluate aTwoArgBlock for each pair of vertices"
claus
parents: 68
diff changeset
   244
claus
parents: 68
diff changeset
   245
    1 to:vertices size-1 do:[:i |
claus
parents: 68
diff changeset
   246
	aTwoArgBlock value:(vertices at:i) value:(vertices at:i+1)
claus
parents: 68
diff changeset
   247
    ].
claus
parents: 68
diff changeset
   248
claus
parents: 68
diff changeset
   249
    "
claus
parents: 68
diff changeset
   250
     |v p|
claus
parents: 68
diff changeset
   251
claus
parents: 68
diff changeset
   252
     v := View new open.
claus
parents: 68
diff changeset
   253
     [v shown] whileFalse:[Processor yield].
claus
parents: 68
diff changeset
   254
claus
parents: 68
diff changeset
   255
     p := Polygon vertices:(Array with:5@5 
claus
parents: 68
diff changeset
   256
				  with:50@5 
claus
parents: 68
diff changeset
   257
				  with:30@30
claus
parents: 68
diff changeset
   258
				  with:5@5).
claus
parents: 68
diff changeset
   259
claus
parents: 68
diff changeset
   260
     p displayOn:v.
claus
parents: 68
diff changeset
   261
     (Delay forSeconds:3) wait.
claus
parents: 68
diff changeset
   262
claus
parents: 68
diff changeset
   263
     p edgesDo:[:p1 :p2 | v lineWidth:3. v displayLineFrom:p1 to:p2] 
claus
parents: 68
diff changeset
   264
    "
claus
parents: 68
diff changeset
   265
!
claus
parents: 68
diff changeset
   266
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   267
verticesDo:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   268
    "evaluate aBlock for each point"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   269
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   270
    vertices do:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   271
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   272
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   273
     |v p|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   274
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   275
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   276
     [v shown] whileFalse:[Processor yield].
78
claus
parents: 68
diff changeset
   277
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   278
     p := Polygon vertices:(Array with:5@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   279
				  with:50@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   280
				  with:30@30
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   281
				  with:5@5).
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   282
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   283
     p displayOn:v.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   284
     (Delay forSeconds:3) wait.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   285
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   286
     p verticesDo:[:p | v displayRectangleX:p x -3  y:p y -3  width:6 height:6] 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   287
    "
78
claus
parents: 68
diff changeset
   288
! !
claus
parents: 68
diff changeset
   289
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   290
!Polygon methodsFor:'queries'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   291
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   292
bottom
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   293
    "return the bottom boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   294
     that is the maximum y coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   295
78
claus
parents: 68
diff changeset
   296
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   297
    ^ vertices inject:(vertices at:1) y into:[:maxSoFar :p | maxSoFar max:(p y)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   298
78
claus
parents: 68
diff changeset
   299
    "
claus
parents: 68
diff changeset
   300
     (Polygon vertices:(
claus
parents: 68
diff changeset
   301
	Array
claus
parents: 68
diff changeset
   302
	    with:10@10
claus
parents: 68
diff changeset
   303
	    with:60@10
claus
parents: 68
diff changeset
   304
	    with:35@60)) bottom 
claus
parents: 68
diff changeset
   305
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   306
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   307
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   308
canBeFilled
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   309
    "return true, if the receiver can be drawn as a filled geometric.
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   310
     Always true here."
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   311
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   312
    ^ true
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   313
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   314
    "Created: 8.5.1996 / 08:16:53 / cg"
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   315
!
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   316
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   317
computeBounds
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   318
    "return the smallest enclosing rectangle"
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   319
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   320
    |minX maxX minY maxY t n "{ Class: SmallInteger }" |
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   321
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   322
    n := vertices size.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   323
    n == 0 ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   324
        ^ nil    "/ mhmh - should we return an empty rectangle here ?
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   325
    ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   326
    t := vertices at:1.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   327
    minX := maxX := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   328
    minY := maxY := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   329
    2 to:n do:[:i |
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   330
        |x y t|
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   331
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   332
        t := vertices at:i.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   333
        x := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   334
        y := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   335
        x < minX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   336
            minX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   337
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   338
            x > maxX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   339
                maxX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   340
            ]
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   341
        ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   342
        y < minY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   343
            minY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   344
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   345
            y > maxY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   346
                maxY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   347
            ]
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   348
        ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   349
    ].
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   350
    ^ Rectangle left:minX top:minY right:maxX bottom:maxY.
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   351
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   352
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   353
     |p|
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   354
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   355
     p := (Polygon vertices:(
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   356
            Array
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   357
                with:10@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   358
                with:60@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   359
                with:35@60)).
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   360
     p bounds 
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   361
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   362
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   363
    "Modified: 8.5.1996 / 20:51:42 / cg"
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   364
    "Created: 12.2.1997 / 11:44:11 / cg"
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   365
!
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   366
2091
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   367
containsPoint:aPoint
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   368
    "return true, if the argument, aPoint is contained in the receiver"
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   369
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   370
    |angle pPrev p1 p2 angle2D|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   371
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   372
    angle2D := [:p1 :p2 |
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   373
        "/   Return the angle between two vectors on a plane
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   374
        "/   The angle is from vector 1 to vector 2, positive anticlockwise
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   375
        "/   The result is between -pi -> pi
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   376
        |theta theta1 theta2|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   377
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   378
        theta1 := p1 x arcTan2:p1 y.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   379
        theta2 := p2 x arcTan2:p2 y.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   380
        theta := theta2 - theta1.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   381
        [theta > Float pi] whileTrue:[
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   382
            theta := theta - (Float pi * 2)
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   383
        ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   384
        [ theta < (Float pi negated) ] whileTrue:[
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   385
            theta := theta + (Float pi * 2)
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   386
        ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   387
        theta
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   388
    ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   389
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   390
    angle := 0.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   391
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   392
    pPrev := vertices last.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   393
    vertices do:[:pI |
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   394
        p1 := pPrev - aPoint.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   395
        p2 := pI - aPoint.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   396
        angle := angle + (angle2D value:p1 value:p2).
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   397
        pPrev := pI.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   398
    ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   399
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   400
    ^ angle abs >= Float pi
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   401
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   402
    "
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   403
     |p|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   404
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   405
     p := Polygon vertices:(Array 
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   406
                             with:10@10
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   407
                             with:30@10
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   408
                             with:20@20).
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   409
     TestCase assert:(p containsPoint:14@11).     
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   410
     TestCase assert:(p containsPoint:15@15).     
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   411
     TestCase assert:(p containsPoint:5@15) not.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   412
     TestCase assert:(p containsPoint:15@5) not.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   413
     TestCase assert:(p containsPoint:30@15) not. 
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   414
     TestCase assert:(p containsPoint:20@15).       
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   415
    "
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   416
!
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   417
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   418
left
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   419
    "return the left boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   420
     that is the minimum x coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   421
78
claus
parents: 68
diff changeset
   422
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   423
    ^ vertices inject:(vertices at:1) x into:[:minSoFar :p | minSoFar min:(p x)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   424
78
claus
parents: 68
diff changeset
   425
    "
claus
parents: 68
diff changeset
   426
     (Polygon vertices:(
claus
parents: 68
diff changeset
   427
	Array
claus
parents: 68
diff changeset
   428
	    with:10@10
claus
parents: 68
diff changeset
   429
	    with:60@10
claus
parents: 68
diff changeset
   430
	    with:35@60)) left  
claus
parents: 68
diff changeset
   431
    "
claus
parents: 68
diff changeset
   432
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   433
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   434
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   435
right
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   436
    "return the right boundary of the polygon,
88
claus
parents: 85
diff changeset
   437
     that is the maximum x coordinate of all its points"
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   438
78
claus
parents: 68
diff changeset
   439
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   440
    ^ vertices inject:(vertices at:1) x into:[:maxSoFar :p | maxSoFar max:(p x)]
claus
parents: 68
diff changeset
   441
claus
parents: 68
diff changeset
   442
    "
claus
parents: 68
diff changeset
   443
     (Polygon vertices:(
claus
parents: 68
diff changeset
   444
	Array
claus
parents: 68
diff changeset
   445
	    with:10@10
claus
parents: 68
diff changeset
   446
	    with:60@10
claus
parents: 68
diff changeset
   447
	    with:35@60)) right  
claus
parents: 68
diff changeset
   448
    "
claus
parents: 68
diff changeset
   449
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   450
!
78
claus
parents: 68
diff changeset
   451
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   452
top
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   453
    "return the top boundary of the polygon,
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   454
     that is the minimum y coordinate of all its points"
78
claus
parents: 68
diff changeset
   455
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   456
    (vertices size == 0) ifTrue: [^ nil].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   457
    ^ vertices inject:(vertices at:1) y into:[:minSoFar :p | minSoFar min:(p y)]
78
claus
parents: 68
diff changeset
   458
claus
parents: 68
diff changeset
   459
    "
claus
parents: 68
diff changeset
   460
     (Polygon vertices:(
claus
parents: 68
diff changeset
   461
	Array
claus
parents: 68
diff changeset
   462
	    with:10@10
claus
parents: 68
diff changeset
   463
	    with:60@10
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   464
	    with:35@60)) top  
78
claus
parents: 68
diff changeset
   465
    "
claus
parents: 68
diff changeset
   466
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   467
! !
78
claus
parents: 68
diff changeset
   468
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   469
!Polygon class methodsFor:'documentation'!
78
claus
parents: 68
diff changeset
   470
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   471
version
2091
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   472
    ^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.27 2009-01-21 23:22:24 cg Exp $'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   473
! !