Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Common/3.3/Point2D.cs @ 17330

Last change on this file since 17330 was 17246, checked in by gkronber, 5 years ago

#2925: merged r17037:17242 from trunk to branch

File size: 2.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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;
25using HEAL.Attic;
26
27namespace HeuristicLab.Common {
28  [Serializable]
29  [StorableType("9c4b8927-6b8e-490f-a367-78091ccf1494")]
30  public struct Point2D<T> where T : struct, IEquatable<T> {
31    public static readonly Point2D<T> Empty = new Point2D<T>();
32
33    private T x;
34    public T X {
35      get { return x; }
36    }
37
38    private T y;
39    public T Y {
40      get { return y; }
41    }
42
43    private object tag;
44    public object Tag {
45      get { return tag; }
46    }
47
48    [Browsable(false)]
49    public bool IsEmpty {
50      get { return Equals(Empty); }
51    }
52
53    public Point2D(T x, T y, object tag = null) {
54      this.x = x;
55      this.y = y;
56      this.tag = tag;
57    }
58
59    public static Point2D<T> Create(T x, T y, object tag = null) {
60      return new Point2D<T>(x, y, tag);
61    }
62
63    public static bool operator ==(Point2D<T> left, Point2D<T> right) {
64      return left.x.Equals(right.x) && left.y.Equals(right.y) && left.tag == right.tag;
65    }
66    public static bool operator !=(Point2D<T> left, Point2D<T> right) {
67      return !(left == right);
68    }
69
70    public override bool Equals(object obj) {
71      if (!(obj is Point2D<T>))
72        return false;
73      Point2D<T> point = (Point2D<T>)obj;
74      return GetType() == point.GetType() && x.Equals(point.x) && y.Equals(point.y) &&
75             ((tag != null && tag.Equals(point.tag)) || tag == point.tag);
76    }
77    public override int GetHashCode() {
78      return base.GetHashCode();
79    }
80
81    public override string ToString() {
82      return string.Format((IFormatProvider)CultureInfo.CurrentCulture, "{{X={0}, Y={1}}}", new object[2] { x, y });
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.