Polygon.st
author Claus Gittinger <cg@exept.de>
Thu, 09 Jun 2016 18:09:58 +0200
changeset 3934 3fc6968232c1
parent 2317 a56b5469246d
child 4080 8b66d15c3473
permissions -rw-r--r--
class: exept_expecco_plugin class definition
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
2317
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   149
add:aPoint
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   150
    vertices isNil ifTrue:[
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   151
        vertices := OrderedCollection new
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   152
    ].
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   153
    vertices add:aPoint
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   154
!
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   155
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   156
vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   157
    "return the array containing my points"
78
claus
parents: 68
diff changeset
   158
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   159
    ^ vertices
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   160
!
78
claus
parents: 68
diff changeset
   161
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   162
vertices:anArrayOfPoints
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   163
    "set the array containing my points"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   164
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   165
    vertices := anArrayOfPoints
78
claus
parents: 68
diff changeset
   166
! !
claus
parents: 68
diff changeset
   167
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   168
!Polygon methodsFor:'converting'!
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   169
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   170
asPointArray
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   171
    "return an array containing my vertex points.
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   172
     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
   173
     modify the returned collections points (unless you want to affect
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   174
     the polygon ...)."
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   175
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   176
    ^ vertices
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   177
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   178
    "Modified: 8.5.1996 / 20:43:39 / cg"
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   179
! !
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   180
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   181
!Polygon methodsFor:'displaying'!
78
claus
parents: 68
diff changeset
   182
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   183
displayFilledOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   184
    "display a filled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   185
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   186
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   187
    aGC fillPolygon:vertices 
78
claus
parents: 68
diff changeset
   188
claus
parents: 68
diff changeset
   189
    "
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   190
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   191
     v := View new openAndWait.
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   192
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   193
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   194
          Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   195
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   196
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   197
            with:35@60)) displayFilledOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   198
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   199
     |v|
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   200
     v := View new openAndWait.
78
claus
parents: 68
diff changeset
   201
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   202
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   203
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   204
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   205
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   206
            with:35@60
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   207
            with:10@10)) displayStrokedOn:v
78
claus
parents: 68
diff changeset
   208
    "
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   209
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   210
    "Modified: 8.5.1996 / 14:41:47 / cg"
78
claus
parents: 68
diff changeset
   211
!
claus
parents: 68
diff changeset
   212
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   213
displayStrokedOn:aGC
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   214
    "display an unfilled polygin as represented by the receiver in 
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   215
     the graphicsContext, aGC"
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   216
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   217
    aGC displayPolygon:vertices 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   218
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   219
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   220
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   221
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   222
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   223
     [v shown] whileFalse:[Processor yield].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   224
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   225
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   226
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   227
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   228
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   229
            with:35@60)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   230
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   231
     |v|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   232
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   233
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   234
     [v shown] whileFalse:[Processor yield].
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
     (Polygon vertices:(
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   237
        Array
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   238
            with:10@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   239
            with:60@10
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   240
            with:35@60
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   241
            with:10@10)) displayStrokedOn:v
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   242
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   243
267
1941121ff1c3 examples
Claus Gittinger <cg@exept.de>
parents: 255
diff changeset
   244
    "Modified: 27.4.1996 / 14:52:29 / cg"
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   245
! !
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   246
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   247
!Polygon methodsFor:'enumerating'!
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   248
78
claus
parents: 68
diff changeset
   249
edgesDo:aTwoArgBlock
claus
parents: 68
diff changeset
   250
    "evaluate aTwoArgBlock for each pair of vertices"
claus
parents: 68
diff changeset
   251
claus
parents: 68
diff changeset
   252
    1 to:vertices size-1 do:[:i |
claus
parents: 68
diff changeset
   253
	aTwoArgBlock value:(vertices at:i) value:(vertices at:i+1)
claus
parents: 68
diff changeset
   254
    ].
claus
parents: 68
diff changeset
   255
claus
parents: 68
diff changeset
   256
    "
claus
parents: 68
diff changeset
   257
     |v p|
claus
parents: 68
diff changeset
   258
claus
parents: 68
diff changeset
   259
     v := View new open.
claus
parents: 68
diff changeset
   260
     [v shown] whileFalse:[Processor yield].
claus
parents: 68
diff changeset
   261
claus
parents: 68
diff changeset
   262
     p := Polygon vertices:(Array with:5@5 
claus
parents: 68
diff changeset
   263
				  with:50@5 
claus
parents: 68
diff changeset
   264
				  with:30@30
claus
parents: 68
diff changeset
   265
				  with:5@5).
claus
parents: 68
diff changeset
   266
claus
parents: 68
diff changeset
   267
     p displayOn:v.
