Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit b2867d8

Browse files
committed
Minor generalizations, now RegularLightSpectrum has more flexible constructors
1 parent 896d529 commit b2867d8

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

ColorSharp/src/LightSpectrums/RegularLightSpectrum.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929

3030
using System;
31+
using System.Collections.Generic;
32+
using System.Collections.ObjectModel;
3133

3234

3335
namespace Litipk.ColorSharp
@@ -44,33 +46,33 @@ public sealed class RegularLightSpectrum : ALightSpectrum
4446
#region properties
4547

4648
// Needed values to interpret the data points
47-
readonly double NmPerStep;
48-
readonly double MinWaveLength;
49-
readonly double MaxWaveLength;
49+
public readonly double NmPerStep;
50+
public readonly double MinWaveLength;
51+
public readonly double MaxWaveLength;
5052

5153
// Data points
52-
readonly double[] Amplitudes;
54+
public readonly ReadOnlyCollection<double> Amplitudes;
5355
#endregion
5456

5557

5658
#region constructors
5759

5860
// Constructor
59-
public RegularLightSpectrum (double minWaveLength, double maxWaveLength, double[] amplitudes, AConvertibleColor dataSource=null) : base(dataSource)
61+
public RegularLightSpectrum (double minWaveLength, double maxWaveLength, IList<double> amplitudes, AConvertibleColor dataSource=null) : base(dataSource)
6062
{
6163
MinWaveLength = minWaveLength;
6264
MaxWaveLength = maxWaveLength;
63-
NmPerStep = (maxWaveLength - minWaveLength) / (amplitudes.Length - 1);
64-
Amplitudes = amplitudes;
65+
NmPerStep = (maxWaveLength - minWaveLength) / (amplitudes.Count - 1);
66+
Amplitudes = new ReadOnlyCollection<double> (amplitudes);
6567
}
6668

6769
// Constructor
68-
public RegularLightSpectrum (double minWaveLength, double[] amplitudes, double nmPerStep, AConvertibleColor dataSource=null) : base(dataSource)
70+
public RegularLightSpectrum (double minWaveLength, IList<double> amplitudes, double nmPerStep, AConvertibleColor dataSource=null) : base(dataSource)
6971
{
7072
NmPerStep = nmPerStep;
7173
MinWaveLength = minWaveLength;
72-
MaxWaveLength = minWaveLength + nmPerStep * (amplitudes.Length - 1);
73-
Amplitudes = amplitudes;
74+
MaxWaveLength = minWaveLength + nmPerStep * (amplitudes.Count - 1);
75+
Amplitudes = new ReadOnlyCollection<double> (amplitudes);
7476
}
7577

7678
#endregion
@@ -86,7 +88,7 @@ public override double EvaluateAt (double waveLength)
8688
if (waveLength >= MinWaveLength && waveLength <= MaxWaveLength) {
8789
double dblIndex = (waveLength - MinWaveLength) / NmPerStep;
8890
double floorIndex = Math.Floor (dblIndex);
89-
uint uIndex = (uint)floorIndex;
91+
int uIndex = (int)floorIndex;
9092

9193
if (dblIndex - floorIndex <= 2*double.Epsilon) {
9294
return Amplitudes [uIndex];
@@ -124,7 +126,7 @@ public override double GetMaxValueOnSupport ()
124126
{
125127
double max = 0;
126128

127-
for (int i = 0; i < Amplitudes.Length; i++) {
129+
for (int i = 0; i < Amplitudes.Count; i++) {
128130
if (Amplitudes [i] > max) {
129131
max = Amplitudes [i];
130132
}
@@ -138,7 +140,7 @@ public override double GetMaxValueOnSupport ()
138140
*/
139141
public override int GetNumberOfDataPoints()
140142
{
141-
return Amplitudes.Length;
143+
return Amplitudes.Count;
142144
}
143145

144146
/**

0 commit comments

Comments
 (0)