OSDN Git Service

ルーラーとラインマーカーが重なって表示される問題を修正した
[fooeditengine/FooEditEngine.git] / Common / TextPoint.cs
1 /*\r
2  * Copyright (C) 2013 FooProject\r
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by\r
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\r
5 \r
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of \r
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\r
8 \r
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.\r
10  */\r
11 using System;\r
12 \r
13 namespace FooEditEngine\r
14 {\r
15     struct Point2\r
16     {\r
17         public double X;\r
18         public int Row;\r
19         public Point2(double x, int row)\r
20         {\r
21             this.X = x;\r
22             this.Row = row;\r
23         }\r
24     }\r
25     /// <summary>\r
26     /// 文章の位置を示すクラス\r
27     /// </summary>\r
28     public struct TextPoint : IComparable<TextPoint>\r
29     {\r
30         /// <summary>\r
31         /// 行番号\r
32         /// </summary>\r
33         public int row;\r
34         /// <summary>\r
35         /// 桁\r
36         /// </summary>\r
37         public int col;\r
38 \r
39         /// <summary>\r
40         /// TextPointがドキュメント上のどこも指していないことを表す\r
41         /// </summary>\r
42         public static readonly TextPoint Null = new TextPoint(-1,-1);\r
43 \r
44         /// <summary>\r
45         /// コンストラクター\r
46         /// </summary>\r
47         /// <param name="row">行番号</param>\r
48         /// <param name="col">桁</param>\r
49         public TextPoint(int row, int col)\r
50         {\r
51             this.row = row;\r
52             this.col = col;\r
53         }\r
54 \r
55         /// <summary>\r
56         /// 比較演算子を実装します\r
57         /// </summary>\r
58         /// <param name="a">比較される方</param>\r
59         /// <param name="b">比較対象</param>\r
60         /// <returns>条件を満たすなら真</returns>\r
61         public static bool operator <(TextPoint a, TextPoint b)\r
62         {\r
63             return a.CompareTo(b) == -1;\r
64         }\r
65 \r
66         /// <summary>\r
67         /// 比較演算子を実装します\r
68         /// </summary>\r
69         /// <param name="a">比較される方</param>\r
70         /// <param name="b">比較対象</param>\r
71         /// <returns>条件を満たすなら真</returns>\r
72         public static bool operator <=(TextPoint a, TextPoint b)\r
73         {\r
74             return a.CompareTo(b) != 1;\r
75         }\r
76 \r
77         /// <summary>\r
78         /// 比較演算子を実装します\r
79         /// </summary>\r
80         /// <param name="a">比較される方</param>\r
81         /// <param name="b">比較対象</param>\r
82         /// <returns>条件を満たすなら真</returns>\r
83         public static bool operator >(TextPoint a, TextPoint b)\r
84         {\r
85             return a.CompareTo(b) == 1;\r
86         }\r
87 \r
88         /// <summary>\r
89         /// 比較演算子を実装します\r
90         /// </summary>\r
91         /// <param name="a">比較される方</param>\r
92         /// <param name="b">比較対象</param>\r
93         /// <returns>条件を満たすなら真</returns>\r
94         public static bool operator >=(TextPoint a, TextPoint b)\r
95         {\r
96             return a.CompareTo(b) != -1;\r
97         }\r
98 \r
99         /// <summary>\r
100         /// 比較演算子を実装します\r
101         /// </summary>\r
102         /// <param name="a">比較される方</param>\r
103         /// <param name="b">比較対象</param>\r
104         /// <returns>条件を満たすなら真</returns>\r
105         public static bool operator ==(TextPoint a, TextPoint b)\r
106         {\r
107             return a.Equals(b);\r
108         }\r
109 \r
110         /// <summary>\r
111         /// 比較演算子を実装します\r
112         /// </summary>\r
113         /// <param name="a">比較される方</param>\r
114         /// <param name="b">比較対象</param>\r
115         /// <returns>条件を満たすなら真</returns>\r
116         public static bool operator !=(TextPoint a, TextPoint b)\r
117         {\r
118             return !a.Equals(b);\r
119         }\r
120 \r
121         /// <summary>\r
122         /// 一致するかどうか\r
123         /// </summary>\r
124         /// <param name="o">比較対象</param>\r
125         /// <returns>一致するなら真</returns>\r
126         public override bool Equals(object o)\r
127         {\r
128             TextPoint b = (TextPoint)o;\r
129             return this.col == b.col && this.row == b.row;\r
130         }\r
131 \r
132         /// <summary>\r
133         /// ハッシュを返す\r
134         /// </summary>\r
135         /// <returns>ハッシュを返す</returns>\r
136         public override int GetHashCode()\r
137         {\r
138             int result = this.row.GetHashCode();\r
139             result ^= this.col.GetHashCode();\r
140             return result;\r
141         }\r
142 \r
143         #region IComparable<TextPoint> メンバー\r
144 \r
145         /// <summary>\r
146         /// 比較する\r
147         /// </summary>\r
148         /// <param name="other">比較対象となるTextPointオブジェクト</param>\r
149         /// <returns>相対値を返す</returns>\r
150         public int CompareTo(TextPoint other)\r
151         {\r
152             if (this.row == other.row && this.col == other.col)\r
153                 return 0;\r
154             if (this.row < other.row)\r
155                 return -1;\r
156             else if (this.row == other.row && this.col < other.col)\r
157                 return -1;\r
158             else\r
159                 return 1;\r
160         }\r
161 \r
162         #endregion\r
163     }\r
164 \r
165     /// <summary>\r
166     /// 文章上での矩形エリアを表す\r
167     /// </summary>\r
168     public struct TextRectangle\r
169     {\r
170         TextPoint _TopLeft;\r
171         \r
172         TextPoint _BottomRight;\r
173 \r
174         /// <summary>\r
175         /// 矩形エリアがドキュメントのどこも指していないことを表す\r
176         /// </summary>\r
177         public static readonly TextRectangle Null = new TextRectangle(new TextPoint(-1,-1),new TextPoint(-1,-1));\r
178 \r
179         /// <summary>\r
180         /// 左上を表す\r
181         /// </summary>\r
182         public TextPoint TopLeft\r
183         {\r
184             get\r
185             {\r
186                 return this._TopLeft;\r
187             }\r
188         }\r
189 \r
190         /// <summary>\r
191         /// 右上を表す\r
192         /// </summary>\r
193         public TextPoint TopRight\r
194         {\r
195             get\r
196             {\r
197                 return new TextPoint(this._TopLeft.row, this._BottomRight.col);\r
198             }\r
199         }\r
200 \r
201         /// <summary>\r
202         /// 左下を表す\r
203         /// </summary>\r
204         public TextPoint BottomLeft\r
205         {\r
206             get\r
207             {\r
208                 return new TextPoint(this._BottomRight.row, this._TopLeft.col);\r
209             }\r
210         }\r
211 \r
212         /// <summary>\r
213         /// 右下を表す\r
214         /// </summary>\r
215         public TextPoint BottomRight\r
216         {\r
217             get\r
218             {\r
219                 return this._BottomRight;\r
220             }\r
221         }\r
222 \r
223         /// <summary>\r
224         /// コンストラクター\r
225         /// </summary>\r
226         /// <param name="row">行</param>\r
227         /// <param name="col">桁</param>\r
228         /// <param name="height">高さ</param>\r
229         /// <param name="width">幅</param>\r
230         public TextRectangle(int row, int col, int height,int width)\r
231         {\r
232             this._TopLeft = new TextPoint(row, col);\r
233             this._BottomRight = new TextPoint(row + height - 1, col + width - 1);\r
234         }\r
235         \r
236         /// <summary>\r
237         /// コンストラクター\r
238         /// </summary>\r
239         /// <param name="topLeft">矩形の左上</param>\r
240         /// <param name="bottomRight">矩形の右下</param>\r
241         public TextRectangle(TextPoint topLeft, TextPoint bottomRight)\r
242         {\r
243             this._TopLeft = topLeft;\r
244             this._BottomRight = bottomRight;\r
245         }\r
246 \r
247         /// <summary>\r
248         /// 比較演算子を実装します\r
249         /// </summary>\r
250         /// <param name="a">比較される方</param>\r
251         /// <param name="b">比較対象</param>\r
252         /// <returns>条件を満たすなら真</returns>\r
253         public static bool operator ==(TextRectangle a, TextRectangle b)\r
254         {\r
255             return a.Equals(b);\r
256         }\r
257 \r
258         /// <summary>\r
259         /// 比較演算子を実装します\r
260         /// </summary>\r
261         /// <param name="a">比較される方</param>\r
262         /// <param name="b">比較対象</param>\r
263         /// <returns>条件を満たすなら真</returns>\r
264         public static bool operator !=(TextRectangle a, TextRectangle b)\r
265         {\r
266             return !a.Equals(b);\r
267         }\r
268 \r
269         /// <summary>\r
270         /// 一致するかどうか\r
271         /// </summary>\r
272         /// <param name="o">比較対象</param>\r
273         /// <returns>一致するなら真</returns>\r
274         public override bool Equals(object o)\r
275         {\r
276             TextRectangle b = (TextRectangle)o;\r
277             return this._TopLeft == b._TopLeft && this._BottomRight == b._BottomRight;\r
278         }\r
279 \r
280         /// <summary>\r
281         /// ハッシュを返す\r
282         /// </summary>\r
283         /// <returns>ハッシュを返す</returns>\r
284         public override int GetHashCode()\r
285         {\r
286             int result = this._TopLeft.GetHashCode();\r
287             result ^= this._BottomRight.GetHashCode();\r
288             return result;\r
289         }\r
290     }\r
291 }\r