Comparison of objects of class Form
Last updated at 2:39 pm UTC on 3 October 2020
This page is about how to compare two objects of class Form, to find out if they are equal or not.
Let us take the example given on the page about Form objects.
Definition of a first Form object
f := Form extent: 5@5 depth: 32.
"f extent 5@5"
"f width 5"
f colorAt: 0@0 put: Color red.
f colorAt: 0@4 put: Color green.
f colorAt: 4@4 put: Color blue.
f colorAt: 4@0 put: Color yellow.
Definition of a second Form object
f2 := Form extent: 5@5 depth: 32.
f2 colorAt: 0@0 put: Color red.
f2 colorAt: 0@4 put: Color green.
f2 colorAt: 4@4 put: Color blue.
f2 colorAt: 4@0 put: Color yellow.
If the compare the two object we get as result 'false', though this should not be so.
f = f2 false
However if we compare
f bits = f2 bits
and
f extent = f2 extent
we get in both cases true
as the answer.
To conclude
We need to do the comparison in the following way to get the correct result
(f bits = f2 bits) and: [f extent = f2 extent]