Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorModel/BasicTypes/SvgRect.cs @ 13918

Last change on this file since 13918 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 3.0 KB
Line 
1// <developer>niklas@protocol7.com</developer>
2// <developer>kevin@kevlindev.com</developer>
3// <completed>100</completed>
4
5using System;
6using System.Globalization;
7using System.Text.RegularExpressions;
8
9namespace SharpVectors.Dom.Svg
10{
11  /// <summary>
12  /// Rectangles are defined as consisting of a (x,y) coordinate pair
13  /// identifying a minimum X value, a minimum Y value, and a width
14  /// and height, which are usually constrained to be non-negative.
15  /// </summary>
16    public sealed class SvgRect : ISvgRect
17  {
18        #region Static Fields
19
20        public static readonly SvgRect Empty = new SvgRect(0,0,0,0);
21       
22        #endregion
23
24        #region Private Fields
25
26        private double x;
27        private double y;
28        private double width;
29        private double height;
30   
31        #endregion
32
33    #region Constructors
34
35        public SvgRect(double x, double y, double width, double height)
36        {
37            this.x      = x;
38            this.y      = y;
39            this.width  = width;
40            this.height = height;
41        }
42
43    public SvgRect(string str)
44    {
45      string replacedStr = Regex.Replace(str, @"(\s|,)+", ",");
46      string[] tokens = replacedStr.Split(new char[]{','});
47      if (tokens.Length == 2)
48      {
49        this.x      = 0;
50        this.y      = 0;
51        this.width  = SvgNumber.ParseNumber(tokens[0]);
52        this.height = SvgNumber.ParseNumber(tokens[1]);
53      }
54            else if (tokens.Length == 4)
55            {
56                this.x      = SvgNumber.ParseNumber(tokens[0]);
57                this.y      = SvgNumber.ParseNumber(tokens[1]);
58                this.width  = SvgNumber.ParseNumber(tokens[2]);
59                this.height = SvgNumber.ParseNumber(tokens[3]);
60            }
61      else
62      {
63        throw new SvgException(SvgExceptionType.SvgInvalidValueErr,
64                    "Invalid SvgRect value: " + str);
65      }
66    }
67
68        #endregion
69
70    #region Public Properties
71
72    public bool IsEmpty
73    {
74      get
75      {
76        return (width <= 0 || height <= 0);
77      }
78    }
79
80    #endregion
81
82        #region Public Methods
83
84        public override string ToString()
85    {
86            return ("{X=" + this.X.ToString(CultureInfo.CurrentCulture)
87                + ",Y=" + this.Y.ToString(CultureInfo.CurrentCulture)
88                + ",Width=" + this.Width.ToString(CultureInfo.CurrentCulture)
89                + ",Height=" + this.Height.ToString(CultureInfo.CurrentCulture) + "}");
90        }
91
92        #endregion
93
94        #region ISvgRect Interface
95
96        public double X
97    {
98      get
99      {
100        return x;
101      }
102      set
103      {
104        x = value;
105      }
106    }
107
108    public double Y
109    {
110      get
111      {
112        return y;
113      }
114      set
115      {
116        y = value;
117      }
118    }
119
120    public double Width
121    {
122      get
123      {
124        return width;
125      }
126      set
127      {
128        width = value;
129      }
130    }
131
132    public double Height
133    {
134      get
135      {
136        return height;
137      }
138      set
139      {
140        height = value;
141      }
142    }
143
144    #endregion
145  }
146}
Note: See TracBrowser for help on using the repository browser.