/* * Copyright (C) 2013 FooProject * * 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 * the Free Software Foundation; either version 3 of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; namespace FooEditEngine { struct SrcPoint { public double X; public int Row; public double Y; public double GetOffsetY(double line_height) { return this.Row * line_height - this.Y; } public SrcPoint(double x, int row, double y) { if (row < 0) throw new ArgumentOutOfRangeException("マイナスを値を指定することはできません"); this.X = x; this.Row = row; this.Y = y; } } /// /// テキストの範囲を表す /// public struct TextRange { /// /// 開始インデックス /// public int Index; /// /// 長さ /// public int Length; /// /// 空の範囲を表す /// public static TextRange Null = new TextRange(0, 0); /// /// コンストラクター /// /// 開始インデックス /// 長さ public TextRange(int index, int length) { this.Index = index; this.Length = length; } } /// /// 文章の位置を示すクラス /// public struct TextPoint : IComparable { /// /// 行番号 /// public int row; /// /// 桁 /// public int col; /// /// TextPointがドキュメント上のどこも指していないことを表す /// public static readonly TextPoint Null = new TextPoint(-1,-1); /// /// コンストラクター /// /// 行番号 /// 桁 public TextPoint(int row, int col) { this.row = row; this.col = col; } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator <(TextPoint a, TextPoint b) { return a.CompareTo(b) == -1; } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator <=(TextPoint a, TextPoint b) { return a.CompareTo(b) != 1; } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator >(TextPoint a, TextPoint b) { return a.CompareTo(b) == 1; } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator >=(TextPoint a, TextPoint b) { return a.CompareTo(b) != -1; } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator ==(TextPoint a, TextPoint b) { return a.Equals(b); } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator !=(TextPoint a, TextPoint b) { return !a.Equals(b); } /// /// 一致するかどうか /// /// 比較対象 /// 一致するなら真 public override bool Equals(object o) { TextPoint b = (TextPoint)o; return this.col == b.col && this.row == b.row; } /// /// ハッシュを返す /// /// ハッシュを返す public override int GetHashCode() { int result = this.row.GetHashCode(); result ^= this.col.GetHashCode(); return result; } #region IComparable メンバー /// /// 比較する /// /// 比較対象となるTextPointオブジェクト /// 相対値を返す public int CompareTo(TextPoint other) { if (this.row == other.row && this.col == other.col) return 0; if (this.row < other.row) return -1; else if (this.row == other.row && this.col < other.col) return -1; else return 1; } #endregion } /// /// 文章上での矩形エリアを表す /// public struct TextRectangle { TextPoint _TopLeft; TextPoint _BottomRight; /// /// 矩形エリアがドキュメントのどこも指していないことを表す /// public static readonly TextRectangle Null = new TextRectangle(new TextPoint(-1,-1),new TextPoint(-1,-1)); /// /// 左上を表す /// public TextPoint TopLeft { get { return this._TopLeft; } } /// /// 右上を表す /// public TextPoint TopRight { get { return new TextPoint(this._TopLeft.row, this._BottomRight.col); } } /// /// 左下を表す /// public TextPoint BottomLeft { get { return new TextPoint(this._BottomRight.row, this._TopLeft.col); } } /// /// 右下を表す /// public TextPoint BottomRight { get { return this._BottomRight; } } /// /// コンストラクター /// /// 行 /// 桁 /// 高さ /// 幅 public TextRectangle(int row, int col, int height,int width) { this._TopLeft = new TextPoint(row, col); this._BottomRight = new TextPoint(row + height - 1, col + width - 1); } /// /// コンストラクター /// /// 矩形の左上 /// 矩形の右下 public TextRectangle(TextPoint topLeft, TextPoint bottomRight) { this._TopLeft = topLeft; this._BottomRight = bottomRight; } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator ==(TextRectangle a, TextRectangle b) { return a.Equals(b); } /// /// 比較演算子を実装します /// /// 比較される方 /// 比較対象 /// 条件を満たすなら真 public static bool operator !=(TextRectangle a, TextRectangle b) { return !a.Equals(b); } /// /// 一致するかどうか /// /// 比較対象 /// 一致するなら真 public override bool Equals(object o) { TextRectangle b = (TextRectangle)o; return this._TopLeft == b._TopLeft && this._BottomRight == b._BottomRight; } /// /// ハッシュを返す /// /// ハッシュを返す public override int GetHashCode() { int result = this._TopLeft.GetHashCode(); result ^= this._BottomRight.GetHashCode(); return result; } } }