Vector += vector

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
tukuyomi
Full Member
Posts: 50
Joined: Mon Aug 09, 2010 6:15 pm

Vector += vector

Post by tukuyomi » Thu Aug 25, 2016 1:11 pm

Hello ! I have a little question :

Code: Select all

var v = new RVector(1,2) , v1 = new RVector(4,8);
    qDebug("1>"+v)
    qDebug("2>"+v1)
v.operator+=(v1);
    qDebug("3>"+v)
What to expect, doing this? Here is what I get :

Code: Select all

Debug:    1>RVector(1, 2, 0, true) 
Debug:    2>RVector(4, 8, 0, true) 
Debug:    3>RVector(1, 2, 0, true) 
Is it possible to have

Code: Select all

Debug:    3>RVector(5, 10, 0, true) 
(add 2 vectors) ?
Thanks for your answers !

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Vector += vector

Post by andrew » Thu Aug 25, 2016 1:16 pm

ECMAScript does not support overloading of operators, so you'll have to use the workaround functions for operators:
var v3 = v1.operator_add(v2);
Similarly, there are operator_subtract, operator_multiply, operator_divide and getNegated(v) for -v.

tukuyomi
Full Member
Posts: 50
Joined: Mon Aug 09, 2010 6:15 pm

Re: Vector += vector

Post by tukuyomi » Thu Aug 25, 2016 1:29 pm

Thanks andrew :D Will try this asap :D Thank you !

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”