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