Marcel Taeumel uploaded a new version of ST80 to project The Trunk:
http://source.squeak.org/trunk/ST80-ct.269.mcz ==================== Summary ==================== Name: ST80-ct.269 Author: ct Time: 17 April 2021, 10:06:28.149652 pm UUID: 2f319f7f-9553-0d47-94ea-f3398af6f4b4 Ancestors: ST80-mt.268 Reuse new Arc >> #computeVertices: to display arcs. Complements ST80-ct.240. Also added an extension point for modifying the granularity of arcs, #numberOfVertices. Sorry for the confusion, this patch has somehow went down in my changes file. :-) Benchmarks: Use anArc from Arc example and do: [anArc displayOn: Display] bench. Before: 726 microseconds per run. After: 650 microseconds per run. =============== Diff against ST80-mt.268 =============== Item was changed: Path subclass: #Arc + instanceVariableNames: 'quadrant radius center numberOfVertices' - instanceVariableNames: 'quadrant radius center' classVariableNames: '' poolDictionaries: '' category: 'ST80-Paths'! !Arc commentStamp: '<historical>' prior: 0! Arcs are an unusual implementation of splines due to Ted Kaehler. Imagine two lines that meet at a corner. Now imagine two moving points; one moves from the corner to the end on one line, the other moves from the end of the other line in to the corner. Now imagine a series of lines drawn between those moving points at each step along the way (they form a sort of spider web pattern). By connecting segments of the intersecting lines, a smooth curve is achieved that is tangent to both of the original lines. Voila.! Item was changed: ----- Method: Arc>>computeVertices: (in category 'displaying') ----- computeVertices: size | dAngle dSin dCos point | dAngle := (90 / (size - 1)) degreesToRadians. dSin := dAngle sin. dCos := dAngle cos. point := (1 to: quadrant) inject: 0 @ radius into: [:p :i | p leftRotated]. ^ (OrderedCollection new: size) add: (center + point) rounded; + addAll: ((2 to: size) collect: [:i | - addAll: ((1 to: size - 1) collect: [:i | point := point * dCos + (point * dSin) leftRotated. (center + point) rounded]); yourself! Item was changed: ----- Method: Arc>>displayOn:at:clippingBox:rule:fillColor: (in category 'displaying') ----- displayOn: aDisplayMedium at: aPoint clippingBox: clipRect rule: anInteger fillColor: aForm + | line | - | nSegments line angle sin cos xn yn | - nSegments := 12.0. line := Line new. line form: self form. + (self computeVertices: self numberOfVertices) overlappingPairsDo: [:start :dest | + line + beginPoint: start; + endPoint: dest; + displayOn: aDisplayMedium - angle := (90.0 / nSegments) degreesToRadians. - sin := angle sin. - cos := angle cos. - quadrant = 1 - ifTrue: - [xn := radius asFloat. - yn := 0.0]. - quadrant = 2 - ifTrue: - [xn := 0.0. - yn := 0.0 - radius asFloat]. - quadrant = 3 - ifTrue: - [xn := 0.0 - radius asFloat. - yn := 0.0]. - quadrant = 4 - ifTrue: - [xn := 0.0. - yn := radius asFloat]. - nSegments asInteger - timesRepeat: - [ | xn1 yn1 | - xn1 := xn * cos + (yn * sin). - yn1 := yn * cos - (xn * sin). - line beginPoint: center + (xn asInteger @ yn asInteger). - line endPoint: center + (xn1 asInteger @ yn1 asInteger). - line - displayOn: aDisplayMedium at: aPoint clippingBox: clipRect rule: anInteger + fillColor: aForm]! - fillColor: aForm. - xn := xn1. - yn := yn1]! Item was added: + ----- Method: Arc>>numberOfVertices (in category 'accessing') ----- + numberOfVertices + + ^ numberOfVertices ifNil: [12]! Item was added: + ----- Method: Arc>>numberOfVertices: (in category 'accessing') ----- + numberOfVertices: anInteger + + numberOfVertices := anInteger.! |
Free forum by Nabble | Edit this page |