[pgsqlclient-checkins] SF.net SVN: pgsqlclient: [169] trunk/PostgreSqlClient/source/PostgreSql/Data/
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-05-31 19:44:50
|
Revision: 169 Author: carlosga_fb Date: 2006-05-31 12:03:49 -0700 (Wed, 31 May 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=169&view=rev Log Message: ----------- 2006-05-31 Carlos Guzman Alvarez (car...@gm...) - Committed initial support for fetching PostGIS Box3D values. Modified Paths: -------------- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs Added Paths: ----------- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox3D.cs trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint3D.cs Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs 2006-05-31 18:36:50 UTC (rev 168) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs 2006-05-31 19:03:49 UTC (rev 169) @@ -1,3 +1,20 @@ +/* + * PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ + * + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. + * + * Software distributed under the License is distributed on + * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * Copyright (c) 2006 Carlos Guzman Alvarez + * All Rights Reserved. + */ + using System; using PostgreSql.Data.Protocol; Added: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox3D.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox3D.cs (rev 0) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox3D.cs 2006-05-31 19:03:49 UTC (rev 169) @@ -0,0 +1,129 @@ +/* + * PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ + * + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. + * + * Software distributed under the License is distributed on + * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * Copyright (c) 2003, 2006 Carlos Guzman Alvarez + * All Rights Reserved. + */ + +using System; +using PostgreSql.Data.Protocol; + +namespace PostgreSql.Data.PgTypes +{ + [Serializable] + public struct PgBox3D + { + #region \xB7 Fields \xB7 + + private PgPoint3D upperRight; + private PgPoint3D lowerLeft; + + #endregion + + #region \xB7 Properties \xB7 + + public PgPoint3D UpperRight + { + get { return this.upperRight; } + } + + public PgPoint3D LowerLeft + { + get { return this.lowerLeft; } + } + + #endregion + + #region \xB7 Constructors \xB7 + + public PgBox3D(PgPoint3D lowerLeft, PgPoint3D upperRight) + { + this.lowerLeft = lowerLeft; + this.upperRight = upperRight; + } + + public PgBox3D(double x1, double y1, double z1, double x2, double y2, double z2) + { + this.lowerLeft = new PgPoint3D(x1, y1, z1); + this.upperRight = new PgPoint3D(x2, y2, z2); + } + + #endregion + + #region \xB7 Operators \xB7 + + public static bool operator ==(PgBox3D left, PgBox3D right) + { + return (left.UpperRight == right.UpperRight && left.LowerLeft == right.LowerLeft); + } + + public static bool operator !=(PgBox3D left, PgBox3D right) + { + return (left.UpperRight != right.UpperRight || left.LowerLeft != right.LowerLeft); + } + + #endregion + + #region \xB7 Overriden Methods \xB7 + + public override string ToString() + { + return String.Format("BOX3D({0},{1})", this.lowerLeft.ToString(), this.upperRight.ToString()); + } + + public override int GetHashCode() + { + return (this.UpperRight.GetHashCode() ^ this.LowerLeft.GetHashCode()); + } + + public override bool Equals(object obj) + { + if (obj is PgBox3D) + { + return ((PgBox3D)obj) == this; + } + else + { + return false; + } + } + + #endregion + + #region \xB7 Static Methods \xB7 + + public static PgBox3D Parse(string s) + { + if (s == null) + { + throw new ArgumentNullException("s cannot be null"); + } + + if (s.IndexOf("(") > 0) + { + s = s.Substring(s.IndexOf("(") + 1, s.IndexOf(")") - s.IndexOf("(") - 1); + } + + string[] delimiters = new string[] { PgDatabase.DataTypes["box3d"].Delimiter }; + + string[] boxPoints = s.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); + + PgPoint3D left = PgPoint3D.Parse(boxPoints[0]); + PgPoint3D right = PgPoint3D.Parse(boxPoints[1]); + + return new PgBox3D(left, right); + } + + #endregion + } +} Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs 2006-05-31 18:36:50 UTC (rev 168) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs 2006-05-31 19:03:49 UTC (rev 169) @@ -59,26 +59,12 @@ public static bool operator ==(PgPoint left, PgPoint right) { - if (left.X == right.X && left.Y == right.Y) - { - return true; - } - else - { - return true; - } + return (left.X == right.X && left.Y == right.Y); } public static bool operator !=(PgPoint left, PgPoint right) { - if (left.X != right.X || left.Y != right.Y) - { - return true; - } - else - { - return true; - } + return (left.X != right.X || left.Y != right.Y); } #endregion Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs 2006-05-31 18:36:50 UTC (rev 168) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs 2006-05-31 19:03:49 UTC (rev 169) @@ -11,7 +11,7 @@ * express or implied. See the License for the specific * language governing rights and limitations under the License. * - * Copyright (c) 2003, 2006 Carlos Guzman Alvarez + * Copyright (c) 2006 Carlos Guzman Alvarez * All Rights Reserved. */ @@ -35,12 +35,12 @@ public double X { - get { return x; } + get { return this.x; } } public double Y { - get { return y; } + get { return this.y; } } #endregion @@ -59,26 +59,12 @@ public static bool operator ==(PgPoint2D left, PgPoint2D right) { - if (left.X == right.X && left.Y == right.Y) - { - return true; - } - else - { - return true; - } + return (left.X == right.X && left.Y == right.Y); } public static bool operator !=(PgPoint2D left, PgPoint2D right) { - if (left.X != right.X || left.Y != right.Y) - { - return true; - } - else - { - return true; - } + return (left.X != right.X || left.Y != right.Y); } #endregion Added: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint3D.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint3D.cs (rev 0) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint3D.cs 2006-05-31 19:03:49 UTC (rev 169) @@ -0,0 +1,137 @@ +/* + * PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ + * + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. + * + * Software distributed under the License is distributed on + * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * Copyright (c) 2006 Carlos Guzman Alvarez + * All Rights Reserved. + */ + +using System; +using System.Globalization; +using PostgreSql.Data.Protocol; + +namespace PostgreSql.Data.PgTypes +{ + [Serializable] + public struct PgPoint3D + { + #region \xB7 Fields \xB7 + + private double x; + private double y; + private double z; + + #endregion + + #region \xB7 Properties \xB7 + + public double X + { + get { return this.x; } + } + + public double Y + { + get { return this.y; } + } + + public double Z + { + get { return this.z; } + } + + #endregion + + #region \xB7 Constructors \xB7 + + public PgPoint3D(double x, double y, double z) + { + this.x = x; + this.y = y; + this.z = z; + } + + #endregion + + #region \xB7 Operators \xB7 + + public static bool operator ==(PgPoint3D left, PgPoint3D right) + { + return (left.X == right.X && left.Y == right.Y && left.Z == right.Z); + } + + public static bool operator !=(PgPoint3D left, PgPoint3D right) + { + return (left.X != right.X || left.Y != right.Y || left.Z != right.Z); + } + + #endregion + + #region \xB7 Overriden Methods \xB7 + + public override string ToString() + { + CultureInfo culture = CultureInfo.InvariantCulture; + + return String.Format(culture, "{0} {1} {2}", this.x, this.y, this.z); + } + + public override int GetHashCode() + { + return (this.x.GetHashCode() ^ this.y.GetHashCode() ^ this.z.GetHashCode()); + } + + public override bool Equals(object obj) + { + if (obj != null && obj is PgPoint3D) + { + return ((PgPoint3D)obj) == this; + } + else + { + return false; + } + } + + #endregion + + #region \xB7 Static Methods \xB7 + + public static PgPoint3D Parse(string s) + { + if (s == null) + { + throw new ArgumentNullException("s cannot be null"); + } + + if (s.IndexOf("(") > 0) + { + s = s.Substring(s.IndexOf("("), s.Length - s.IndexOf("(")); + } + + string[] pointCoords = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + if (pointCoords == null || pointCoords.Length != 3) + { + throw new ArgumentException("s is not a valid point."); + } + + double x = Double.Parse(pointCoords[0], System.Globalization.CultureInfo.InvariantCulture); + double y = Double.Parse(pointCoords[1], System.Globalization.CultureInfo.InvariantCulture); + double z = Double.Parse(pointCoords[2], System.Globalization.CultureInfo.InvariantCulture); + + return new PgPoint3D(x, y, z); + } + + #endregion + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |