CoordinateStruct.cs :  » GIS » DeepEarth » GisSharpBlog » NetTopologySuite » Geometries » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » DeepEarth 
DeepEarth » GisSharpBlog » NetTopologySuite » Geometries » CoordinateStruct.cs
using System;
using GeoAPI.Geometries;

namespace GisSharpBlog.NetTopologySuite.Geometries{
#if !SILVERLIGHT
    [Serializable]
#endif
  public struct CoordinateStruct : ICoordinate 
    {
        private double x;
        private double y;
        private double z;

        public CoordinateStruct(double x, double y, double z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public CoordinateStruct(double x, double y) : this(x, y, Double.NaN) { }

        public CoordinateStruct(ICoordinate c) : this(c.X, c.Y, c.Z) { }

        public double X
        {
            get { return x;  }
            set { x = value; }
        }

        public double Y
        {
            get { return y;  }
            set { y = value; }
        }

        public double Z
        {
            get { return z;  }
            set { z = value; }
        }

        public ICoordinate CoordinateValue
        {
            get { return this; }
            set
            {
                x = value.X;
                y = value.Y;
                z = value.Z;
            }
        }        

        public double Distance(ICoordinate p)
        {
            double dx = x - p.X;
            double dy = y - p.Y;
            return Math.Sqrt(dx * dx + dy * dy);
        }

        public bool Equals2D(ICoordinate other)
        {
            return (x == other.X) && (y == other.Y);
        }

        public bool Equals3D(ICoordinate other)
        {
            return (x == other.X) && (y == other.Y) && 
                ((z == other.Z) || (Double.IsNaN(Z) && Double.IsNaN(other.Z)));
        }       
        
        public object Clone()
        {
            return new CoordinateStruct(this.X, this.Y, this.Z);
        }
        
        public int CompareTo(object obj)
        {
            ICoordinate other = (ICoordinate) obj;
            return CompareTo(other);
        }

        public int CompareTo(ICoordinate other)
        {
            if (x < other.X)
                return -1;
            if (x > other.X)
                return 1;
            if (y < other.Y)
                return -1;
            if (y > other.Y)
                return 1;
            return 0;
        }

        public bool Equals(ICoordinate other)
        {
            return Equals2D(other);
        }

        public override bool Equals(object other)
        {
            if (other == null)
                return false;
            if (!(other is CoordinateStruct))
                return false;
            return Equals((CoordinateStruct) other);
        }

        public static bool operator ==(CoordinateStruct obj1, CoordinateStruct obj2)
        {
            return Equals(obj1, obj2);
        }

        public static bool operator !=(CoordinateStruct obj1, CoordinateStruct obj2)
        {
            return !(obj1 == obj2);
        }  

        public override string ToString()
        {
            return "(" + x + ", " + y + ", " + z + ")";
        }

        public override int GetHashCode()
        {
            int result = 17;
            result = 37 * result + GetHashCode(X);
            result = 37 * result + GetHashCode(Y);
            return result;
        }

        private static int GetHashCode(double value)
        {
#if !SILVERLIGHT
            long f = BitConverter.DoubleToInt64Bits(value);
#else
      long f = GisSharpBlog.NetTopologySuite.Utilities.BitConverter.DoubleToInt64Bits(value);
#endif
            return (int)(f ^ (f >> 32));
        }
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.