[8280] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 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;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Common {
|
---|
| 27 | [Serializable]
|
---|
[15097] | 28 | public struct Point2D<T> where T : struct, IEquatable<T> {
|
---|
[8280] | 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 |
|
---|
[15097] | 40 | private object tag;
|
---|
| 41 | public object Tag {
|
---|
| 42 | get { return tag; }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[8280] | 45 | [Browsable(false)]
|
---|
| 46 | public bool IsEmpty {
|
---|
| 47 | get { return Equals(Empty); }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[15097] | 50 | public Point2D(T x, T y, object tag = null) {
|
---|
[8280] | 51 | this.x = x;
|
---|
| 52 | this.y = y;
|
---|
[15097] | 53 | this.tag = tag;
|
---|
[8280] | 54 | }
|
---|
| 55 |
|
---|
[15220] | 56 | public static Point2D<T> Create(T x, T y, object tag = null) {
|
---|
| 57 | return new Point2D<T>(x, y, tag);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[8280] | 60 | public static bool operator ==(Point2D<T> left, Point2D<T> right) {
|
---|
[15097] | 61 | return left.x.Equals(right.x) && left.y.Equals(right.y) && left.tag == right.tag;
|
---|
[8280] | 62 | }
|
---|
| 63 | public static bool operator !=(Point2D<T> left, Point2D<T> right) {
|
---|
| 64 | return !(left == right);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public override bool Equals(object obj) {
|
---|
| 68 | if (!(obj is Point2D<T>))
|
---|
| 69 | return false;
|
---|
| 70 | Point2D<T> point = (Point2D<T>)obj;
|
---|
[15097] | 71 | return GetType() == point.GetType() && x.Equals(point.x) && y.Equals(point.y) &&
|
---|
| 72 | ((tag != null && tag.Equals(point.tag)) || tag == point.tag);
|
---|
[8280] | 73 | }
|
---|
| 74 | public override int GetHashCode() {
|
---|
| 75 | return base.GetHashCode();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public override string ToString() {
|
---|
| 79 | return string.Format((IFormatProvider)CultureInfo.CurrentCulture, "{{X={0}, Y={1}}}", new object[2] { x, y });
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|