[squeak-dev] The Trunk: Morphic-ul.556.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Jul 25 09:27:49 UTC 2011
Levente Uzonyi uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-ul.556.mcz
==================== Summary ====================
Name: Morphic-ul.556
Author: ul
Time: 25 July 2011, 1:41:43.183 am
UUID: 674e0386-e032-5c40-8708-f89d2f73edd7
Ancestors: Morphic-ul.555
Various speedups for curves:
- avoid an unnecessary assert (with an unnecessary block) in Cubic>>honeIn:.
- pass a point for #polynomialEval:, instead of a Float to avoid Point-Float multiplications in Cubic>>measureFor:
- avoid interval creation in SequenceableCollection>>changeOfChangesInSlopes: and SequenceableCollection>>closedCubicSlopes
- avoid creating intermediate objects in SequenceableCollection>>cubicPointPolynomialAt:
=============== Diff against Morphic-ul.555 ===============
Item was changed:
----- Method: Cubic>>honeIn: (in category 'cubic support') -----
honeIn: enough
"Find if there is a smaller n than enough that give the same
measure for n."
+
+ enough < 2 ifTrue: [ ^enough].
- self
- assert: [enough isPowerOfTwo].
- enough < 2
- ifTrue: [^ enough].
^ self
honeIn: enough
step: enough // 2
measure: (self measureFor: enough)
withIn: self leeway!
Item was changed:
----- Method: Cubic>>measureFor: (in category 'cubic support') -----
measureFor: n
"Return a distance measure for cubic curve with n segments.
For convienence and accuracy we use the sum of the
distances. "
"first point is poly of 0."
+ | p1 measure |
+ p1 := self at: 1.
- | p1 p2 measure |
- p1 := self first.
measure := 0.
+ 1 to: n do: [ :i |
+ | x p2 |
+ x := i asFloat / n.
+ p2 := self polynomialEval: x @ x.
+ measure := measure + (p2 dist: p1).
+ p1 := p2 ].
+ ^measure!
- 1 to: n
- do: [:i |
- p2 := self polynomialEval: i / n asFloat.
- measure := measure
- + (p2 dist: p1).
- p1 := p2].
- ^ measure!
Item was changed:
----- Method: SequenceableCollection>>changeOfChangesInSlopes: (in category '*Morphic-NewCurves-cubic support') -----
changeOfChangesInSlopes: slopes
"A message to knots of a spline. Returns an array with the 4rd
cubic coeff."
"The last nth item is correct iff this is a closed cubic.
Presumably that is the only time we care.
We always return the same sized array as self."
| n changes |
n := self size.
n = slopes size
ifFalse: [^ self error: 'vertices and slopes differ in number'].
changes := Array new: n.
+ 1 to: n do: [ :i |
+ changes at: i put: (self at: i)
+ - (self atWrap: i + 1) * 2
+ + (slopes at: i)
+ + (slopes atWrap: i + 1) ].
- (1 to: n)
- do: [:i | changes at: i put: (self at: i)
- - (self atWrap: i + 1) * 2
- + (slopes at: i)
- + (slopes atWrap: i + 1)].
-
^ changes!
Item was changed:
----- Method: SequenceableCollection>>closedCubicSlopes (in category '*Morphic-NewCurves-cubic support') -----
closedCubicSlopes
"Sent to knots returns the slopes of a closed cubic spline.
From the same set of java sources as naturalCubic. This is a squeak
transliteration of the java code."
"from java code NatCubicClosed extends NatCubic
solves for the set of equations for all knots:
b1+4*b2+b3=3*(a3-a1)
where a1 is (knots atWrap: index + 1) etc.
and the b's are the slopes .
by decomposing the matrix into upper triangular and lower matrices
and then back sustitution. See Spath 'Spline Algorithms for Curves
and Surfaces' pp 19--21. The D[i] are the derivatives at the knots.
"
| v w x y z n1 D F G H |
n1 := self size.
n1 < 3
ifTrue: [self error: 'Less than 3 points makes a poor curve'].
v := Array new: n1.
w := Array new: n1.
y := Array new: n1.
D := Array new: n1.
x := self.
z := 1.0 / 4.0.
v at: 2 put: z.
w at: 2 put: z.
y at: 1 put: z * 3.0 * ((x at: 2)
- (x at: n1)).
H := 4.0.
F := 3 * ((x at: 1)
- (x at: n1 - 1)).
G := 1.
2 to: n1 - 1
do: [:k |
z := 1.0 / (4.0
- (v at: k)).
v at: k + 1 put: z.
w at: k + 1 put: z negated
* (w at: k).
y at: k put: z * (3.0 * ((x at: k + 1)
- (x at: k - 1))
- (y at: k - 1)).
H := H - (G
* (w at: k)).
F := F - (G
* (y at: k - 1)).
G := (v at: k) negated * G].
H := H - (G + 1 * ((v at: n1)
+ (w at: n1))).
y at: n1 put: F - (G + 1
* (y at: n1 - 1)).
D at: n1 put: (y at: n1)
/ H.
D at: n1 - 1 put: (y at: n1 - 1)
- ((v at: n1)
+ (w at: n1)
* (D at: n1)).
+ n1 -2 to: 1 by: -1 do: [ :k |
+ D at: k put:
+ (y at: k)
- (1 to: n1 - 2)
- reverseDo: [:k | D at: k put: (y at: k)
- ((v at: k + 1)
* (D at: k + 1)) - ((w at: k + 1)
* (D at: n1))].
^ D .!
Item was changed:
----- Method: SequenceableCollection>>cubicPointPolynomialAt: (in category '*Morphic-NewCurves-cubic support') -----
cubicPointPolynomialAt: vIndex
"From curve information assemble a 4-array of points representing the coefficents for curve segment between to points. Beginning point is first point in array endpoint is the pointSum of the array. Meant to be sent to newcurves idea of curve coefficents."
+
+ | result |
+ result := Cubic new: 4.
+ 1 to: 4 do: [ :i |
+ result at: i put: ((self at: i) at: vIndex) @ ((self at: 4 + i) at: vIndex) ].
+ ^result!
- ^ ((1 to: 4)
- collect: [:i | ((self at: i)
- at: vIndex)
- @ ((self at: 4 + i)
- at: vIndex)]) asCubic!
More information about the Squeak-dev
mailing list
|