-require 'mathn'- in my plugin causes FredoTools Round Corner plugin to break

So in the plugin i’m making, i found that it breaks another plugin i’ve had for a while. however i don’t understand why. i have my tool wrapped two modules deep and require it from there. what might i be missing?

module UniqueOuterModule
  module UniqueInnerModule
    require 'mathn'

    class ToolClass
    end

  end
end

So when i comment out the require ‘mathn’ then the other plugin works.

(1) Just because you require some file from within a scope, does not mean it is evaluated in that scope. The eval method is a global method defined in the Kernel mixin module, which is mixed into Object.
It always evaluates files (by default) in the TOPLEVEL_BINDING (which is “the particular instance of Object called main.”)

(2) Many of the standard library files, actually modify base Ruby classes. FredoTools was written way back when SketchUp was not distro’d with the Full Ruby Standard library. So he may not have anticipated this behavior.
See [url]http://ruby-doc.org/stdlib-2.0.0/libdoc/mathn/rdoc/index.html[/url]
and you’ll see only 2 methods are added to the Math mixin module. The others modify Ruby base classes.

(3) For some reason I am thinking that perhaps Mathn has been deprecated ?

(4) What is it you need Mathn for specifically ? So we can come up with a workaround.

(5) What is the error if any that it causes with FredoTools ?

mathn changes the way division works in Ruby. It makes it so all Integer divisions return a Rational instead of an Integer when mathn is required. It’s madness.

mathn has been deprecated for about a year. Don’t use it, you don’t need it.

1 Like

OK removed it and it all works. Thanks

I thought i needed to require it to access module Math:: to use PI and acos() and other trigonometric functions.
so i required it but turns out i didn’t even need it. the functions work without it.

the error i was getting was when going to chamfer a corner was:

An error was found when processing geometry. corner at fault is highlighted in the model.

The various Math functions are all available to you automatically.
No ‘require’ is needed for those.

Correct. The Math mixin module is part of the Ruby Core.

Inside your plugin module you can do
include Math
and it will add proxy lookups to all the Math functions, as if they were locally defined. (Ie, you would no longer need to qualify their calls with the Math module name.)