StanfordCPPLib GPoint Class Reference

This class contains real-valued x and y fields. More...

`#include "gtypes.h"`

Public Member Functions

GPoint(double x=0, double y=0)
Creates a `GPoint` object with the specified `x` and `y` coordinates. More...

GPoint(const Point &point)
Creates a `GPoint` object with the same `x` and `y` coordinates as the given point. More...

double getX() const
Returns the x component of the point. More...

double getY() const
Returns the y component of the point. More...

string toString() const
Converts the `GPoint` to a string in the form `"(</code><i>x</i><code>,</code>&nbsp;<i>y</i><code>)"`. More...

Detailed Description

This class contains real-valued x and y fields.

It is used to represent a location on the graphics plane.

◆ GPoint() [1/2]

 GPoint ( double x = `0`, double y = `0` )

Creates a `GPoint` object with the specified `x` and `y` coordinates.

If the coordinates are not supplied, the default constructor sets these fields to 0.

◆ GPoint() [2/2]

 GPoint ( const Point & point )

Creates a `GPoint` object with the same `x` and `y` coordinates as the given point.

◆ getX()

 double getX ( ) const

Returns the x component of the point.

◆ getY()

 double getY ( ) const

Returns the y component of the point.

◆ toString()

 string toString ( ) const

Converts the `GPoint` to a string in the form `"(</code><i>x</i><code>,</code>&nbsp;<i>y</i><code>)"`.

◆ hashCode

 int hashCode ( const GPoint & pt )
friend

Hashing function for GPoint objects.

◆ operator!=

 bool operator!= ( const GPoint & p1, const GPoint & p2 )
friend

Compares two GPoint objects for inequality.

◆ operator*

 GPoint operator* ( const GPoint & p, double scale )
friend

Multiplies the x and y coordinates of the given point by the given scale factor and returns the scaled point.

◆ operator<

 bool operator< ( const GPoint & p1, const GPoint & p2 )
friend

Relational operators that compare points by x-coordinate and then by y-coordinate.

◆ operator<<

 std::ostream& operator<< ( std::ostream & out, const GPoint & p )
friend

Writes the given point to the given output stream.

◆ operator<=

 bool operator<= ( const GPoint & p1, const GPoint & p2 )
friend

Relational operators that compare points by x-coordinate and then by y-coordinate.

◆ operator==

 bool operator== ( const GPoint & p1, const GPoint & p2 )
friend

Compares two GPoint objects for equality.

◆ operator>

 bool operator> ( const GPoint & p1, const GPoint & p2 )
friend

Relational operators that compare points by x-coordinate and then by y-coordinate.

◆ operator>=

 bool operator>= ( const GPoint & p1, const GPoint & p2 )
friend

Relational operators that compare points by x-coordinate and then by y-coordinate.