// Copyright (C) 1996 DIMACS Center, Rutgers, The State University of New Jersey
// Author(s): ??

// This software is copyrighted by the DIMACS Center at Rutgers, The State
// University of New Jersey.  IT IS PROVIDED AS IS, AND THE AUTHORS, DIMACS, AND
// RUTGERS, THE STATE UNIVERSITY OF NEW JERSEY  DISCLAIM
// ALL LIABILITY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
// DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

// THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
// IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
// NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
// MODIFICATIONS.

// The authors hereby grant permission to use, copy, modify, distribute,
// and license this software and its documentation for any purpose, provided
// that existing copyright notices are retained in all copies and that this
// notice is included verbatim in any distributions. No written agreement,
// license, or royalty fee is required for any of the authorized uses.
// Modifications to this software may be copyrighted by their authors
// and need not follow the licensing terms described here, provided that
// the new terms are clearly indicated on the first page of each file where
// they apply.

// Last File Update: 31-Jul-1996
// 

#ifndef Location_h
#define Location_h

#include <fstream.h>
#include <math.h>
#include <LINK/basic/general.h>


class Location {
public:
    Location()				{ x = 0.0; y = 0.0; }
    Location(float x_val, float y_val)	{ x = x_val; y = y_val; }

		// get and set individual coordinates
    float	xValue() const		{ return x; }
    float	xValue(float x_val)	{ return x = x_val; }
    float	yValue() const		{ return y; }
    float	yValue(float y_val)	{ return y = y_val; }

		// addition, subtraction and negation of Location
    Location	operator=(const Location& l)
				{ x = l.x; y = l.y; return *this; }
    Location	operator+(const Location& l) const
				{ return Location(x+l.x, y+l.y); }
    Location	operator-() const
				{ return Location(-x,-y); }
    Location	operator-(const Location& l) const
				{ return Location(x-l.x, y-l.y); }

		// scaling of points
    friend Location operator*(const Location& l, float f);
    friend Location operator*(float f, const Location& l);

		// comparison operators
    Bool	operator==(const Location& l) const
				{ return (x == l.x && y == l.y); }
    Bool	operator!=(const Location& l) const
				{ return (x != l.x || y != l.y); }
    Bool	operator<(const Location& l) const
				{ return (y < l.y && x < l.x); }
    Bool	operator<=(const Location& l) const
				{ return (y <= l.y && x <= l.x); }
    Bool	operator>(const Location& l) const
				{ return (y > l.y && x > l.x); }
    Bool	operator>=(const Location& l) const
				{ return (y >= l.y && x >= l.x); }

		// translation and scaling of Location
    void	operator+=(const Location& l)	{ x += l.x; y += l.y; }
    void	operator-=(const Location& l)	{ x -= l.x; y -= l.y; }
    void	operator*=(int s)		{ x *= s; y *= s; }

		// other functions
    double	distance(const Location& l) const
				{ return hypot(x-l.x, y-l.y); }
    Location	transpose() const		{ return Location(y,x); }
    Location	max(const Location& l) const;
    Location	min(const Location& l) const;
    Bool	withinEpsilon(const Location& l, float eps) const;

    friend ostream& operator<<(ostream& stream, Location l);

    float	x;
    float	y;
};

Location operator*(const Location& l, float i);
Location operator*(float i, const Location& l);


#endif
