cocos2d-x  3.0-alpha0
Point Class Reference

`#include <CCGeometry.h>`

## Public Member Functions

Point ()
Point (float x, float y)
Point ( local x, local y)
Point (const Point &other)
Point (const Size &size)
Pointoperator= (const Point &other)
Pointoperator= (const Size &size)
Point operator+ (const Point &right) const
Point operator- (const Point &right) const
Point operator- () const
Point operator* (float a) const
Point operator/ (float a) const
void setPoint (float x, float y)
bool equals (const Point &target) const
bool fuzzyEquals (const Point &target, float variance) const
float getLength () const
Calculates distance between point an origin. More...

float getLengthSq () const
Calculates the square length of a Point (not calling sqrt() ) More...

float getDistanceSq (const Point &other) const
Calculates the square distance between two points (not calling sqrt() ) More...

float getDistance (const Point &other) const
Calculates the distance between two points. More...

float getAngle () const
float getAngle (const Point &other) const
float dot (const Point &other) const
Calculates dot product of two points. More...

float cross (const Point &other) const
Calculates cross product of two points. More...

Point getPerp () const
Calculates perpendicular of v, rotated 90 degrees counter-clockwise – cross(v, perp(v)) >= 0. More...

Point getMidpoint (const Point &other) const
Calculates midpoint between two points. More...

Point getClampPoint (const Point &min_inclusive, const Point &max_inclusive) const
Clamp a point between from and to. More...

Point compOp (std::function< float(float)> function) const
Run a math operation function on each point component absf, fllorf, ceilf, roundf any function that has the signature: float func(float); For example: let's try to take the floor of x,y p.compOp(floorf);. More...

Point getRPerp () const
Calculates perpendicular of v, rotated 90 degrees clockwise – cross(v, rperp(v)) <= 0. More...

Point project (const Point &other) const
Calculates the projection of this over other. More...

Point rotate (const Point &other) const
Complex multiplication of two points ("rotates" two points). More...

Point unrotate (const Point &other) const
Unrotates two points. More...

Point normalize () const
Returns point multiplied to a length of 1. More...

Point lerp (const Point &other, float alpha) const
Linear Interpolation between two points a and b. More...

Point rotateByAngle (const Point &pivot, float angle) const
Rotates a point counter clockwise by the angle around a pivot. More...

## Static Public Member Functions

static Point forAngle (const float a)
static bool isLineIntersect (const Point &A, const Point &B, const Point &C, const Point &D, float *S=nullptr, float *T=nullptr)
A general line-line intersection test. More...

static bool isLineOverlap (const Point &A, const Point &B, const Point &C, const Point &D)
returns true if Line A-B overlap with segment C-D More...

static bool isLineParallel (const Point &A, const Point &B, const Point &C, const Point &D)
returns true if Line A-B parallel with segment C-D More...

static bool isSegmentOverlap (const Point &A, const Point &B, const Point &C, const Point &D, Point *S=nullptr, Point *E=nullptr)
returns true if Segment A-B overlap with segment C-D More...

static bool isSegmentIntersect (const Point &A, const Point &B, const Point &C, const Point &D)
returns true if Segment A-B intersects with segment C-D More...

static Point getIntersectPoint (const Point &A, const Point &B, const Point &C, const Point &D)
returns the intersection point of line A-B, C-D More...

float x
float y

## Static Public Attributes

static const Point ZERO

## Constructor & Destructor Documentation

 Point ( )
 local Point ( )
 Point ( float x, float y )
 local Point ( local x, local y )
 Point ( const Point & other)
 Point ( const Size & size)
explicit

## Member Function Documentation

 Point compOp ( std::function< float(float)> function) const
inline

Run a math operation function on each point component absf, fllorf, ceilf, roundf any function that has the signature: float func(float); For example: let's try to take the floor of x,y p.compOp(floorf);.

Since
v3.0
 float cross ( const Point & other) const
inline

Calculates cross product of two points.

Returns
float
Since
v2.1.4
 float dot ( const Point & other) const
inline

Calculates dot product of two points.

Returns
float
Since
v2.1.4
 bool equals ( const Point & target) const
 local equals ( local target)
 static Point forAngle ( const float a)
inlinestatic
 bool fuzzyEquals ( const Point & target, float variance ) const
Returns
if points have fuzzy equality which means equal with some degree of variance.
Since
v2.1.4
 float getAngle ( ) const
inline
Returns
the angle in radians between this vector and the x axis
Since
v2.1.4
 float getAngle ( const Point & other) const
Returns
the angle in radians between two vector directions
Since
v2.1.4
 Point getClampPoint ( const Point & min_inclusive, const Point & max_inclusive ) const
inline

Clamp a point between from and to.

Since
v3.0
 float getDistance ( const Point & other) const
inline

Calculates the distance between two points.

Returns
float
Since
v2.1.4
 float getDistanceSq ( const Point & other) const
inline

Calculates the square distance between two points (not calling sqrt() )

Returns
float
Since
v2.1.4
 static Point getIntersectPoint ( const Point & A, const Point & B, const Point & C, const Point & D )
static

returns the intersection point of line A-B, C-D

Since
v3.0
 float getLength ( ) const
inline

Calculates distance between point an origin.

Returns
float
Since
v2.1.4
 float getLengthSq ( ) const
inline

Calculates the square length of a Point (not calling sqrt() )

Returns
float
Since
v2.1.4
 Point getMidpoint ( const Point & other) const
inline

Calculates midpoint between two points.

Returns
Point
Since
v3.0
 Point getPerp ( ) const
inline

Calculates perpendicular of v, rotated 90 degrees counter-clockwise – cross(v, perp(v)) >= 0.

Returns
Point
Since
v2.1.4
 Point getRPerp ( ) const
inline

Calculates perpendicular of v, rotated 90 degrees clockwise – cross(v, rperp(v)) <= 0.

Returns
Point
Since
v2.1.4
 static bool isLineIntersect ( const Point & A, const Point & B, const Point & C, const Point & D, float * S = `nullptr`, float * T = `nullptr` )
static

A general line-line intersection test.

Parameters
 A the startpoint for the first line L1 = (A - B) B the endpoint for the first line L1 = (A - B) C the startpoint for the second line L2 = (C - D) D the endpoint for the second line L2 = (C - D) S the range for a hitpoint in L1 (p = A + S*(B - A)) T the range for a hitpoint in L2 (p = C + T*(D - C))
Returns
whether these two lines interects.

Note that to truly test intersection for segments we have to make sure that S & T lie within [0..1] and for rays, make sure S & T > 0 the hit point is C + T * (D - C); the hit point also is A + S * (B - A);

Since
3.0
 static bool isLineOverlap ( const Point & A, const Point & B, const Point & C, const Point & D )
static

returns true if Line A-B overlap with segment C-D

Since
v3.0
 static bool isLineParallel ( const Point & A, const Point & B, const Point & C, const Point & D )
static

returns true if Line A-B parallel with segment C-D

Since
v3.0
 static bool isSegmentIntersect ( const Point & A, const Point & B, const Point & C, const Point & D )
static

returns true if Segment A-B intersects with segment C-D

Since
v3.0
 static bool isSegmentOverlap ( const Point & A, const Point & B, const Point & C, const Point & D, Point * S = `nullptr`, Point * E = `nullptr` )
static

returns true if Segment A-B overlap with segment C-D

Since
v3.0
 Point lerp ( const Point & other, float alpha ) const
inline

Linear Interpolation between two points a and b.

Returns
alpha == 0 ? a alpha == 1 ? b otherwise a value between a..b
Since
v2.1.4
 Point normalize ( ) const
inline

Returns point multiplied to a length of 1.

If the point is 0, it returns (1, 0)

Returns
Point
Since
v2.1.4
 Point operator* ( float a) const
 Point operator+ ( const Point & right) const
 Point operator- ( const Point & right) const
 Point operator- ( ) const
 Point operator/ ( float a) const
 Point& operator= ( const Point & other)
 Point& operator= ( const Size & size)
 Point project ( const Point & other) const
inline

Calculates the projection of this over other.

Returns
Point
Since
v2.1.4
 Point rotate ( const Point & other) const
inline

Complex multiplication of two points ("rotates" two points).

Returns
Point vector with an angle of this.getAngle() + other.getAngle(), and a length of this.getLength() * other.getLength().
Since
v2.1.4
 Point rotateByAngle ( const Point & pivot, float angle ) const

Rotates a point counter clockwise by the angle around a pivot.

Parameters
 pivot is the pivot, naturally angle is the angle of rotation ccw in radians
Returns
the rotated point
Since
v2.1.4
 void setPoint ( float x, float y )
 Point unrotate ( const Point & other) const
inline

Unrotates two points.

Returns
Point vector with an angle of this.getAngle() - other.getAngle(), and a length of this.getLength() * other.getLength().
Since
v2.1.4

## Member Data Documentation

 float x
 var x
 local x
 float y
 var y
 local y
 const Point ZERO
static

The documentation for this class was generated from the following file:
• /Users/cocos2d/MyWork/cocos2d-x-develop/cocos2dx/cocoa/CCGeometry.h