Hi,
in my little Project OPAL (Ordinary PAth Library, www.kudling.de/opal/) i have
a small problem.
I have a class “Rect”, which is defined by two “Point” members “tl” and “tr”,
which itself have the members “x” and “y” each.
Sind “Rect” acts as a bounding box for geometric figures, i want to implement
a function to Rect, which “adds” a new Point to the bounding box in such a
way, that the bounding box is enlarged if necessary:
class Rect
def +( z )
if z.kind_of? Point
@tl.x = z.x if z.x < @tl.x
@tl.y = z.y if z.y > @tl.y
@br.x = z.x if z.x > @br.x
@br.y = z.y if z.y < @br.y
self
else
# TODO: rect + rect
end
end
end
Now i wonder whether it is better to create new Point members instead of
adjusting the current member, since when i clone a Rect, the Rect instances
affect each other. Or is an proper own clone()/copy() funtion preferable?
Thanks
Lenny