#region LGPL License
/*************************************************************************
Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)
C# Port developed by Chris McGuirk (leedgitar@latenitegames.com)
Compatible with the Axiom 3D Engine (http://axiomengine.sf.net)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*************************************************************************/
#endregion LGPL License
#region Using directives
using System;
using System.Text;
#endregion
namespace CrayzEdsGui.Base{
public struct Point {
public float x, y;
public Point(float x, float y) {
this.x = x;
this.y = y;
}
/// <summary>
/// Add 2 Point structs.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static Point operator + (Point left, Point right) {
return new Point(left.x + right.x, left.y + right.y);
}
/// <summary>
/// Subtract one Point from another.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static Point operator - (Point left, Point right) {
return new Point(left.x - right.x, left.y - right.y);
}
/// <summary>
/// Check if 2 Point structs are equal.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator == (Point left, Point right) {
return (left.x == right.x) && (left.y == right.y);
}
/// <summary>
/// Check if 2 Point structs are not equal.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator != (Point left, Point right) {
return (left.x != right.x) || (left.y != right.y);
}
/// <summary>
/// Returns a string representation of the Point.
/// </summary>
/// <returns>The string representation of the point.</returns>
public override string ToString()
{
return string.Format( "x:{0} y:{1}", x, y );
}
/// <summary>
/// Parses a string representation of a Point, and returns the Point.
/// </summary>
/// <param name="data">String representation of a point.</param>
/// <returns>Point</returns>
public static Point Parse( string data )
{
string[] parameters = data.Split( new char[] { ' ', ':' } );
Point point = new Point();
for( int i = 0; i < parameters.Length; i++ )
{
if( 0 == parameters[i].CompareTo( "x" ) )
{
point.x = float.Parse( parameters[++i] );
}
else if( 0 == parameters[i].CompareTo( "y" ) )
{
point.y = float.Parse( parameters[++i] );
}
}
return point;
}
}
}
|