claus
parents: 68
diff changeset
   268
     (Delay forSeconds:3) wait.
claus
parents: 68
diff changeset
   269
claus
parents: 68
diff changeset
   270
     p edgesDo:[:p1 :p2 | v lineWidth:3. v displayLineFrom:p1 to:p2] 
claus
parents: 68
diff changeset
   271
    "
claus
parents: 68
diff changeset
   272
!
claus
parents: 68
diff changeset
   273
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   274
verticesDo:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   275
    "evaluate aBlock for each point"
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   276
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   277
    vertices do:aBlock
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   278
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   279
    "
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   280
     |v p|
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   281
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   282
     v := View new open.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   283
     [v shown] whileFalse:[Processor yield].
78
claus
parents: 68
diff changeset
   284
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   285
     p := Polygon vertices:(Array with:5@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   286
				  with:50@5 
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   287
				  with:30@30
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   288
				  with:5@5).
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   289
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   290
     p displayOn:v.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   291
     (Delay forSeconds:3) wait.
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   292
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   293
     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
   294
    "
78
claus
parents: 68
diff changeset
   295
! !
claus
parents: 68
diff changeset
   296
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   297
!Polygon methodsFor:'queries'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   298
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   299
bottom
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   300
    "return the bottom boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   301
     that is the maximum y coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   302
78
claus
parents: 68
diff changeset
   303
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   304
    ^ vertices inject:(vertices at:1) y into:[:maxSoFar :p | maxSoFar max:(p y)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   305
78
claus
parents: 68
diff changeset
   306
    "
claus
parents: 68
diff changeset
   307
     (Polygon vertices:(
claus
parents: 68
diff changeset
   308
	Array
claus
parents: 68
diff changeset
   309
	    with:10@10
claus
parents: 68
diff changeset
   310
	    with:60@10
claus
parents: 68
diff changeset
   311
	    with:35@60)) bottom 
claus
parents: 68
diff changeset
   312
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   313
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   314
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   315
computeBounds
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   316
    "return the smallest enclosing rectangle"
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   317
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   318
    |minX maxX minY maxY t n "{ Class: SmallInteger }" |
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
    n := vertices size.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   321
    n == 0 ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   322
        ^ nil    "/ mhmh - should we return an empty rectangle here ?
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   323
    ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   324
    t := vertices at:1.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   325
    minX := maxX := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   326
    minY := maxY := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   327
    2 to:n do:[:i |
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   328
        |x y t|
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   329
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   330
        t := vertices at:i.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   331
        x := t x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   332
        y := t y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   333
        x < minX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   334
            minX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   335
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   336
            x > maxX ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   337
                maxX := x.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   338
            ]
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   339
        ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   340
        y < minY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   341
            minY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   342
        ] ifFalse:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   343
            y > maxY ifTrue:[
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   344
                maxY := y.
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   345
            ]
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   346
        ].
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   347
    ].
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   348
    ^ Rectangle left:minX top:minY right:maxX bottom:maxY.
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   349
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   350
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   351
     |p|
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 := (Polygon vertices:(
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   354
            Array
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   355
                with:10@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   356
                with:60@10
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   357
                with:35@60)).
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   358
     p bounds 
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   359
    "
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   360
283
59a8cfbc1e5e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 281
diff changeset
   361
    "Modified: 8.5.1996 / 20:51:42 / cg"
490
ef43c7a69346 added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   362
    "Created: 12.2.1997 / 11:44:11 / cg"
276
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   363
!
e104a0359515 comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents: 267
diff changeset
   364
