Curve.st
author Stefan Vogel <sv@exept.de>
Thu, 08 Nov 2007 15:03:14 +0100
changeset 1908 7d5c6c7d805f
parent 1303 6ca5f36cdc63
child 2156 27b688e0dd31
permissions -rw-r--r--
Methods to get all addresses for a given hostname (multihomed hosts)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
    13
"{ Package: 'stx:libbasic2' }"
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
    14
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
Geometric subclass:#Curve
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	instanceVariableNames:'startPoint middlePoint endPoint'
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:''
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
    19
	category:'Graphics-Geometry-Objects'
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!Curve class methodsFor:'documentation'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
copyright
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
 COPYRIGHT (c) 1996 by Claus Gittinger
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
              All Rights Reserved
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 This software is furnished under a license and may be used
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 hereby transferred.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    A Curve is a conic section determined by three points
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    that interpolates the first and the third and is tangent to the angle formed
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    by the three points at the first and third points.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    [author:]
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
        Claus Gittinger
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    [see also:]
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        Rectangle Polygon EllipticalArc Circle Spline Point LineSegment
331
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
    49
        ArrowedSpline Arrow
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        GraphicsContext
331
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
    51
        StrokingWrapper FillingWrapper
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
examples
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
  filled & unfilled:
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
                                                                        [exBegin]
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    |v c|
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    v := (View extent:100@100) openAndWait.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    c := Curve start:(20@20) middle:(80@80) end:(20@80).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    v paint:Color blue.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    c displayFilledOn:v.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    v paint:Color red.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    c displayStrokedOn:v.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
                                                                        [exEnd]
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
  with a grid (for demonstration):
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
                                                                        [exBegin]
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    |v c|
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    v := (View extent:200@100) openAndWait.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    v lineStyle:#dashed.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    v displayLineFrom:(20@0) to:(20@200).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    v displayLineFrom:(180@0) to:(180@200).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    v displayLineFrom:(0@20) to:(200@20).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    v displayLineFrom:(0@80) to:(200@80).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    v lineStyle:#solid.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    c := Curve start:(20@20) middle:(180@80) end:(20@80).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    v paint:Color blue.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    c displayFilledOn:v.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    v paint:Color red.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    c displayStrokedOn:v.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    v paint:(Color black).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    v displayLineFrom:(20@20) to:(180@80).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    v displayLineFrom:(20@80) to:(180@80).
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
                                                                        [exEnd]
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
! !
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
!Curve class methodsFor:'instance creation'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
from:startPoint to:endPoint through:middlePoint
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
    "return a new curve, passing through the three given points"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    ^ self new start:startPoint middle:middlePoint end:endPoint
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "Created: 8.5.1996 / 21:16:39 / cg"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
start:startPoint middle:middlePoint end:endPoint
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "return a new curve, passing through the three given points"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    ^ self new start:startPoint middle:middlePoint end:endPoint
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "Created: 8.5.1996 / 21:19:30 / cg"
346
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   118
!
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   119
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   120
with:startPoint with:middlePoint with:endPoint
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   121
    "return a new curve, passing through the three given points"
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   122
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   123
    ^ self new start:startPoint middle:middlePoint end:endPoint
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   124
d263792e62f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 331
diff changeset
   125
    "Created: 17.5.1996 / 10:22:47 / cg"
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
! !
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
!Curve methodsFor:'accessing'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
end
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    "return the endPoint"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    ^ endPoint
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    "Created: 8.5.1996 / 21:08:35 / cg"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
start
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    "return the startPoint"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    ^ startPoint
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    "Created: 8.5.1996 / 21:08:44 / cg"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
start:p1 middle:p2 end:p3
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    "set the startPoint, middlePoint and the endPoint"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    startPoint := p1.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    middlePoint := p2.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    endPoint := p3.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
    "Created: 8.5.1996 / 21:09:40 / cg"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
! !
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   156
!Curve methodsFor:'converting'!
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   157
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   158
asPointArray
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   159
    "return an array containing my points."
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   160
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   161
    ^ Array with:startPoint with:middlePoint with:endPoint
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   162
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   163
    "Created: 9.5.1996 / 01:07:07 / cg"
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   164
!
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   165
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   166
asPolygon
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   167
    "return a polygon, approximating the spline"
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   168
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   169
    ^ Polygon vertices:(self computeLineSegments)
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   170
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   171
    "Created: 9.5.1996 / 01:08:12 / cg"
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   172
! !
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   173
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
!Curve methodsFor:'displaying'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
displayFilledOn:aGC
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    "draw the receiver as a filled curve in a graphicsContext, aGC"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   179
    aGC fillPolygon:self computeLineSegments
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    "Created: 8.5.1996 / 21:24:15 / cg"
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   182
    "Modified: 9.5.1996 / 01:08:34 / cg"
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
displayStrokedOn:aGC
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    "draw the receiver as a unfilled curve in a graphicsContext, aGC"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   188
    aGC displayPolygon:self computeLineSegments
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   190
    "Modified: 9.5.1996 / 01:08:36 / cg"
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
! !
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
!Curve methodsFor:'helpers'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   195
computeLineSegments
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    "compute the lines which approxiamte this curve"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    |lines pa pb 
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
     numberOfSegments "{ Class: SmallInteger }"|
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    lines := OrderedCollection new.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
    "/ Compute the number of line segments used to approximate the curve.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    pa := middlePoint - startPoint.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    pb := endPoint - middlePoint.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    numberOfSegments := 5 max:pa x abs + pa y abs + pb x abs + pb y abs // 20.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    "/ Add all of the points necessary for the path.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    lines add:startPoint.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    1 to:numberOfSegments do:[:seg | 
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
        lines add:
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
                ((pa * seg // numberOfSegments + startPoint) * (numberOfSegments - seg)
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
                + ((pb * (seg - 1) // numberOfSegments + middlePoint) * (seg - 1)))
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
                // (numberOfSegments - 1)
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    ].
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    lines add:endPoint.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    ^ lines
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
289
c4a61914a9a0 more examples & comments
Claus Gittinger <cg@exept.de>
parents: 285
diff changeset
   220
    "Created: 9.5.1996 / 01:08:21 / cg"
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
! !
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
!Curve methodsFor:'queries'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
bounds
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    "return the smallest enclosing rectangle"
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    |min max|
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    min := (startPoint min: endPoint) min: middlePoint.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
    max := (startPoint max: endPoint) max: middlePoint.
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    ^ min corner:max
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    "
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
     (Curve from:10@10 to:50@100 through:50@50) bounds   
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
     (Curve from:10@10 to:50@100 through:100@50) bounds 
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    "
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    "Modified: 8.5.1996 / 21:18:50 / cg"
374
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   240
!
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   241
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   242
canBeFilled
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   243
    "return true, if the receiver can be drawn as a filled geometric.
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   244
     Always true here."
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   245
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   246
    ^ true
a77f804c605e added #canBeFilled for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 346
diff changeset
   247
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
! !
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
!Curve class methodsFor:'documentation'!
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
version
1303
6ca5f36cdc63 category
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   253
    ^ '$Header: /cvs/stx/stx/libbasic2/Curve.st,v 1.7 2003-08-29 17:32:10 cg Exp $'
285
7d46d088d2c0 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
! !