using System; using GeoAPI.Geometries; namespace GisSharpBlog.NetTopologySuite.Noding { /// /// Octants in the Cartesian plane. /// Octants are numbered as follows: /// /// \2|1/ /// 3 \|/ 0 /// ---+-- /// 4 /|\ 7 /// /5|6\ /// /// If line segments lie along a coordinate axis, the octant is the lower of the two possible values. /// public enum Octants { /// /// /// Null = -1, /// /// /// Zero = 0, /// /// /// One = 1, /// /// /// Two = 2, /// /// /// Three = 3, /// /// /// Four = 4, /// /// /// Five = 5, /// /// /// Six = 6, /// /// /// Seven = 7, } /// /// Methods for computing and working with of the Cartesian plane. /// public static class Octant { /// /// Returns the octant of a directed line segment (specified as x and y /// displacements, which cannot both be 0). /// /// /// /// public static Octants GetOctant(double dx, double dy) { if (dx == 0.0 && dy == 0.0) { throw new ArgumentException("Cannot compute the octant for point ( " + dx + ", " + dy + " )"); } double adx = Math.Abs(dx); double ady = Math.Abs(dy); if (dx >= 0) { if (dy >= 0) { if (adx >= ady) { return Octants.Zero; } else { return Octants.One; } } else // dy < 0 { if (adx >= ady) { return Octants.Seven; } else { return Octants.Six; } } } else // dx < 0 { if (dy >= 0) { if (adx >= ady) { return Octants.Three; } else { return Octants.Two; } } else // dy < 0 { if (adx >= ady) { return Octants.Four; } else { return Octants.Five; } } } } /// /// Returns the octant of a directed line segment from p0 to p1. /// /// /// /// public static Octants GetOctant(ICoordinate p0, ICoordinate p1) { double dx = p1.X - p0.X; double dy = p1.Y - p0.Y; if (dx == 0.0 && dy == 0.0) { throw new ArgumentException("Cannot compute the octant for two identical points " + p0); } return GetOctant(dx, dy); } } }