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