Blend.cs 1.8 KB

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