Re: [Bug] rs_actiondrawellipsecenter3point
Posted by
dxli on
Jun 16, 2013; 1:33am
URL: https://forum.librecad.org/Bug-rs-actiondrawellipsecenter3point-tp5708194p5708360.html
actually, squared() is a misnomer here. It should be called squaredLength() or lengthSquared():
for a 2D vector, RS_Vector( x, y);
double RS_Vector::squared() const {
return x*x + y*y;
}
we use squared length instead of length when we only need to compare length, so, we skip the extra sqrt() here.
On Sat, Jun 15, 2013 at 4:34 PM, cantcode [via LibreCAD]
<[hidden email]> wrote:
can someone pleasse tell me why we have to square the vector??
"if( (sol.get(mSize) - sol.get(mSize-1)).squared() < RS_TOLERANCE15 ) {..."
so we take the last two vectors and subtract them to get a new vector.
why do we then use .squared afterwards?
Isn't the RS_TOLERANCE15 the length which tells us if we should consider the next point as a new one?
If so, then one would have to calculate the length of the new vector (coming from the subtraction).
IIRC, the length of a vector is calculated by squaring the x,y,z components, adding them and then square root the result.
--
Dongxu Li, Ph.D.
www.librecad.org