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