@@ -386,12 +386,86 @@ void testSpectralData_Operators()
386386 }
387387}
388388
389+ void testSpectralData_ReshapeInterpolation ()
390+ {
391+ // / Create a spectrum with a different shape that will require interpolation
392+ // / Source: 380-400 nm with step 10 (so samples at 380, 390, 400)
393+ // / Target: ReferenceShape 380-780 nm with step 5 (so samples at 380, 385, 390, 395, 400, ...)
394+ // / This will trigger interpolation at 385 (between 380 and 390) and 395 (between 390 and 400)
395+ rta::core::Spectrum::Shape source_shape = { 380 , 400 , 10 };
396+ rta::core::Spectrum spectrum ( 0.0 , source_shape );
397+
398+ // / Set known values
399+ spectrum.values [0 ] = 10.0 ; // / Value at 380 nm
400+ spectrum.values [1 ] = 20.0 ; // / Value at 390 nm
401+ spectrum.values [2 ] = 30.0 ; // / Value at 400 nm
402+
403+ // / Verify initial shape
404+ OIIO_CHECK_EQUAL ( spectrum.shape .first , 380 );
405+ OIIO_CHECK_EQUAL ( spectrum.shape .last , 400 );
406+ OIIO_CHECK_EQUAL ( spectrum.shape .step , 10 );
407+ OIIO_CHECK_EQUAL ( spectrum.values .size (), 3 );
408+
409+ // / Reshape to ReferenceShape (380-780, step 5)
410+ spectrum.reshape ();
411+
412+ // / Verify shape changed to ReferenceShape
413+ OIIO_CHECK_EQUAL ( spectrum.shape .first , 380 );
414+ OIIO_CHECK_EQUAL ( spectrum.shape .last , 780 );
415+ OIIO_CHECK_EQUAL ( spectrum.shape .step , 5 );
416+ OIIO_CHECK_EQUAL (
417+ spectrum.values .size (),
418+ ( 780 - 380 + 5 ) / 5 ); // / Should be 81 samples
419+
420+ // / Test exact matches (no interpolation needed)
421+ OIIO_CHECK_EQUAL_THRESH (
422+ spectrum.values [0 ], 10.0 , 1e-10 ); // / 380 nm - exact match
423+ OIIO_CHECK_EQUAL_THRESH (
424+ spectrum.values [2 ], 20.0 , 1e-10 ); // / 390 nm - exact match
425+ OIIO_CHECK_EQUAL_THRESH (
426+ spectrum.values [4 ], 30.0 , 1e-10 ); // / 400 nm - exact match
427+
428+ // / Test interpolation at 385 nm (between 380 and 390)
429+ // / ratio = (385 - 380) / (390 - 380) = 5 / 10 = 0.5
430+ // / expected = 10.0 * (1.0 - 0.5) + 20.0 * 0.5 = 15.0
431+ double expected_385 = 10.0 * ( 1.0 - 0.5 ) + 20.0 * 0.5 ;
432+ OIIO_CHECK_EQUAL_THRESH ( spectrum.values [1 ], expected_385, 1e-10 );
433+
434+ // / Test interpolation at 395 nm (between 390 and 400)
435+ // / ratio = (395 - 390) / (400 - 390) = 5 / 10 = 0.5
436+ // / expected = 20.0 * (1.0 - 0.5) + 30.0 * 0.5 = 25.0
437+ double expected_395 = 20.0 * ( 1.0 - 0.5 ) + 30.0 * 0.5 ;
438+ OIIO_CHECK_EQUAL_THRESH ( spectrum.values [3 ], expected_395, 1e-10 );
439+
440+ // / Test a more complex interpolation case with non-0.5 ratio
441+ // / Create another spectrum with step 15 to get more interesting ratios
442+ rta::core::Spectrum::Shape source_shape2 = { 380 , 410 , 15 };
443+ rta::core::Spectrum spectrum2 ( 0.0 , source_shape2 );
444+
445+ // / Set values: [100.0, 200.0, 300.0] at wavelengths 380, 395, 410
446+ spectrum2.values [0 ] = 100.0 ; // / Value at 380 nm
447+ spectrum2.values [1 ] = 200.0 ; // / Value at 395 nm
448+ spectrum2.values [2 ] = 300.0 ; // / Value at 410 nm
449+
450+ spectrum2.reshape ();
451+
452+ // / Test interpolation at 390 nm (between 380 and 395)
453+ // / ratio = (390 - 380) / (395 - 380) = 10 / 15 = 2/3 ≈ 0.6667
454+ // / expected = 100.0 * (1/3) + 200.0 * (2/3)
455+ // / = 100/3 + 400/3 = 500/3 ≈ 166.6667
456+ double ratio_390 = ( 390.0 - 380.0 ) / ( 395.0 - 380.0 );
457+ double expected_390 = 100.0 * ( 1.0 - ratio_390 ) + 200.0 * ratio_390;
458+ OIIO_CHECK_EQUAL_THRESH (
459+ spectrum2.values [2 ], expected_390, 1e-10 ); // / Index 2 = 390 nm
460+ }
461+
389462int main ( int , char ** )
390463{
391464 testSpectralData_Spectrum ();
392465 testSpectralData_Properties ();
393466 testSpectralData_LoadSpst ();
394467 testSpectralData_Operators ();
468+ testSpectralData_ReshapeInterpolation ();
395469
396470 return unit_test_failures;
397471}
0 commit comments