cocos2d-x版本:2.2.1
/** Returns point multiplied to a length of 1.
* If the point is 0, it returns (1, 0)
@return CCPoint
@since v2.1.4
*/
inline CCPoint normalize() const {
float length = getLength();
if(length == 0.) return CCPoint(1.f, 0);
return *this / getLength(); // 【标记1】
};
【标记1】处,getLength()重复调用了,直接用length不就好了么?