cocos2d-x  3.0rc1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Point Class Reference

#include <CCGeometry.h>

Public Member Functions

 Point ()
 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
Pointoperator+= (const Point &right)
Point operator- (const Point &right) const
Pointoperator-= (const Point &right)
Point operator- () const
bool operator== (const Point &right)
bool operator!= (const Point &right)
bool operator== (const Point &right) const
bool operator!= (const Point &right) const
Point operator* (float a) const
Point operator/ (float a) const
void setPoint (float x, float y)
bool equals (const Point &target) const
local equals ( local target)
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...
 

Public Attributes

float x
var x
local x
float y
var y
local y

Static Public Attributes

static const Point ZERO
 equals to Point(0,0) More...
 
static const Point ANCHOR_MIDDLE
 equals to Point(0.5, 0.5) More...
 
var ANCHOR_MIDDLE
 equals to Point(0.5, 0.5) More...
 
local ANCHOR_MIDDLE
 equals to Point(0.5, 0.5) More...
 
static const Point ANCHOR_BOTTOM_LEFT
 equals to Point(0, 0) More...
 
static const Point ANCHOR_TOP_LEFT
 equals to Point(0, 1) More...
 
var ANCHOR_TOP_LEFT
 equals to Point(0, 1) More...
 
local ANCHOR_TOP_LEFT
 equals to Point(0, 1) More...
 
static const Point ANCHOR_BOTTOM_RIGHT
 equals to Point(1, 0) More...
 
static const Point ANCHOR_TOP_RIGHT
 equals to Point(1, 1) More...
 
var ANCHOR_TOP_RIGHT
 equals to Point(1, 1) More...
 
local ANCHOR_TOP_RIGHT
 equals to Point(1, 1) More...
 
static const Point ANCHOR_MIDDLE_RIGHT
 equals to Point(1, 0.5) More...
 
var ANCHOR_MIDDLE_RIGHT
 equals to Point(1, 0.5) More...
 
local ANCHOR_MIDDLE_RIGHT
 equals to Point(1, 0.5) More...
 
static const Point ANCHOR_MIDDLE_LEFT
 equals to Point(0, 0.5) More...
 
var ANCHOR_MIDDLE_LEFT
 equals to Point(0, 0.5) More...
 
local ANCHOR_MIDDLE_LEFT
 equals to Point(0, 0.5) More...
 
static const Point ANCHOR_MIDDLE_TOP
 equals to Point(0.5, 1) More...
 
var ANCHOR_MIDDLE_TOP
 equals to Point(0.5, 1) More...
 
local ANCHOR_MIDDLE_TOP
 equals to Point(0.5, 1) More...
 
static const Point ANCHOR_MIDDLE_BOTTOM
 equals to Point(0.5, 0) More...
 
var ANCHOR_MIDDLE_BOTTOM
 equals to Point(0.5, 0) More...
 
local ANCHOR_MIDDLE_BOTTOM
 equals to Point(0.5, 0) More...
 

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
Athe startpoint for the first line L1 = (A - B)
Bthe endpoint for the first line L1 = (A - B)
Cthe startpoint for the second line L2 = (C - D)
Dthe endpoint for the second line L2 = (C - D)
Sthe range for a hitpoint in L1 (p = A + S*(B - A))
Tthe 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
bool operator!= ( const Point right)
bool operator!= ( const Point right) const
Point operator* ( float  a) const
Point operator+ ( const Point right) const
Point& operator+= ( const Point right)
Point operator- ( const Point right) const
Point operator- ( ) const
Point& operator-= ( const Point right)
Point operator/ ( float  a) const
Point& operator= ( const Point other)
Point& operator= ( const Size size)
bool operator== ( const Point right)
bool operator== ( const Point right) const
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
pivotis the pivot, naturally
angleis 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

const Point ANCHOR_BOTTOM_LEFT
static

equals to Point(0, 0)

var ANCHOR_BOTTOM_LEFT
static

equals to Point(0, 0)

local ANCHOR_BOTTOM_LEFT
static

equals to Point(0, 0)

const Point ANCHOR_BOTTOM_RIGHT
static

equals to Point(1, 0)

var ANCHOR_BOTTOM_RIGHT
static

equals to Point(1, 0)

local ANCHOR_BOTTOM_RIGHT
static

equals to Point(1, 0)

const Point ANCHOR_MIDDLE
static

equals to Point(0.5, 0.5)

var ANCHOR_MIDDLE
static

equals to Point(0.5, 0.5)

local ANCHOR_MIDDLE
static

equals to Point(0.5, 0.5)

const Point ANCHOR_MIDDLE_BOTTOM
static

equals to Point(0.5, 0)

var ANCHOR_MIDDLE_BOTTOM
static

equals to Point(0.5, 0)

local ANCHOR_MIDDLE_BOTTOM
static

equals to Point(0.5, 0)

const Point ANCHOR_MIDDLE_LEFT
static

equals to Point(0, 0.5)

var ANCHOR_MIDDLE_LEFT
static

equals to Point(0, 0.5)

local ANCHOR_MIDDLE_LEFT
static

equals to Point(0, 0.5)

const Point ANCHOR_MIDDLE_RIGHT
static

equals to Point(1, 0.5)

var ANCHOR_MIDDLE_RIGHT
static

equals to Point(1, 0.5)

local ANCHOR_MIDDLE_RIGHT
static

equals to Point(1, 0.5)

const Point ANCHOR_MIDDLE_TOP
static

equals to Point(0.5, 1)

var ANCHOR_MIDDLE_TOP
static

equals to Point(0.5, 1)

local ANCHOR_MIDDLE_TOP
static

equals to Point(0.5, 1)

const Point ANCHOR_TOP_LEFT
static

equals to Point(0, 1)

var ANCHOR_TOP_LEFT
static

equals to Point(0, 1)

local ANCHOR_TOP_LEFT
static

equals to Point(0, 1)

const Point ANCHOR_TOP_RIGHT
static

equals to Point(1, 1)

var ANCHOR_TOP_RIGHT
static

equals to Point(1, 1)

local ANCHOR_TOP_RIGHT
static

equals to Point(1, 1)

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

equals to Point(0,0)

var ZERO
static

equals to Point(0,0)

local ZERO
static

equals to Point(0,0)


The documentation for this class was generated from the following file: