checkin for Dennis Hayes <dennish@raytek.com>, see ChangeLog
[mono.git] / mcs / class / System.Drawing / System.Drawing.Drawing2D / Blend.cs
1 //\r
2 // System.Drawing.Drawing2D.Blend.cs\r
3 //\r
4 // Author:\r
5 //   Dennis Hayes (dennish@Raytek.com)\r
6 //\r
7 // (C) 2002/3 Ximian, Inc\r
8 //\r
9 using System;\r
10 \r
11 namespace System.Drawing.Drawing2D\r
12 {\r
13         /// <summary>\r
14         /// Summary description for Blend.\r
15         /// </summary>\r
16         public sealed class Blend\r
17         {\r
18                 private int count;\r
19                 private float [] positions;\r
20                 private float [] factors;\r
21                 public Blend(int count) {\r
22                         this.count = count;\r
23                         if(count < 2){\r
24                                 throw new ArgumentOutOfRangeException("Count", count, "Must be at least 2");\r
25                         }\r
26                         if(count == 2){\r
27                                 //FIXME: call Blend!\r
28                                 count = 2;\r
29                                 positions = new float [1];\r
30                                 factors = new float [1];\r
31                                 positions[0] = 0.0F;\r
32                                 positions[1] = 1.0F;\r
33                                 factors[0] = 0.0F;\r
34                                 factors[1] = 1.0F;\r
35                         }\r
36                         int i;\r
37                         for(i = 0; i < count; i++){\r
38                                 positions[i] = (1.0F/count) * i;\r
39                                 factors[i] = (1.0F/count) * i;\r
40                         }\r
41                         //fix any rounding errors that would generate an invald list.\r
42                         positions[0] = 0.0F;\r
43                         positions[1] = 1.0F;\r
44                         factors[0] = 0.0F;\r
45                         factors[1] = 1.0F;\r
46 \r
47                 }\r
48                 public Blend() {\r
49                         count = 2;\r
50                         positions = new float [1];\r
51                         factors = new float [1];\r
52                         positions[0] = 0.0F;\r
53                         positions[1] = 1.0F;\r
54                         factors[0] = 0.0F;\r
55                         factors[1] = 1.0F;\r
56                 }\r
57                 public float [] Factors{\r
58                         get {\r
59                                 return factors;\r
60                         }\r
61                         set{\r
62                                 count = value.GetUpperBound(0) + 1;\r
63                                 if((value[0] !=0) | (value[count-1] != 1.0F)){\r
64                                         throw new ArgumentException(" First value must be 0.0, last value must be 1.0","Factors");\r
65                                 }\r
66                                 factors = value;\r
67                         }\r
68                 }\r
69                 public float [] Positions{\r
70                         get {\r
71                                 return Positions;\r
72                         }\r
73                         set{\r
74                                 count = value.GetUpperBound(0) + 1;\r
75                                 if((value[0] !=0) | (value[count-1] != 1.0F)){\r
76                                         throw new ArgumentException(" First value must be 0.0, last value must be 1.0","Positon");\r
77                                 }\r
78                                 positions = value;\r
79                                 \r
80                         }\r
81                 }\r
82         }\r
83 }\r