@@ -130,35 +130,52 @@ def testPointMultiplicity( self ) :
130130 def testSolveAndCall ( self ) :
131131
132132 random .seed ( 0 )
133- for i in range ( 0 , 100 ) :
134133
135- s = IECore .Splineff ()
136- x = 0
137-
138- for i in range ( 0 , 40 ) :
139-
140- s [x ] = random .uniform ( 0 , 10 )
141- x += 1 + random .uniform ( 0 , 1 )
142-
143- xv = s .keys ()
144- yv = s .values ()
145-
146- for i in range ( 0 , 1000 ) :
147-
148- # select a segment
149- seg = int ( random .uniform ( 0 , len (xv ) - 3 ) )
150- seg -= seg % s .basis .step
151- # evaluate an x,y point on the curve directly
152- # ourselves
153- t = i / 1000.0
154- c = s .basis .coefficients ( t )
155- x = xv [seg + 0 ] * c [0 ] + xv [seg + 1 ] * c [1 ] + xv [seg + 2 ] * c [2 ] + xv [seg + 3 ] * c [3 ]
156- y = yv [seg + 0 ] * c [0 ] + yv [seg + 1 ] * c [1 ] + yv [seg + 2 ] * c [2 ] + yv [seg + 3 ] * c [3 ]
157-
158- # then check that solving for x gives y
159- yy = s ( x )
160-
161- self .assertAlmostEqual ( yy , y , 3 )
134+ for b in [
135+ IECore .StandardCubicBasis .Linear ,
136+ IECore .StandardCubicBasis .Bezier ,
137+ IECore .StandardCubicBasis .BSpline ,
138+ IECore .StandardCubicBasis .CatmullRom ,
139+ IECore .StandardCubicBasis .Constant
140+ ]:
141+ for i in range ( 0 , 100 ) :
142+
143+ s = IECore .Splineff ( IECore .CubicBasisf ( b ) )
144+ numCoeffs = s .basis .numCoefficients ()
145+ x = 0
146+
147+ numCVs = 40
148+ for i in range ( 0 , numCVs ) :
149+
150+ s [x ] = random .uniform ( 0 , 10 )
151+ x += 1 + random .uniform ( 0 , 1 )
152+
153+ # Pad with zeroes so we can evaluate the last segment for basis that doesn't use all 4 coefficients
154+ xv = s .keys () + ( 0.0 , ) * ( 4 - numCoeffs )
155+ yv = s .values () + ( 0.0 , ) * ( 4 - numCoeffs )
156+
157+ for i in range ( 0 , 1000 ) :
158+
159+ # select a segment
160+ seg = int (random .uniform ( 0 , 1 + numCVs - numCoeffs ) )
161+ seg -= seg % s .basis .step
162+
163+ # evaluate an x,y point on the curve directly
164+ # ourselves
165+ t = i / 1000.0
166+ c = s .basis .coefficients ( t )
167+ if b == IECore .StandardCubicBasis .Constant and seg + 1 < numCVs :
168+ # For the constant basis, we can test any of the positions in X within this span,
169+ # not just the beginning point, which is the only point the basis will give us
170+ x = xv [seg + 0 ] * ( 1 - t ) + xv [seg + 1 ] * t
171+ else :
172+ x = xv [seg + 0 ] * c [0 ] + xv [seg + 1 ] * c [1 ] + xv [seg + 2 ] * c [2 ] + xv [seg + 3 ] * c [3 ]
173+ y = yv [seg + 0 ] * c [0 ] + yv [seg + 1 ] * c [1 ] + yv [seg + 2 ] * c [2 ] + yv [seg + 3 ] * c [3 ]
174+
175+ # then check that solving for x gives y
176+ yy = s ( x )
177+
178+ self .assertAlmostEqual ( yy , y , 3 )
162179
163180 def testRepr ( self ) :
164181
0 commit comments