28
28
29
29
30
30
using System ;
31
+ using System . Collections . Generic ;
32
+ using System . Collections . ObjectModel ;
31
33
32
34
33
35
namespace Litipk . ColorSharp
@@ -44,33 +46,33 @@ public sealed class RegularLightSpectrum : ALightSpectrum
44
46
#region properties
45
47
46
48
// 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 ;
50
52
51
53
// Data points
52
- readonly double [ ] Amplitudes ;
54
+ public readonly ReadOnlyCollection < double > Amplitudes ;
53
55
#endregion
54
56
55
57
56
58
#region constructors
57
59
58
60
// 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 )
60
62
{
61
63
MinWaveLength = minWaveLength ;
62
64
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 ) ;
65
67
}
66
68
67
69
// 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 )
69
71
{
70
72
NmPerStep = nmPerStep ;
71
73
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 ) ;
74
76
}
75
77
76
78
#endregion
@@ -86,7 +88,7 @@ public override double EvaluateAt (double waveLength)
86
88
if ( waveLength >= MinWaveLength && waveLength <= MaxWaveLength ) {
87
89
double dblIndex = ( waveLength - MinWaveLength ) / NmPerStep ;
88
90
double floorIndex = Math . Floor ( dblIndex ) ;
89
- uint uIndex = ( uint ) floorIndex ;
91
+ int uIndex = ( int ) floorIndex ;
90
92
91
93
if ( dblIndex - floorIndex <= 2 * double . Epsilon ) {
92
94
return Amplitudes [ uIndex ] ;
@@ -124,7 +126,7 @@ public override double GetMaxValueOnSupport ()
124
126
{
125
127
double max = 0 ;
126
128
127
- for ( int i = 0 ; i < Amplitudes . Length ; i ++ ) {
129
+ for ( int i = 0 ; i < Amplitudes . Count ; i ++ ) {
128
130
if ( Amplitudes [ i ] > max ) {
129
131
max = Amplitudes [ i ] ;
130
132
}
@@ -138,7 +140,7 @@ public override double GetMaxValueOnSupport ()
138
140
*/
139
141
public override int GetNumberOfDataPoints ( )
140
142
{
141
- return Amplitudes . Length ;
143
+ return Amplitudes . Count ;
142
144
}
143
145
144
146
/**
0 commit comments