[fxruby-users] FXVec* default constructors
David MacMahon
davidm at astro.berkeley.edu
Mon Jan 26 02:17:12 EST 2009
I just noticed that the default constructors for FXVec* do not
initialize their elements. This also affects anything that uses
FXVec* default constructors under the covers such as the FXExtent*
default constructors.
It would be nice if the docs were explicit on this "point". :-)
Perhaps this is the expected behavior in C++ given the various ways
that the C++ default constructor can be invoked, but in Ruby I was
expecting the no-argument constructor to initialize the instance to
[0.0, 0.0]...
$ cat defctor.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'fox16'
include Fox
500.times do |i|
v = FXVec2d.new
next if v[0] == 0.0 && v[1] == 0.0
p [i, v]
break
end
puts 'done'
$ ruby defctor.rb
[222, [6.76425275721251e-320, 4.70741886267958e-284]]
$ fox-config --version
1.6.34
$ gem list -l fxruby | grep fxruby
fxruby (1.6.18)
Sorry if this is old news,
Dave
P.S. Ruby users can get an "always initialized" default constructor
by using this "monkey patch"...
class Fox::FXVec2d
alias :fox_initialize :initialize
def initialize(*args)
args = [0.0, 0.0] if args.empty?
fox_initialize(*args)
end
end
More information about the fxruby-users
mailing list