Vector compare ?

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
User avatar
srl
Full Member
Posts: 65
Joined: Tue Aug 09, 2011 4:40 am

Vector compare ?

Post by srl » Fri May 20, 2016 12:43 am

Hi Andrew I can't get this vector compare to return true.
Screenshot from 2016-05-20 09-01-18.png
Screenshot from 2016-05-20 09-01-18.png (291.8 KiB) Viewed 6648 times
srl

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

Re: Vector compare ?

Post by andrew » Fri May 20, 2016 9:05 am

To compare two vectors, use:
vector1.equalsFuzzy(vector2)
To compare two doubles (real or floating point numeric values):
RMath.fuzzyCompare(value1, value2)
The == operator should never be used when dealing with floating point values since floating point arithmetic is not always 100% accurate:
0.1+0.2==0.3
false
With vectors and other objects, == does not work even if two vector are exactly identical since == compares the objects for identity, not the values inside:
var a = new RVector(0,0);
var b = new RVector(0,0);
a==b
false
a==a
true

User avatar
srl
Full Member
Posts: 65
Joined: Tue Aug 09, 2011 4:40 am

Re: Vector compare ?

Post by srl » Fri May 20, 2016 12:02 pm

Thanks Andrew.

As you can see I'm been on the LinuxCNC simulator. P2 makes the full arc circle work with offset.
Still more testing to be done.

srl

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”