Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Common/3.3/Point2D.cs @ 13262

Last change on this file since 13262 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 2.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.ComponentModel;
24using System.Globalization;
25
26namespace HeuristicLab.Common {
27  [Serializable]
28  public struct Point2D<T> where T : struct {
29    public static readonly Point2D<T> Empty = new Point2D<T>();
30
31    private T x;
32    public T X {
33      get { return x; }
34    }
35    private T y;
36    public T Y {
37      get { return y; }
38    }
39
40    [Browsable(false)]
41    public bool IsEmpty {
42      get { return Equals(Empty); }
43    }
44
45    public Point2D(T x, T y) {
46      this.x = x;
47      this.y = y;
48    }
49
50    public static bool operator ==(Point2D<T> left, Point2D<T> right) {
51      return left.x.Equals(right.x) && left.y.Equals(right.y);
52    }
53    public static bool operator !=(Point2D<T> left, Point2D<T> right) {
54      return !(left == right);
55    }
56
57    public override bool Equals(object obj) {
58      if (!(obj is Point2D<T>))
59        return false;
60      Point2D<T> point = (Point2D<T>)obj;
61      return x.Equals(point.x) && y.Equals(point.y) && GetType().Equals(point.GetType());
62    }
63    public override int GetHashCode() {
64      return base.GetHashCode();
65    }
66
67    public override string ToString() {
68      return string.Format((IFormatProvider)CultureInfo.CurrentCulture, "{{X={0}, Y={1}}}", new object[2] { x, y });
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.