2091
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   365
containsPoint:aPoint
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   366
    "return true, if the argument, aPoint is contained in the receiver"
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   367
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   368
    |angle pPrev p1 p2 angle2D|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   369
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   370
    angle2D := [:p1 :p2 |
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   371
        "/   Return the angle between two vectors on a plane
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   372
        "/   The angle is from vector 1 to vector 2, positive anticlockwise
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   373
        "/   The result is between -pi -> pi
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   374
        |theta theta1 theta2|
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   375
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   376
        theta1 := p1 x arcTan2:p1 y.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   377
        theta2 := p2 x arcTan2:p2 y.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   378
        theta := theta2 - theta1.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   379
        [theta > Float pi] whileTrue:[
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   380
            theta := theta - (Float pi * 2)
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   381
        ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   382
        [ theta < (Float pi negated) ] whileTrue:[
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   383
            theta := theta + (Float pi * 2)
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   384
        ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   385
        theta
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   386
    ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   387
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   388
    angle := 0.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   389
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   390
    pPrev := vertices last.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   391
    vertices do:[:pI |
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   392
        p1 := pPrev - aPoint.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   393
        p2 := pI - aPoint.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   394
        angle := angle + (angle2D value:p1 value:p2).
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   395
        pPrev := pI.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   396
    ].
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   397
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   398
    ^ angle abs >= Float pi
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   399
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   400
    "
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   401
     |p|
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 := Polygon vertices:(Array 
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   404
                             with:10@10
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   405
                             with:30@10
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   406
                             with:20@20).
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   407
     TestCase assert:(p containsPoint:14@11).     
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   408
     TestCase assert:(p containsPoint:15@15).     
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   409
     TestCase assert:(p containsPoint:5@15) not.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   410
     TestCase assert:(p containsPoint:15@5) not.
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   411
     TestCase assert:(p containsPoint:30@15) not. 
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   412
     TestCase assert:(p containsPoint:20@15).       
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   413
    "
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   414
!
24965fa2be83 +containsPoint:
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
   415
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   416
left
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   417
    "return the left boundary of the polygon,
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   418
     that is the minimum x coordinate of all its points"
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   419
78
claus
parents: 68
diff changeset
   420
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   421
    ^ vertices inject:(vertices at:1) x into:[:minSoFar :p | minSoFar min:(p x)]
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   422
78
claus
parents: 68
diff changeset
   423
    "
claus
parents: 68
diff changeset
   424
     (Polygon vertices:(
claus
parents: 68
diff changeset
   425
	Array
claus
parents: 68
diff changeset
   426
	    with:10@10
claus
parents: 68
diff changeset
   427
	    with:60@10
claus
parents: 68
diff changeset
   428
	    with:35@60)) left  
claus
parents: 68
diff changeset
   429
    "
claus
parents: 68
diff changeset
   430
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   431
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   432
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   433
right
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   434
    "return the right boundary of the polygon,
88
claus
parents: 85
diff changeset
   435
     that is the maximum x coordinate of all its points"
14
ca0b5fbc8131 *** empty log message ***
claus
parents: 4
diff changeset
   436
78
claus
parents: 68
diff changeset
   437
    (vertices size == 0) ifTrue: [^ nil].
claus
parents: 68
diff changeset
   438
    ^ vertices inject:(vertices at:1) x into:[:maxSoFar :p | maxSoFar max:(p x)]
claus
parents: 68
diff changeset
   439
claus
parents: 68
diff changeset
   440
    "
claus
parents: 68
diff changeset
   441
     (Polygon vertices:(
claus
parents: 68
diff changeset
   442
	Array
claus
parents: 68
diff changeset
   443
	    with:10@10
claus
parents: 68
diff changeset
   444
	    with:60@10
claus
parents: 68
diff changeset
   445
	    with:35@60)) right  
claus
parents: 68
diff changeset
   446
    "
claus
parents: 68
diff changeset
   447
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   448
!
78
claus
parents: 68
diff changeset
   449
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   450
top
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   451
    "return the top boundary of the polygon,
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   452
     that is the minimum y coordinate of all its points"
78
claus
parents: 68
diff changeset
   453
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   454
    (vertices size == 0) ifTrue: [^ nil].
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   455
    ^ vertices inject:(vertices at:1) y into:[:minSoFar :p | minSoFar min:(p y)]
78
claus
parents: 68
diff changeset
   456
claus
parents: 68
diff changeset
   457
    "
claus
parents: 68
diff changeset
   458
     (Polygon vertices:(
claus
parents: 68
diff changeset
   459
	Array
claus
parents: 68
diff changeset
   460
	    with:10@10
claus
parents: 68
diff changeset
   461
	    with:60@10
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   462
	    with:35@60)) top  
78
claus
parents: 68
diff changeset
   463
    "
claus
parents: 68
diff changeset
   464
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   465
! !
78
claus
parents: 68
diff changeset
   466
2158
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   467
!Polygon methodsFor:'testing'!
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   468
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   469
canBeFilled
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   470
    "return true, if the receiver can be drawn as a filled geometric.
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   471
     Always true here."
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   472
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   473
    ^ true
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   474
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   475
    "Created: 8.5.1996 / 08:16:53 / cg"
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   476
! !
cc8120b2afc9 category changes
Claus Gittinger <cg@exept.de>
parents: 2091
diff changeset
   477
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   478
!Polygon class methodsFor:'documentation'!
78
claus
parents: 68
diff changeset
   479
135
64428d5e8d06 version at the end
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   480
version
2317
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   481
    ^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.29 2009-10-26 21:15:19 cg Exp $'
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   482
!
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   483
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   484
version_CVS
a56b5469246d added: #add:
Claus Gittinger <cg@exept.de>
parents: 2158
diff changeset
   485
    ^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.29 2009-10-26 21:15:19 cg Exp $'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   486
! !