facets 1.3.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{doc/AUTHORS → AUTHORS} +12 -3
- data/README +35 -29
- data/WARNING +56 -0
- data/demo/annotation/demo_annotation.rb +22 -0
- data/demo/ansicolor/cdiff.rb +20 -0
- data/demo/ansicolor/example.rb +82 -0
- data/demo/io-reactor/chatserver.rb +347 -0
- data/demo/lisp/game.rb +47 -0
- data/lib/facet/all.rb +1 -0
- data/lib/facet/annattr.rb +1 -0
- data/lib/facet/class/to_proc.rb +1 -0
- data/lib/facet/cookie.rb +1 -0
- data/lib/facet/dir/self/descend.rb +1 -0
- data/lib/facet/enumerable/count.rb +1 -0
- data/lib/facet/hash/to_proc.rb +1 -0
- data/lib/facet/hashbuilder.rb +1 -0
- data/lib/facet/http.rb +1 -0
- data/lib/facet/httpaccess.rb +1 -0
- data/lib/facet/kernel/__get__.rb +1 -0
- data/lib/facet/kernel/__set__.rb +1 -0
- data/lib/facet/kernel/cache.rb +1 -0
- data/lib/facet/kernel/respond.rb +1 -0
- data/lib/facet/lazy.rb +1 -0
- data/lib/facet/module/class.rb +1 -0
- data/lib/facet/module/nodef.rb +1 -0
- data/lib/facet/opencascade.rb +1 -0
- data/lib/facet/pqueue.rb +1 -0
- data/lib/facet/taskable.rb +1 -0
- data/lib/facets.rb +98 -37
- data/lib/facets/core/all.rb +5 -0
- data/lib/facets/core/class/to_proc.rb +25 -0
- data/lib/facets/core/dir/self/ascend.rb +2 -1
- data/lib/facets/core/dir/self/descend.rb +11 -0
- data/lib/facets/core/enumerable/accumulate.rb +2 -2
- data/lib/facets/core/enumerable/count.rb +54 -0
- data/lib/facets/core/enumerable/cross.rb +3 -0
- data/lib/facets/core/enumerable/graph.rb +8 -4
- data/lib/facets/core/enumerable/self/cross.rb +11 -5
- data/lib/facets/core/hash/to_proc.rb +34 -0
- data/lib/facets/core/hash/traverse.rb +10 -5
- data/lib/facets/core/kernel/__class__.rb +1 -1
- data/lib/facets/core/kernel/__get__.rb +5 -0
- data/lib/facets/core/kernel/__set__.rb +2 -0
- data/lib/facets/core/kernel/assign_from.rb +1 -1
- data/lib/facets/core/kernel/assign_with.rb +11 -3
- data/lib/facets/core/kernel/bool.rb +1 -1
- data/lib/facets/core/kernel/cache.rb +31 -0
- data/lib/facets/core/kernel/demo.rb +4 -0
- data/lib/facets/core/kernel/get_by_id.rb +1 -0
- data/lib/facets/core/kernel/in.rb +1 -1
- data/lib/facets/core/kernel/instance_assign.rb +2 -3
- data/lib/facets/core/kernel/method.rb +25 -7
- data/lib/facets/core/kernel/methods.rb +1 -1
- data/lib/facets/core/kernel/new.rb +1 -1
- data/lib/facets/core/kernel/object_class.rb +1 -1
- data/lib/facets/core/kernel/object_hexid.rb +1 -1
- data/lib/facets/core/kernel/own.rb +1 -1
- data/lib/facets/core/kernel/require_all.rb +1 -0
- data/lib/facets/core/kernel/require_esc.rb +4 -2
- data/lib/facets/core/kernel/require_facet.rb +2 -0
- data/lib/facets/core/kernel/require_local.rb +1 -0
- data/lib/facets/core/kernel/respond.rb +14 -0
- data/lib/facets/core/kernel/send_as.rb +1 -1
- data/lib/facets/core/kernel/silence_warnings.rb +1 -1
- data/lib/facets/core/kernel/singleton.rb +3 -1
- data/lib/facets/core/matchdata/matchtree.rb +13 -3
- data/lib/facets/core/module/class.rb +3 -0
- data/lib/facets/core/module/integrate.rb +31 -4
- data/lib/facets/core/module/{undef.rb → nodef.rb} +8 -3
- data/lib/facets/core/module/revisal.rb +5 -5
- data/lib/facets/more/annattr.rb +147 -0
- data/lib/facets/more/annotation.rb +32 -136
- data/lib/facets/more/ansicode.rb +89 -100
- data/lib/facets/more/aspects.rb +28 -0
- data/lib/facets/more/association.rb +88 -47
- data/lib/facets/more/basicobject.rb +51 -33
- data/lib/facets/more/bbcode.rb +21 -34
- data/lib/facets/more/binaryreader.rb +62 -33
- data/lib/facets/more/bitmask.rb +24 -24
- data/lib/facets/more/blankslate.rb +4 -0
- data/lib/facets/more/builderobject.rb +16 -20
- data/lib/facets/more/bytes.rb +43 -24
- data/lib/facets/more/classinherit.rb +15 -31
- data/lib/facets/more/classmethods.rb +19 -29
- data/lib/facets/more/cloneable.rb +42 -30
- data/lib/facets/more/consoleapp.rb +42 -22
- data/lib/facets/more/cookie.rb +565 -0
- data/lib/facets/more/coroutine.rb +17 -21
- data/lib/facets/more/crypt.rb +33 -12
- data/lib/facets/more/dictionary.rb +27 -36
- data/lib/facets/more/downloader.rb +21 -17
- data/lib/facets/more/elementor.rb +22 -0
- data/lib/facets/more/enumerablepass.rb +19 -27
- data/lib/facets/more/expirable.rb +18 -28
- data/lib/facets/more/filelist.rb +33 -32
- data/lib/facets/more/floatstring.rb +31 -40
- data/lib/facets/more/functor.rb +15 -25
- data/lib/facets/more/hashbuilder.rb +76 -0
- data/lib/facets/more/heap.rb +29 -36
- data/lib/facets/more/htmlbuilder.rb +22 -24
- data/lib/facets/more/htmlhelper.rb +89 -0
- data/lib/facets/more/http.rb +570 -0
- data/lib/facets/more/httpaccess.rb +1608 -0
- data/lib/facets/more/inheritor.rb +29 -21
- data/lib/facets/more/interval.rb +21 -25
- data/lib/facets/more/ioredirect.rb +21 -25
- data/lib/facets/more/json.rb +27 -17
- data/lib/facets/more/lazy.rb +238 -0
- data/lib/facets/more/lisp.rb +24 -27
- data/lib/facets/more/lisp_format.rb +93 -85
- data/lib/facets/more/lrucache.rb +17 -27
- data/lib/facets/more/mathconstants.rb +22 -40
- data/lib/facets/more/methodprobe.rb +56 -61
- data/lib/facets/more/mock.rb +24 -17
- data/lib/facets/more/multipliers.rb +21 -17
- data/lib/facets/more/multiton.rb +18 -24
- data/lib/facets/more/nackclass.rb +17 -21
- data/lib/facets/more/nilcomparable.rb +28 -30
- data/lib/facets/more/nullclass.rb +16 -15
- data/lib/facets/more/one.rb +94 -58
- data/lib/facets/more/opencascade.rb +187 -0
- data/lib/facets/more/openobject.rb +89 -66
- data/lib/facets/more/orderedhash.rb +4 -0
- data/lib/facets/more/ormsupport.rb +18 -29
- data/lib/facets/more/overload.rb +39 -3
- data/lib/facets/more/paramix.rb +16 -24
- data/lib/facets/more/pathlist.rb +17 -23
- data/lib/facets/more/pool.rb +21 -29
- data/lib/facets/more/pqueue.rb +190 -0
- data/lib/facets/more/preinitialize.rb +17 -18
- data/lib/facets/more/progressbar.rb +19 -15
- data/lib/facets/more/promoteself.rb +17 -21
- data/lib/facets/more/quaternion.rb +379 -346
- data/lib/facets/more/recorder.rb +15 -20
- data/lib/facets/more/reference.rb +25 -22
- data/lib/facets/more/rexmlbuilder.rb +21 -6
- data/lib/facets/more/rtals.rb +27 -24
- data/lib/facets/more/semaphore.rb +15 -28
- data/lib/facets/more/snapshot.rb +45 -41
- data/lib/facets/more/stateparser.rb +25 -35
- data/lib/facets/more/statichash.rb +37 -29
- data/lib/facets/more/syncarray.rb +18 -26
- data/lib/facets/more/synchash.rb +17 -26
- data/lib/facets/more/system.rb +25 -17
- data/lib/facets/more/tagiterator.rb +15 -39
- data/lib/facets/more/taskable.rb +417 -0
- data/lib/facets/more/timer.rb +22 -26
- data/lib/facets/more/times.rb +23 -23
- data/lib/facets/more/tracepoint.rb +25 -24
- data/lib/facets/more/tuple.rb +25 -42
- data/lib/facets/more/typecast.rb +27 -29
- data/lib/facets/more/uninheritable.rb +15 -22
- data/lib/facets/more/units.rb +23 -29
- data/lib/facets/more/xmlbuilder.rb +20 -22
- data/lib/facets/more/xmlhelper.rb +18 -21
- data/lib/facets/more/xoxo.rb +23 -11
- data/lib/facets/more/yamlstruct.rb +25 -22
- data/test/lib/facets/core/array/test_at_rand.rb +1 -1
- data/test/lib/facets/core/array/test_delete_unless.rb +1 -1
- data/test/lib/facets/core/array/test_delete_values.rb +1 -1
- data/test/lib/facets/core/array/test_delete_values_at.rb +1 -1
- data/test/lib/facets/core/array/test_first.rb +1 -1
- data/test/lib/facets/core/array/test_head.rb +1 -1
- data/test/lib/facets/core/array/test_last_index.rb +1 -1
- data/test/lib/facets/core/array/test_merge.rb +1 -1
- data/test/lib/facets/core/array/test_mid.rb +1 -1
- data/test/lib/facets/core/array/test_middle.rb +1 -1
- data/test/lib/facets/core/array/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/array/test_op_store.rb +1 -1
- data/test/lib/facets/core/array/test_pick.rb +1 -1
- data/test/lib/facets/core/array/test_pos.rb +1 -1
- data/test/lib/facets/core/array/test_pot.rb +1 -1
- data/test/lib/facets/core/array/test_pull.rb +1 -1
- data/test/lib/facets/core/array/test_rand_index.rb +1 -1
- data/test/lib/facets/core/array/test_rand_subset.rb +1 -1
- data/test/lib/facets/core/array/test_range.rb +1 -1
- data/test/lib/facets/core/array/test_rotate.rb +1 -1
- data/test/lib/facets/core/array/test_select.rb +1 -1
- data/test/lib/facets/core/array/test_shuffle.rb +1 -1
- data/test/lib/facets/core/array/test_thru.rb +1 -1
- data/test/lib/facets/core/array/test_to_b.rb +1 -1
- data/test/lib/facets/core/array/test_to_h.rb +1 -1
- data/test/lib/facets/core/array/test_to_hash.rb +1 -1
- data/test/lib/facets/core/binding/self/test_of_caller.rb +1 -1
- data/test/lib/facets/core/binding/test___LINE__.rb +1 -1
- data/test/lib/facets/core/binding/test_call_stack.rb +1 -1
- data/test/lib/facets/core/binding/test_called.rb +1 -1
- data/test/lib/facets/core/binding/test_caller.rb +1 -1
- data/test/lib/facets/core/binding/test_defined.rb +1 -1
- data/test/lib/facets/core/binding/test_eval.rb +1 -1
- data/test/lib/facets/core/binding/test_local_variables.rb +1 -1
- data/test/lib/facets/core/binding/test_method_name.rb +1 -1
- data/test/lib/facets/core/binding/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/binding/test_op_store.rb +1 -1
- data/test/lib/facets/core/binding/test_self.rb +1 -1
- data/test/lib/facets/core/class/test_cattr.rb +1 -1
- data/test/lib/facets/core/class/test_descendents.rb +1 -1
- data/test/lib/facets/core/class/test_method_name.rb +1 -1
- data/test/lib/facets/core/class/test_remove_descendents.rb +1 -1
- data/test/lib/facets/core/class/test_unix_path.rb +1 -1
- data/test/lib/facets/core/comparable/test_at_least.rb +1 -1
- data/test/lib/facets/core/comparable/test_clip.rb +1 -1
- data/test/lib/facets/core/comparable/test_cmp.rb +1 -1
- data/test/lib/facets/core/continuation/self/test_create.rb +1 -1
- data/test/lib/facets/core/date/test_days_in_month.rb +1 -1
- data/test/lib/facets/core/date/test_days_of_month.rb +1 -1
- data/test/lib/facets/core/date/test_stamp.rb +1 -1
- data/test/lib/facets/core/date/test_to_date.rb +1 -1
- data/test/lib/facets/core/date/test_to_s.rb +1 -1
- data/test/lib/facets/core/date/test_to_time.rb +1 -1
- data/test/lib/facets/core/dir/self/test_ancestor.rb +1 -1
- data/test/lib/facets/core/dir/self/test_ascend.rb +1 -1
- data/test/lib/facets/core/enumerable/self/test_combinations.rb +1 -1
- data/test/lib/facets/core/enumerable/self/test_cross.rb +1 -1
- data/test/lib/facets/core/enumerable/test_collect_with_index.rb +1 -1
- data/test/lib/facets/core/enumerable/test_commonality.rb +1 -1
- data/test/lib/facets/core/enumerable/test_compact_collect.rb +1 -1
- data/test/lib/facets/core/enumerable/test_count.rb +38 -0
- data/test/lib/facets/core/enumerable/test_cross.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_combination.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_pair.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_slice.rb +1 -1
- data/test/lib/facets/core/enumerable/test_each_unique_pair.rb +1 -1
- data/test/lib/facets/core/enumerable/test_entropy.rb +1 -1
- data/test/lib/facets/core/enumerable/test_every.rb +1 -1
- data/test/lib/facets/core/enumerable/test_ew.rb +1 -1
- data/test/lib/facets/core/enumerable/test_filter_collect.rb +1 -1
- data/test/lib/facets/core/enumerable/test_find_collisions.rb +1 -1
- data/test/lib/facets/core/enumerable/test_frequency.rb +1 -1
- data/test/lib/facets/core/enumerable/test_graph.rb +1 -1
- data/test/lib/facets/core/enumerable/test_ideal_entropy.rb +1 -1
- data/test/lib/facets/core/enumerable/test_none.rb +1 -1
- data/test/lib/facets/core/enumerable/test_occur.rb +1 -1
- data/test/lib/facets/core/enumerable/test_one.rb +1 -1
- data/test/lib/facets/core/enumerable/test_op_pow.rb +1 -1
- data/test/lib/facets/core/enumerable/test_partition_by.rb +1 -1
- data/test/lib/facets/core/enumerable/test_permute.rb +1 -1
- data/test/lib/facets/core/enumerable/test_probability.rb +1 -1
- data/test/lib/facets/core/enumerable/test_to_h.rb +1 -1
- data/test/lib/facets/core/enumerable/test_uniq_by.rb +1 -1
- data/test/lib/facets/core/file/self/test_create.rb +1 -1
- data/test/lib/facets/core/file/self/test_open_as_string.rb +1 -1
- data/test/lib/facets/core/file/self/test_read_list.rb +1 -1
- data/test/lib/facets/core/file/self/test_sanitize.rb +1 -1
- data/test/lib/facets/core/file/self/test_split_all.rb +1 -1
- data/test/lib/facets/core/float/test_round_at.rb +1 -1
- data/test/lib/facets/core/float/test_round_to.rb +1 -1
- data/test/lib/facets/core/hash/self/test_zipnew.rb +1 -1
- data/test/lib/facets/core/hash/test_alias.rb +1 -1
- data/test/lib/facets/core/hash/test_assert_has_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_assert_has_only_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_at.rb +1 -1
- data/test/lib/facets/core/hash/test_collate.rb +1 -1
- data/test/lib/facets/core/hash/test_each.rb +1 -1
- data/test/lib/facets/core/hash/test_each_with_index.rb +1 -1
- data/test/lib/facets/core/hash/test_each_with_key.rb +1 -1
- data/test/lib/facets/core/hash/test_graph.rb +1 -1
- data/test/lib/facets/core/hash/test_has_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_has_only_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_inverse.rb +1 -1
- data/test/lib/facets/core/hash/test_keys_to_s.rb +1 -1
- data/test/lib/facets/core/hash/test_keys_to_sym.rb +1 -1
- data/test/lib/facets/core/hash/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/hash/test_op_lshift.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_key.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_pair.rb +1 -1
- data/test/lib/facets/core/hash/test_rand_value.rb +1 -1
- data/test/lib/facets/core/hash/test_replace_each.rb +1 -1
- data/test/lib/facets/core/hash/test_shuffle.rb +1 -1
- data/test/lib/facets/core/hash/test_slice.rb +1 -1
- data/test/lib/facets/core/hash/test_swap.rb +1 -1
- data/test/lib/facets/core/hash/test_swapkey.rb +1 -1
- data/test/lib/facets/core/hash/test_to_h.rb +1 -1
- data/test/lib/facets/core/hash/test_to_ostruct.rb +1 -1
- data/test/lib/facets/core/hash/test_to_ostruct_recurse.rb +1 -1
- data/test/lib/facets/core/hash/test_traverse.rb +1 -1
- data/test/lib/facets/core/hash/test_update_each.rb +1 -1
- data/test/lib/facets/core/hash/test_update_keys.rb +1 -1
- data/test/lib/facets/core/hash/test_update_values.rb +1 -1
- data/test/lib/facets/core/hash/test_weave.rb +1 -1
- data/test/lib/facets/core/integer/test_factorial.rb +1 -1
- data/test/lib/facets/core/integer/test_multiple.rb +1 -1
- data/test/lib/facets/core/integer/test_ordinal.rb +1 -1
- data/test/lib/facets/core/integer/test_times_collect.rb +1 -1
- data/test/lib/facets/core/kernel/test___class__.rb +1 -1
- data/test/lib/facets/core/kernel/test_as.rb +1 -1
- data/test/lib/facets/core/kernel/test_assign_from.rb +1 -1
- data/test/lib/facets/core/kernel/test_assign_with.rb +1 -1
- data/test/lib/facets/core/kernel/test_bool.rb +1 -1
- data/test/lib/facets/core/kernel/test_bug.rb +1 -1
- data/test/lib/facets/core/kernel/test_call_stack.rb +1 -1
- data/test/lib/facets/core/kernel/test_called.rb +1 -1
- data/test/lib/facets/core/kernel/test_constant.rb +1 -1
- data/test/lib/facets/core/kernel/test_copy.rb +1 -1
- data/test/lib/facets/core/kernel/test_deep_copy.rb +1 -1
- data/test/lib/facets/core/kernel/test_demo.rb +1 -1
- data/test/lib/facets/core/kernel/test_fn.rb +1 -1
- data/test/lib/facets/core/kernel/test_generate_method_name.rb +1 -1
- data/test/lib/facets/core/kernel/test_get_by_id.rb +1 -1
- data/test/lib/facets/core/kernel/test_here.rb +1 -1
- data/test/lib/facets/core/kernel/test_in.rb +1 -1
- data/test/lib/facets/core/kernel/test_maybe.rb +1 -1
- data/test/lib/facets/core/kernel/test_metaclass.rb +1 -1
- data/test/lib/facets/core/kernel/test_method.rb +1 -1
- data/test/lib/facets/core/kernel/test_methodname.rb +1 -1
- data/test/lib/facets/core/kernel/test_methods.rb +1 -1
- data/test/lib/facets/core/kernel/test_new.rb +1 -1
- data/test/lib/facets/core/kernel/test_object_class.rb +1 -1
- data/test/lib/facets/core/kernel/test_object_hexid.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_all.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_esc.rb +1 -1
- data/test/lib/facets/core/kernel/test_require_facet.rb +1 -1
- data/test/lib/facets/core/kernel/test_resc.rb +1 -1
- data/test/lib/facets/core/kernel/test_returning.rb +1 -1
- data/test/lib/facets/core/kernel/test_send_as.rb +1 -1
- data/test/lib/facets/core/kernel/test_set_from.rb +1 -1
- data/test/lib/facets/core/kernel/test_set_with.rb +1 -1
- data/test/lib/facets/core/kernel/test_silently.rb +1 -1
- data/test/lib/facets/core/kernel/test_singleton.rb +1 -1
- data/test/lib/facets/core/kernel/test_superior.rb +1 -1
- data/test/lib/facets/core/kernel/test_supermethod.rb +1 -1
- data/test/lib/facets/core/kernel/test_this.rb +1 -1
- data/test/lib/facets/core/kernel/test_to_b.rb +1 -1
- data/test/lib/facets/core/kernel/test_to_bool.rb +1 -1
- data/test/lib/facets/core/kernel/test_uri.rb +1 -1
- data/test/lib/facets/core/kernel/test_val.rb +1 -1
- data/test/lib/facets/core/kernel/test_with_accessor.rb +1 -1
- data/test/lib/facets/core/matchdata/test_match.rb +1 -1
- data/test/lib/facets/core/matchdata/test_matchtree.rb +7 -2
- data/test/lib/facets/core/module/test_abstract.rb +1 -1
- data/test/lib/facets/core/module/test_alias_module_function.rb +1 -1
- data/test/lib/facets/core/module/test_ancestor.rb +1 -1
- data/test/lib/facets/core/module/test_basename.rb +1 -1
- data/test/lib/facets/core/module/test_by_name.rb +1 -1
- data/test/lib/facets/core/module/test_clone_using.rb +1 -1
- data/test/lib/facets/core/module/test_dirname.rb +1 -1
- data/test/lib/facets/core/module/test_equate_on.rb +1 -1
- data/test/lib/facets/core/module/test_generate_instance_method_name.rb +1 -1
- data/test/lib/facets/core/module/test_include_as.rb +1 -1
- data/test/lib/facets/core/module/test_inherit.rb +1 -1
- data/test/lib/facets/core/module/test_initializer.rb +1 -1
- data/test/lib/facets/core/module/test_instance_methods.rb +1 -1
- data/test/lib/facets/core/module/test_integrate.rb +1 -1
- data/test/lib/facets/core/module/test_memoize.rb +1 -1
- data/test/lib/facets/core/module/test_modspace.rb +1 -1
- data/test/lib/facets/core/module/test_namespace.rb +1 -1
- data/test/lib/facets/core/module/test_nesting.rb +1 -1
- data/test/lib/facets/core/module/{test_undef.rb → test_nodef.rb} +5 -5
- data/test/lib/facets/core/module/test_on_included.rb +1 -1
- data/test/lib/facets/core/module/test_redef.rb +1 -1
- data/test/lib/facets/core/module/test_redefine_method.rb +1 -1
- data/test/lib/facets/core/module/test_redirect.rb +1 -1
- data/test/lib/facets/core/module/test_redirect_method.rb +1 -1
- data/test/lib/facets/core/module/test_remove.rb +1 -1
- data/test/lib/facets/core/module/test_rename.rb +1 -1
- data/test/lib/facets/core/module/test_rename_method.rb +1 -1
- data/test/lib/facets/core/module/test_revisal.rb +1 -1
- data/test/lib/facets/core/module/test_shadow_method.rb +1 -1
- data/test/lib/facets/core/module/test_sort_on.rb +1 -1
- data/test/lib/facets/core/module/test_this.rb +1 -1
- data/test/lib/facets/core/module/test_wrap.rb +1 -1
- data/test/lib/facets/core/module/test_wrap_method.rb +1 -1
- data/test/lib/facets/core/nilclass/test_blank.rb +1 -1
- data/test/lib/facets/core/nilclass/test_empty.rb +1 -1
- data/test/lib/facets/core/nilclass/test_include.rb +1 -1
- data/test/lib/facets/core/nilclass/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/nilclass/test_size.rb +1 -1
- data/test/lib/facets/core/nilclass/test_to_h.rb +1 -1
- data/test/lib/facets/core/numeric/test_approx.rb +1 -1
- data/test/lib/facets/core/numeric/test_ceil_multiple.rb +1 -1
- data/test/lib/facets/core/numeric/test_succ.rb +1 -1
- data/test/lib/facets/core/numeric/test_to_b.rb +1 -1
- data/test/lib/facets/core/ostruct/test___merge__.rb +1 -1
- data/test/lib/facets/core/ostruct/test___update__.rb +1 -1
- data/test/lib/facets/core/ostruct/test_op_fetch.rb +1 -1
- data/test/lib/facets/core/ostruct/test_op_store.rb +1 -1
- data/test/lib/facets/core/proc/test_compose.rb +1 -1
- data/test/lib/facets/core/proc/test_to_method.rb +1 -1
- data/test/lib/facets/core/range/test_to_r.rb +1 -1
- data/test/lib/facets/core/range/test_to_range.rb +1 -1
- data/test/lib/facets/core/range/test_umbrella.rb +1 -1
- data/test/lib/facets/core/range/test_within.rb +1 -1
- data/test/lib/facets/core/regexp/test_arity.rb +1 -1
- data/test/lib/facets/core/regexp/test_to_re.rb +1 -1
- data/test/lib/facets/core/regexp/test_to_regexp.rb +1 -1
- data/test/lib/facets/core/string/self/test_interpolate.rb +1 -1
- data/test/lib/facets/core/string/self/test_patterns.rb +1 -1
- data/test/lib/facets/core/string/self/test_rand_letter.rb +1 -1
- data/test/lib/facets/core/string/test_align_center.rb +1 -1
- data/test/lib/facets/core/string/test_at_rand.rb +1 -1
- data/test/lib/facets/core/string/test_basename.rb +1 -1
- data/test/lib/facets/core/string/test_blank.rb +1 -1
- data/test/lib/facets/core/string/test_bracket.rb +1 -1
- data/test/lib/facets/core/string/test_camelcase.rb +1 -1
- data/test/lib/facets/core/string/test_camelize.rb +1 -1
- data/test/lib/facets/core/string/test_capitalized.rb +1 -1
- data/test/lib/facets/core/string/test_chars.rb +1 -1
- data/test/lib/facets/core/string/test_cmp.rb +1 -1
- data/test/lib/facets/core/string/test_demodulize.rb +1 -1
- data/test/lib/facets/core/string/test_downcase.rb +1 -1
- data/test/lib/facets/core/string/test_dresner.rb +1 -1
- data/test/lib/facets/core/string/test_each_char.rb +1 -1
- data/test/lib/facets/core/string/test_each_word.rb +1 -1
- data/test/lib/facets/core/string/test_first.rb +1 -1
- data/test/lib/facets/core/string/test_fold.rb +1 -1
- data/test/lib/facets/core/string/test_frequency.rb +1 -1
- data/test/lib/facets/core/string/test_humanize.rb +1 -1
- data/test/lib/facets/core/string/test_indent.rb +1 -1
- data/test/lib/facets/core/string/test_index_all.rb +1 -1
- data/test/lib/facets/core/string/test_last.rb +1 -1
- data/test/lib/facets/core/string/test_line_wrap.rb +1 -1
- data/test/lib/facets/core/string/test_lines.rb +1 -1
- data/test/lib/facets/core/string/test_lowercase.rb +1 -1
- data/test/lib/facets/core/string/test_margin.rb +1 -1
- data/test/lib/facets/core/string/test_methodize.rb +1 -1
- data/test/lib/facets/core/string/test_modulize.rb +1 -1
- data/test/lib/facets/core/string/test_mscan.rb +1 -1
- data/test/lib/facets/core/string/test_natcmp.rb +1 -1
- data/test/lib/facets/core/string/test_nchar.rb +1 -1
- data/test/lib/facets/core/string/test_pathize.rb +1 -1
- data/test/lib/facets/core/string/test_pop.rb +1 -1
- data/test/lib/facets/core/string/test_pot.rb +1 -1
- data/test/lib/facets/core/string/test_probability.rb +1 -1
- data/test/lib/facets/core/string/test_push.rb +1 -1
- data/test/lib/facets/core/string/test_quote.rb +1 -1
- data/test/lib/facets/core/string/test_rand_byte.rb +1 -1
- data/test/lib/facets/core/string/test_rand_index.rb +1 -1
- data/test/lib/facets/core/string/test_range.rb +1 -1
- data/test/lib/facets/core/string/test_range_all.rb +1 -1
- data/test/lib/facets/core/string/test_range_of_line.rb +1 -1
- data/test/lib/facets/core/string/test_regesc.rb +1 -1
- data/test/lib/facets/core/string/test_shatter.rb +1 -1
- data/test/lib/facets/core/string/test_shift.rb +1 -1
- data/test/lib/facets/core/string/test_shuffle.rb +1 -1
- data/test/lib/facets/core/string/test_similarity.rb +1 -1
- data/test/lib/facets/core/string/test_singular.rb +1 -1
- data/test/lib/facets/core/string/test_soundex.rb +1 -1
- data/test/lib/facets/core/string/test_succ.rb +1 -1
- data/test/lib/facets/core/string/test_to_a.rb +1 -1
- data/test/lib/facets/core/string/test_to_b.rb +1 -1
- data/test/lib/facets/core/string/test_to_const.rb +1 -1
- data/test/lib/facets/core/string/test_to_date.rb +1 -1
- data/test/lib/facets/core/string/test_to_proc.rb +1 -1
- data/test/lib/facets/core/string/test_to_re.rb +1 -1
- data/test/lib/facets/core/string/test_to_time.rb +1 -1
- data/test/lib/facets/core/string/test_unix_crypt.rb +1 -1
- data/test/lib/facets/core/string/test_unpack.rb +1 -1
- data/test/lib/facets/core/string/test_unshift.rb +1 -1
- data/test/lib/facets/core/string/test_upcase.rb +1 -1
- data/test/lib/facets/core/string/test_whitespace.rb +1 -1
- data/test/lib/facets/core/string/test_word_filter.rb +1 -1
- data/test/lib/facets/core/string/test_word_wrap.rb +1 -1
- data/test/lib/facets/core/string/test_words.rb +1 -1
- data/test/lib/facets/core/symbol/test_camelcase.rb +1 -1
- data/test/lib/facets/core/symbol/test_camelize.rb +1 -1
- data/test/lib/facets/core/symbol/test_capitalize.rb +1 -1
- data/test/lib/facets/core/symbol/test_capitalized.rb +1 -1
- data/test/lib/facets/core/symbol/test_downcase.rb +1 -1
- data/test/lib/facets/core/symbol/test_not.rb +1 -1
- data/test/lib/facets/core/symbol/test_pad.rb +1 -1
- data/test/lib/facets/core/symbol/test_succ.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_const.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_proc.rb +1 -1
- data/test/lib/facets/core/symbol/test_to_str.rb +1 -1
- data/test/lib/facets/core/symbol/test_underscore.rb +1 -1
- data/test/lib/facets/core/symbol/test_upcase.rb +1 -1
- data/test/lib/facets/core/time/test_change.rb +1 -1
- data/test/lib/facets/core/time/test_elapse.rb +1 -1
- data/test/lib/facets/core/time/test_stamp.rb +1 -1
- data/test/lib/facets/core/time/test_to_date.rb +1 -1
- data/test/lib/facets/core/time/test_to_s.rb +1 -1
- data/test/lib/facets/core/time/test_to_time.rb +1 -1
- data/test/lib/facets/more/test_annattr.rb +39 -0
- data/test/lib/facets/more/test_annotatedattr.rb +39 -0
- data/test/lib/facets/more/test_annotation.rb +1 -22
- data/test/lib/facets/more/test_ansicode.rb +1 -1
- data/test/lib/facets/more/test_association.rb +6 -1
- data/test/lib/facets/more/test_basicobject.rb +1 -1
- data/test/lib/facets/more/test_bbcode.rb +1 -1
- data/test/lib/facets/more/test_binaryreader.rb +64 -0
- data/test/lib/facets/more/test_bitmask.rb +1 -1
- data/test/lib/facets/more/test_bytes.rb +1 -1
- data/test/lib/facets/more/test_classinherit.rb +1 -1
- data/test/lib/facets/more/test_classmethods.rb +1 -1
- data/test/lib/facets/more/test_coroutine.rb +1 -1
- data/test/lib/facets/more/test_crypt.rb +1 -1
- data/test/lib/facets/more/test_dictionary.rb +1 -1
- data/test/lib/facets/more/test_elementor.rb +1 -1
- data/test/lib/facets/more/test_enumerablepass.rb +1 -1
- data/test/lib/facets/more/test_floatstring.rb +1 -1
- data/test/lib/facets/more/test_functor.rb +1 -1
- data/test/lib/facets/more/test_htmlbuilder.rb +1 -1
- data/test/lib/facets/more/test_inheritor.rb +1 -1
- data/test/lib/facets/more/test_interval.rb +1 -1
- data/test/lib/facets/more/test_json.rb +1 -1
- data/test/lib/facets/more/test_lisp.rb +1 -1
- data/test/lib/facets/more/test_lisp_format.rb +1 -1
- data/test/lib/facets/more/test_lrucache.rb +1 -1
- data/test/lib/facets/more/test_mathconstants.rb +1 -1
- data/test/lib/facets/more/test_methodprobe.rb +1 -1
- data/test/lib/facets/more/test_multipliers.rb +1 -1
- data/test/lib/facets/more/test_multiton.rb +1 -1
- data/test/lib/facets/more/test_nackclass.rb +1 -1
- data/test/lib/facets/more/test_nilcomparable.rb +1 -1
- data/test/lib/facets/more/test_opencascade.rb +66 -0
- data/test/lib/facets/more/test_openobject.rb +14 -2
- data/test/lib/facets/more/test_overload.rb +1 -1
- data/test/lib/facets/more/test_paramix.rb +1 -1
- data/test/lib/facets/more/test_pqueue.rb +39 -0
- data/test/lib/facets/more/test_preinitialize.rb +1 -1
- data/test/lib/facets/more/test_promoteself.rb +1 -1
- data/test/lib/facets/more/test_recorder.rb +1 -1
- data/test/lib/facets/more/test_snapshot.rb +1 -1
- data/test/lib/facets/more/test_statichash.rb +11 -11
- data/test/lib/facets/more/test_syncarray.rb +1 -1
- data/test/lib/facets/more/test_synchash.rb +1 -1
- data/test/lib/facets/more/test_tagiterator.rb +1 -1
- data/test/lib/facets/more/test_taskable.rb +151 -0
- data/test/lib/facets/more/test_timer.rb +1 -1
- data/test/lib/facets/more/test_times.rb +1 -1
- data/test/lib/facets/more/test_tuple.rb +1 -1
- data/test/lib/facets/more/test_typecast.rb +1 -1
- data/test/lib/facets/more/test_uninheritable.rb +1 -1
- data/test/lib/facets/more/test_units.rb +1 -1
- data/test/lib/facets/more/test_xmlbuilder.rb +1 -1
- data/test/lib/facets/more/test_xmlhelper.rb +1 -1
- data/test/lib/facets/more/test_xoxo.rb +1 -1
- data/test/lib/facets/more/test_yamlstruct.rb +1 -1
- metadata +1243 -1247
- data/ProjectInfo +0 -89
- data/Rakefile +0 -181
- data/doc/CHANGELOG +0 -284
- data/doc/TODO +0 -73
- data/doc/noauto +0 -63
- data/lib/facet/array.rb +0 -1
- data/lib/facet/class.rb +0 -1
- data/lib/facet/comparable.rb +0 -1
- data/lib/facet/continuation.rb +0 -1
- data/lib/facet/date.rb +0 -1
- data/lib/facet/dir.rb +0 -1
- data/lib/facet/enumerable.rb +0 -1
- data/lib/facet/file.rb +0 -1
- data/lib/facet/fileutils.rb +0 -1
- data/lib/facet/float.rb +0 -1
- data/lib/facet/gem.rb +0 -1
- data/lib/facet/hash.rb +0 -1
- data/lib/facet/integer.rb +0 -1
- data/lib/facet/kernel.rb +0 -1
- data/lib/facet/logger.rb +0 -1
- data/lib/facet/matchdata.rb +0 -1
- data/lib/facet/module.rb +0 -1
- data/lib/facet/module/undef.rb +0 -1
- data/lib/facet/nilclass.rb +0 -1
- data/lib/facet/numeric.rb +0 -1
- data/lib/facet/pathname.rb +0 -1
- data/lib/facet/proc.rb +0 -1
- data/lib/facet/range.rb +0 -1
- data/lib/facet/regexp.rb +0 -1
- data/lib/facet/string.rb +0 -1
- data/lib/facet/symbol.rb +0 -1
- data/lib/facet/time.rb +0 -1
- data/lib/facet/unboundmethod.rb +0 -1
- data/lib/facets/core/array.rb +0 -35
- data/lib/facets/core/class.rb +0 -11
- data/lib/facets/core/comparable.rb +0 -5
- data/lib/facets/core/continuation.rb +0 -1
- data/lib/facets/core/date.rb +0 -6
- data/lib/facets/core/dir.rb +0 -4
- data/lib/facets/core/enumerable.rb +0 -42
- data/lib/facets/core/file.rb +0 -8
- data/lib/facets/core/fileutils.rb +0 -8
- data/lib/facets/core/float.rb +0 -4
- data/lib/facets/core/gem.rb +0 -4
- data/lib/facets/core/hash.rb +0 -40
- data/lib/facets/core/integer.rb +0 -9
- data/lib/facets/core/kernel.rb +0 -69
- data/lib/facets/core/logger.rb +0 -2
- data/lib/facets/core/matchdata.rb +0 -3
- data/lib/facets/core/module.rb +0 -43
- data/lib/facets/core/nilclass.rb +0 -9
- data/lib/facets/core/numeric.rb +0 -6
- data/lib/facets/core/pathname.rb +0 -2
- data/lib/facets/core/proc.rb +0 -3
- data/lib/facets/core/range.rb +0 -4
- data/lib/facets/core/regexp.rb +0 -3
- data/lib/facets/core/string.rb +0 -91
- data/lib/facets/core/symbol.rb +0 -13
- data/lib/facets/core/time.rb +0 -8
- data/lib/facets/core/unboundmethod.rb +0 -1
@@ -1,30 +1,27 @@
|
|
1
|
-
|
2
|
-
# Preinitialize
|
1
|
+
# = preinitialize.rb
|
3
2
|
#
|
4
|
-
# Copyright (c) 2005 Thomas Sawyer
|
3
|
+
# == Copyright (c) 2005 Thomas Sawyer
|
5
4
|
#
|
6
|
-
#
|
5
|
+
# Ruby License
|
7
6
|
#
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
+
# software under the same terms as Ruby.
|
10
9
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
14
13
|
#
|
14
|
+
# == Author(s)
|
15
15
|
#
|
16
|
-
#
|
17
|
-
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# 05.08.26 trans Created.
|
22
|
-
# ==========================================================================
|
23
|
-
#++
|
16
|
+
# * Thomas Sawyer
|
17
|
+
|
18
|
+
# Author:: Thomas Sawyer
|
19
|
+
# Copyright:: Copyright (c) 2005 Thomas Sawyer
|
20
|
+
# License:: Ruby License
|
24
21
|
|
25
22
|
require 'facet/kernel/__class__'
|
26
23
|
|
27
|
-
|
24
|
+
# = Preinitialize
|
28
25
|
#
|
29
26
|
# This is an object preinitialize system, which provides
|
30
27
|
# an elegant way to initialize an object allowing the
|
@@ -61,6 +58,7 @@ require 'facet/kernel/__class__'
|
|
61
58
|
# If neded the original new method has been aliased, albeit
|
62
59
|
# <tt>postinitialize_new</tt> is probably a bit of a misnomer.
|
63
60
|
|
61
|
+
#--
|
64
62
|
# class Module
|
65
63
|
#
|
66
64
|
# def default_instance_variables(complete=false)
|
@@ -78,6 +76,7 @@ require 'facet/kernel/__class__'
|
|
78
76
|
# end
|
79
77
|
#
|
80
78
|
# end
|
79
|
+
#++
|
81
80
|
|
82
81
|
class Class
|
83
82
|
alias_method :postinitialize_new, :new
|
@@ -1,29 +1,33 @@
|
|
1
|
-
|
2
|
-
# Console::ProgressBar
|
1
|
+
# = progressbar.rb
|
3
2
|
#
|
4
|
-
# Copyright (C) 2001
|
5
|
-
# All rights reserved.
|
3
|
+
# == Copyright (C) 2001 Satoru Takabayashi
|
6
4
|
#
|
7
|
-
#
|
5
|
+
# Ruby License
|
8
6
|
#
|
9
|
-
# You
|
10
|
-
#
|
11
|
-
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
+
# software under the same terms as Ruby.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
13
|
+
#
|
14
|
+
# == Author(s)
|
15
|
+
#
|
16
|
+
# * Satoru Takabayashi
|
12
17
|
|
13
|
-
#
|
18
|
+
# Author:: Satoru Takabayashi
|
19
|
+
# Copyright:: Copyright (c) 2001 Satoru Takabayashi
|
20
|
+
# License:: Ruby License
|
21
|
+
|
22
|
+
# = Console Progress Bar
|
14
23
|
#
|
15
24
|
# Console::ProgressBar is a terminal-based progress bar library.
|
16
25
|
#
|
17
26
|
# == Usage
|
18
|
-
#
|
27
|
+
#
|
19
28
|
# pbar = ConsoleProgressBar.new( "Demo", 100 )
|
20
29
|
# 100.times { pbar.inc }
|
21
30
|
# pbar.finish
|
22
|
-
#
|
23
|
-
# == Author(s)
|
24
|
-
#
|
25
|
-
# * Satoru Takabayashi
|
26
|
-
# * Thomas Sawyer
|
27
31
|
#
|
28
32
|
|
29
33
|
module Console ; end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
|
2
|
-
# PromoteSelf
|
1
|
+
# = promoteself.rb
|
3
2
|
#
|
4
|
-
# Copyright (c) 2005
|
3
|
+
# == Copyright (c) 2005 Thomas Sawyer
|
5
4
|
#
|
6
|
-
#
|
5
|
+
# Ruby License
|
7
6
|
#
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
+
# software under the same terms as Ruby.
|
10
9
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
14
13
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
# == Author(s)
|
15
|
+
#
|
16
|
+
# * Thomas Sawyer
|
17
|
+
|
18
|
+
# Author:: Thomas Sawyer
|
19
|
+
# Copyright:: Copyright (c) 2005 Thomas Sawyer
|
20
|
+
# License:: Ruby License
|
21
|
+
|
22
|
+
# = PromoteSelf
|
23
23
|
#
|
24
24
|
# PromoteSelf converts a module's class methods into instance methods
|
25
25
|
# such that the first parameter is passed self at the instance level.
|
@@ -43,10 +43,6 @@
|
|
43
43
|
#
|
44
44
|
# "Try".jumble( "Me" ) #=> 'TryMe'
|
45
45
|
#
|
46
|
-
# == Authors(s)
|
47
|
-
#
|
48
|
-
# * Thomas Sawyer
|
49
|
-
#
|
50
46
|
|
51
47
|
module PromoteSelf
|
52
48
|
alias_method :singleton_method_added_promoteself, :singleton_method_added if defined?(singleton_method_added)
|
@@ -1,9 +1,36 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
1
|
+
# = quaternion.rb
|
2
|
+
#
|
3
|
+
# == Copyright (c) 2002 K. Kodama
|
4
|
+
#
|
5
|
+
# Ruby License
|
6
|
+
#
|
7
|
+
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
+
# software under the same terms as Ruby.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
+
# FOR A PARTICULAR PURPOSE.
|
13
|
+
#
|
14
|
+
# == Author(s)
|
15
|
+
#
|
16
|
+
# * K. Kodama
|
17
|
+
#
|
18
|
+
# == Developer Notes
|
19
|
+
#
|
20
|
+
# TODO The following documentation should occur before the methods
|
21
|
+
# they describe.
|
4
22
|
|
5
|
-
#
|
23
|
+
# Author:: K. Kodama
|
24
|
+
# Copyright:: Copyright (c) 2002 K. Kodama
|
25
|
+
# License:: Ruby License
|
6
26
|
|
27
|
+
require "mathn"
|
28
|
+
require "complex"
|
29
|
+
|
30
|
+
# = Quaternion
|
31
|
+
#
|
32
|
+
# NOTE This Quaternion class is still very experimental.
|
33
|
+
#
|
7
34
|
# Quaternions are attributed to Sir William Rowan Hamilton
|
8
35
|
# who find it in 1843, and published a major analysis in 1844 called
|
9
36
|
# "On a Species of Imaginary Quantities Connected with a Theory of Quaternions"
|
@@ -11,36 +38,45 @@
|
|
11
38
|
#
|
12
39
|
# Typical quaternion number q is of the form q = r + a i + b j + c k.
|
13
40
|
# Bases i j k behaves as follows:
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# j
|
41
|
+
#
|
42
|
+
# i^2 = j^2 = k^2 = -1
|
43
|
+
# i j = k, j k = i, k i = j
|
44
|
+
# j i = -k, k j = -i, i k = -j
|
45
|
+
#
|
17
46
|
# Quaternion numbers are not Commutative.
|
18
|
-
# Quaternion is
|
19
|
-
# 4-D space over Real number,
|
47
|
+
# Quaternion is 4-D space over Real number,
|
20
48
|
# and 2-D space over Complex numbers as q = (a + b i) + (c + d i)j.
|
21
49
|
#
|
50
|
+
# === Polar Coordinates
|
22
51
|
#
|
23
|
-
# Polar Coordinates:
|
24
52
|
# A Quaternion q = r + a i + b j + k c have 1st level polar form such that
|
53
|
+
#
|
25
54
|
# q = |q|(cos t1 + sin t1 u1) , where u1 is unit vector of u1 = a1 i + b1 j + c1 k.
|
55
|
+
#
|
26
56
|
# u1 have 2nd level
|
57
|
+
#
|
27
58
|
# u1 = i cos t2 + sin t2 u2, where u2 is unit vector of u2 = b2 j + c2 k.
|
59
|
+
#
|
28
60
|
# And u2 have 3rd level
|
61
|
+
#
|
29
62
|
# u2 = j cos t3 + k sin t3.
|
63
|
+
#
|
30
64
|
# So we have
|
31
|
-
#
|
65
|
+
#
|
66
|
+
# q=|q|( cos t1 + sin t1 ( i cos t2 + sin t2 ( j cos t3 + k sin t3 )))
|
67
|
+
#
|
32
68
|
# The equivalent to polar coordinates in quaternion space are
|
33
|
-
# r = |q| cos(t1),
|
34
|
-
# a = |q| sin(t1) cos(t2),
|
35
|
-
# b = |q| sin(t1) sin(t2) cos(t3),
|
36
|
-
# c = |q| sin(t1) sin(t2) sin(t3).
|
37
69
|
#
|
38
|
-
# |q|
|
39
|
-
#
|
70
|
+
# r = |q| cos(t1)
|
71
|
+
# a = |q| sin(t1) cos(t2)
|
72
|
+
# b = |q| sin(t1) sin(t2) cos(t3)
|
73
|
+
# c = |q| sin(t1) sin(t2) sin(t3)
|
74
|
+
#
|
75
|
+
# |q| is known as the magnitude of the quaternion, t1 is the amplitude(or angle),
|
40
76
|
# t2 and t3 are the latitude (or co-latitude) and longitude respectively.
|
41
77
|
#
|
78
|
+
# === Vector
|
42
79
|
#
|
43
|
-
# Vector:
|
44
80
|
# A Quaternions q= r + a i + b j + c k is 4-D space over Real numbers.
|
45
81
|
# A Quaternions with zero real part q = a i + b j + c k is 3-D space,
|
46
82
|
# and called a vector quaternion or, simply, vector.
|
@@ -51,22 +87,22 @@
|
|
51
87
|
# Note that u^2=-1.
|
52
88
|
# Vectors are 3-D space And can define cross-product q1 x q2.
|
53
89
|
#
|
54
|
-
# Rotation
|
90
|
+
# === Rotation
|
91
|
+
#
|
55
92
|
# Quaternion can be used to describe rotation in 3-D space.
|
56
93
|
# For a vector v and a Quaternion q = |q|(cos t/2 + u sin t/2),
|
57
94
|
# q v q^(-1) is a vector v t-rotated along u.
|
58
95
|
# Composit rotation of q1, q2 is described as q2 q1,
|
59
96
|
# because q2 (q1 v q1^(-1)) q2^(-1) = (q2 q1) v (q2 q1)^(-1).
|
60
97
|
#
|
61
|
-
# GCD
|
98
|
+
# === GCD
|
99
|
+
#
|
62
100
|
# D4 lattice space is lattice points of Quaternion q = r + a i + b j + c k as follows.
|
63
101
|
# (1) r,a,b,c are all integer, or
|
64
102
|
# (2) r,a,b,c are all half-integer.
|
65
103
|
# D4 is sub-ring of Quaternion with GCD.
|
66
104
|
# (Ring means a space with +, -, *.)
|
67
105
|
|
68
|
-
|
69
|
-
|
70
106
|
=begin
|
71
107
|
|
72
108
|
* Building quaternions and taking them apart
|
@@ -185,343 +221,340 @@ q.inspect
|
|
185
221
|
=end
|
186
222
|
|
187
223
|
|
188
|
-
require "mathn"
|
189
|
-
require "complex"
|
190
|
-
|
191
224
|
def Quaternion(a=0, b=0,c=0, d=0)
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
225
|
+
if a.kind_of?(Quaternion);
|
226
|
+
a;
|
227
|
+
elsif a.kind_of?(Complex) and b.kind_of?(Complex);
|
228
|
+
Quaternion.new(a.real, a.image, b.real, b.image)
|
229
|
+
elsif a.kind_of?(Complex);
|
230
|
+
Quaternion.new(a.real, a.image)
|
231
|
+
else
|
232
|
+
Quaternion.new(a,b,c,d);
|
233
|
+
end
|
201
234
|
end
|
202
235
|
|
203
236
|
class Quaternion < Numeric
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
237
|
+
attr :re
|
238
|
+
attr :im
|
239
|
+
attr :jm
|
240
|
+
attr :km
|
241
|
+
def image; return @im; end
|
242
|
+
def real_part; return @re; end
|
243
|
+
def real; return @re; end
|
244
|
+
def to_c; return Complex(@re,@im); end
|
245
|
+
def to_c2; return Complex(@jm,@km); end
|
246
|
+
def to_a; return [@re, @im, @jm, @km]; end
|
247
|
+
def Quaternion::generic?(other)
|
248
|
+
return (other.kind_of?(Complex) or Complex.generic?(other));
|
249
|
+
end
|
250
|
+
def initialize(a=0,b=0,c=0,d=0)
|
251
|
+
raise "non numeric 1st arg `#{a.inspect}'" if !a.kind_of? Numeric;
|
252
|
+
raise "non numeric 2nd arg `#{b.inspect}'" if !b.kind_of? Numeric;
|
253
|
+
raise "non numeric 3rd arg `#{c.inspect}'" if !c.kind_of? Numeric;
|
254
|
+
raise "non numeric 4th arg `#{d.inspect}'" if !d.kind_of? Numeric;
|
255
|
+
@re=a; @im=b; @jm=c; @km=d
|
256
|
+
end
|
257
|
+
private :initialize
|
258
|
+
|
259
|
+
Zero=Quaternion(0)
|
260
|
+
One=Quaternion(1)
|
261
|
+
I=Quaternion(0,1)
|
262
|
+
J=Quaternion(0,0,1)
|
263
|
+
K=Quaternion(0,0,0,1)
|
225
264
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
265
|
+
def Quaternion::polar(m,t1=0,t2=0,t3=0)
|
266
|
+
# q=
|
267
|
+
# m*cos(t1)
|
268
|
+
# +m*sin(t1)cos(t2)i
|
269
|
+
# +m*sin(t1)sin(t2)cos(t3)j
|
270
|
+
# +m*sin(t1)sin(t2)sin(t3)k
|
271
|
+
# m is known as the magnitude,
|
272
|
+
# t1 is the amplitude(or angle) of the quaternion,
|
273
|
+
# t2 and t3 are the latitude (or co-latitude) and longitude respectively.
|
274
|
+
if m.kind_of?(Array) and (m.size==4); t1=m[1]; t2=m[2]; t3=m[3]; m=m[0]; end;
|
275
|
+
s=m
|
276
|
+
r_part=s*Math.cos(t1); s=s*Math.sin(t1)
|
277
|
+
i_part=s*Math.cos(t2); s=s*Math.sin(t2)
|
278
|
+
j_part=s*Math.cos(t3); k_part=s*Math.sin(t3)
|
279
|
+
new(r_part, i_part, j_part, k_part)
|
280
|
+
end
|
281
|
+
def amplitude; Math.atan2(Math.sqrt((@im*@im+@jm*@jm+@km*@km).to_f),@re.to_f); end
|
282
|
+
def latitude; Math.atan2(Math.sqrt((@jm*@jm+@km*@km).to_f),@im.to_f); end
|
283
|
+
def longitude; Math.atan2( @km.to_f, @jm.to_f); end
|
284
|
+
def arg1; return amplitude; end
|
285
|
+
def arg2; return latitude; end
|
286
|
+
def arg3; return longitude; end
|
287
|
+
def polar; [magnitude, amplitude, latitude, longitude]; end
|
231
288
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
def longitude; Math.atan2( @km.to_f, @jm.to_f); end
|
251
|
-
def arg1; return amplitude; end
|
252
|
-
def arg2; return latitude; end
|
253
|
-
def arg3; return longitude; end
|
254
|
-
def polar; [magnitude, amplitude, latitude, longitude]; end
|
289
|
+
def round; Quaternion(@re.round,@im.round,@jm.round,@km.round);end
|
290
|
+
def round_D4
|
291
|
+
# round to D4 lattice
|
292
|
+
r1=@re.round; a1=@im.round; b1=@jm.round; c1=@km.round;
|
293
|
+
q1=Quaternion(r1,a1,b1,c1); d1=(q1-self).abs2
|
294
|
+
if d1<=1/4; return q1; end
|
295
|
+
if @re<r1; r2=r1-1/2; else r2=r1+1/2; end
|
296
|
+
if @im<r1; a2=a1-1/2; else a2=a1+1/2; end
|
297
|
+
if @jm<r1; b2=b1-1/2; else b2=b1+1/2; end
|
298
|
+
if @km<r1; c2=c1-1/2; else c2=c1+1/2; end
|
299
|
+
q2=Quaternion(r2,a2,b2,c2); d2=(q2-self).abs2
|
300
|
+
if d1<=d2; return q1; else return q2; end
|
301
|
+
end
|
302
|
+
def abs2; return @re*@re+@im*@im+@jm*@jm+@km*@km; end
|
303
|
+
def abs; Math.sqrt((@re*@re+@im*@im+@jm*@jm+@km*@km).to_f); end
|
304
|
+
def magnitude; return abs; end
|
305
|
+
def conjugate; Quaternion(@re,-@im,-@jm,-@km); end
|
306
|
+
def inverse; conjugate/abs2; end
|
255
307
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
r1=@re.round; a1=@im.round; b1=@jm.round; c1=@km.round;
|
260
|
-
q1=Quaternion(r1,a1,b1,c1); d1=(q1-self).abs2
|
261
|
-
if d1<=1/4; return q1; end
|
262
|
-
if @re<r1; r2=r1-1/2; else r2=r1+1/2; end
|
263
|
-
if @im<r1; a2=a1-1/2; else a2=a1+1/2; end
|
264
|
-
if @jm<r1; b2=b1-1/2; else b2=b1+1/2; end
|
265
|
-
if @km<r1; c2=c1-1/2; else c2=c1+1/2; end
|
266
|
-
q2=Quaternion(r2,a2,b2,c2); d2=(q2-self).abs2
|
267
|
-
if d1<=d2; return q1; else return q2; end
|
268
|
-
end
|
269
|
-
def abs2; return @re*@re+@im*@im+@jm*@jm+@km*@km; end
|
270
|
-
def abs; Math.sqrt((@re*@re+@im*@im+@jm*@jm+@km*@km).to_f); end
|
271
|
-
def magnitude; return abs; end
|
272
|
-
def conjugate; Quaternion(@re,-@im,-@jm,-@km); end
|
273
|
-
def inverse; conjugate/abs2; end
|
308
|
+
def is_real?; @im==0 and @jm==0 and @km==0; end
|
309
|
+
def is_complex?; @jm==0 and @km==0; end
|
310
|
+
def is_quaternion?; not(is_complex?); end
|
274
311
|
|
275
|
-
|
276
|
-
|
277
|
-
|
312
|
+
def vector; Quaternion(0,@im,@jm,@km); end
|
313
|
+
def is_vector?; @re==0; end
|
314
|
+
def to_v; return [@im, @jm, @km]; end
|
315
|
+
def Quaternion::vector(v)
|
316
|
+
# 3-D vector v=[x,y,z]
|
317
|
+
Quaternion(0,v[0],v[1],v[2])
|
318
|
+
end
|
319
|
+
def unit_vector
|
320
|
+
if is_real?; return Quaternion(0,1); end
|
321
|
+
m=Math::sqrt((@im*@im+@jm*@jm+@km*@km).to_f)
|
322
|
+
Quaternion(0,@im/m,@jm/m,@km/m);
|
323
|
+
end
|
324
|
+
def is_unit_vector?; @re==0 and abs2==1; end
|
325
|
+
def Quaternion::rotation(v,t)
|
326
|
+
# t-rotatin along the 3-D vector v
|
327
|
+
(Quaternion::vector(v).unit_vector) * Math::sin(t/2) + Math::cos(t/2)
|
328
|
+
end
|
329
|
+
def rotate(r); r * self * r.conjugate / r.abs2; end
|
330
|
+
def rotate_angle; amplitude/2; end
|
278
331
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
332
|
+
# Arithmetic
|
333
|
+
def coerce(other)
|
334
|
+
if other.kind_of?(Complex); return Quaternion(other), self
|
335
|
+
elsif Complex::generic?(other); return Quaternion(other), self
|
336
|
+
else super
|
337
|
+
end
|
338
|
+
end
|
339
|
+
def <=> (other); self.abs <=> other.abs; end
|
340
|
+
def == (other)
|
341
|
+
if other.kind_of?(Quaternion)
|
342
|
+
return (@re==other.re and @im==other.im and @jm==other.jm and @km==other.km)
|
343
|
+
elsif other.kind_of?(Complex)
|
344
|
+
@re==other.real and @im==other.image and @jm==0 and @km==0
|
345
|
+
elsif Complex.generic?(other)
|
346
|
+
@re==other and @im==0 and @jm==0 and @km==0
|
347
|
+
else x , y = other.coerce(self); x == y
|
348
|
+
end
|
349
|
+
end
|
350
|
+
def + (other)
|
351
|
+
if other.kind_of?(Quaternion)
|
352
|
+
Quaternion(@re+other.re,@im+other.im,@jm+other.jm,@km+other.km)
|
353
|
+
elsif other.kind_of?(Complex)
|
354
|
+
Quaternion(@re+other.real,@im+other.image, @jm, @km)
|
355
|
+
elsif Complex.generic?(other)
|
356
|
+
Quaternion(@re+other.real,@im, @jm, @km)
|
357
|
+
else x , y = other.coerce(self); x + y
|
358
|
+
end
|
359
|
+
end
|
360
|
+
def - (other)
|
361
|
+
if other.kind_of?(Quaternion)
|
362
|
+
Quaternion(@re-other.re,@im-other.im,@jm-other.jm,@km-other.km)
|
363
|
+
elsif other.kind_of?(Complex)
|
364
|
+
Quaternion(@re-other.real,@im-other.image, @jm, @km)
|
365
|
+
elsif Complex.generic?(other)
|
366
|
+
Quaternion(@re-other.real,@im, @jm, @km)
|
367
|
+
else x , y = other.coerce(self); x - y
|
368
|
+
end
|
369
|
+
end
|
370
|
+
def * (other)
|
371
|
+
if other.kind_of?(Quaternion)
|
372
|
+
Quaternion(@re*other.re-@im*other.im-@jm*other.jm-@km*other.km,
|
373
|
+
@re*other.im+@im*other.re+@jm*other.km-@km*other.jm,
|
374
|
+
@re*other.jm-@im*other.km+@jm*other.re+@km*other.im,
|
375
|
+
@re*other.km+@im*other.jm-@jm*other.im+@km*other.re)
|
376
|
+
elsif other.kind_of?(Complex)
|
377
|
+
Quaternion(@re*other.real - @im*other.image,
|
378
|
+
@re*other.image + @im*other.real,
|
379
|
+
@jm*other.real + @km*other.image,
|
380
|
+
@km*other.real - @jm*other.image)
|
381
|
+
elsif Complex.generic?(other)
|
382
|
+
Quaternion(@re * other, @im * other, @jm * other, @km * other)
|
383
|
+
else x , y = other.coerce(self); x * y
|
384
|
+
end
|
385
|
+
end
|
386
|
+
def dot_product other
|
387
|
+
(self*other.conjugate).re
|
388
|
+
end
|
389
|
+
def cross_product other
|
390
|
+
-(self*other.conjugate).vector
|
391
|
+
end
|
392
|
+
def / other
|
393
|
+
if other.kind_of?(Quaternion); self*other.conjugate/other.abs2
|
394
|
+
elsif other.kind_of?(Complex); self*other.conjugate/other.abs2
|
395
|
+
elsif Complex.generic?(other);
|
396
|
+
Quaternion(@re/other, @im/other, @jm/other, @km/other )
|
397
|
+
else x, y = other.coerce(self); x / y
|
398
|
+
end
|
399
|
+
end
|
400
|
+
def rdiv other
|
401
|
+
# right division: q1/q2
|
402
|
+
self/other
|
403
|
+
end
|
404
|
+
def ldiv other
|
405
|
+
# left division: 1/q1 * q2
|
406
|
+
(self.conjugate)*other/self.abs2
|
407
|
+
end
|
408
|
+
def divmod other
|
409
|
+
# right divmod: q1=d*q2+m
|
410
|
+
d=self.rdiv(other).round; m=self-d*other; return d,m
|
411
|
+
end
|
412
|
+
def divmod_D4 other
|
413
|
+
# right divmod: q1=d*q2+m, d be D4
|
414
|
+
d=self.rdiv(other).round_D4; m=self-d*other; return d,m
|
415
|
+
end
|
416
|
+
def ldivmod other
|
417
|
+
# left divmod: q2=q1*d+m
|
418
|
+
d=self.ldiv(other).round; m=other-self*d; return d,m
|
419
|
+
end
|
420
|
+
def ldivmod_D4 other
|
421
|
+
# left divmod: q2=q1*d+m, d be D4
|
422
|
+
d=self.ldiv(other).round_D4; m=other-self*d; return d,m
|
423
|
+
end
|
424
|
+
def % other
|
425
|
+
# right mod
|
426
|
+
d,m=divmod(other); return m
|
427
|
+
end
|
428
|
+
def rmod other
|
429
|
+
# right mod(same as %)
|
430
|
+
d,m=divmod(other); return m
|
431
|
+
end
|
432
|
+
def rmod_D4 other
|
433
|
+
# right mod with D4
|
434
|
+
d,m=divmod_D4(other); return m
|
435
|
+
end
|
436
|
+
def lmod other
|
437
|
+
# left mod
|
438
|
+
d,m=ldivmod(other); return m
|
439
|
+
end
|
440
|
+
def lmod_D4 other
|
441
|
+
# left mod with D4
|
442
|
+
d,m=ldivmod_D4(other); return m
|
443
|
+
end
|
444
|
+
def gcd other
|
445
|
+
a=self; b=other
|
446
|
+
while true
|
447
|
+
if b==0 ; return a;end
|
448
|
+
a=a.rmod_D4(b)
|
449
|
+
if a==0 ; return b;end
|
450
|
+
b=a.lmod_D4(b)
|
451
|
+
end
|
452
|
+
end
|
453
|
+
def orthogonal_split(o)
|
454
|
+
# [q1,q2]. q = q1 + q2 such that q1 parallel to o, and q2 orthogonal to o.
|
455
|
+
q1 = o * dot_product(o); q2=self-q1; return q1,q2
|
456
|
+
end
|
298
457
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
-(self*other.conjugate).vector
|
358
|
-
end
|
359
|
-
def / other
|
360
|
-
if other.kind_of?(Quaternion); self*other.conjugate/other.abs2
|
361
|
-
elsif other.kind_of?(Complex); self*other.conjugate/other.abs2
|
362
|
-
elsif Complex.generic?(other);
|
363
|
-
Quaternion(@re/other, @im/other, @jm/other, @km/other )
|
364
|
-
else x, y = other.coerce(self); x / y
|
365
|
-
end
|
366
|
-
end
|
367
|
-
def rdiv other
|
368
|
-
# right division: q1/q2
|
369
|
-
self/other
|
370
|
-
end
|
371
|
-
def ldiv other
|
372
|
-
# left division: 1/q1 * q2
|
373
|
-
(self.conjugate)*other/self.abs2
|
374
|
-
end
|
375
|
-
def divmod other
|
376
|
-
# right divmod: q1=d*q2+m
|
377
|
-
d=self.rdiv(other).round; m=self-d*other; return d,m
|
378
|
-
end
|
379
|
-
def divmod_D4 other
|
380
|
-
# right divmod: q1=d*q2+m, d be D4
|
381
|
-
d=self.rdiv(other).round_D4; m=self-d*other; return d,m
|
382
|
-
end
|
383
|
-
def ldivmod other
|
384
|
-
# left divmod: q2=q1*d+m
|
385
|
-
d=self.ldiv(other).round; m=other-self*d; return d,m
|
386
|
-
end
|
387
|
-
def ldivmod_D4 other
|
388
|
-
# left divmod: q2=q1*d+m, d be D4
|
389
|
-
d=self.ldiv(other).round_D4; m=other-self*d; return d,m
|
390
|
-
end
|
391
|
-
def % other
|
392
|
-
# right mod
|
393
|
-
d,m=divmod(other); return m
|
394
|
-
end
|
395
|
-
def rmod other
|
396
|
-
# right mod(same as %)
|
397
|
-
d,m=divmod(other); return m
|
398
|
-
end
|
399
|
-
def rmod_D4 other
|
400
|
-
# right mod with D4
|
401
|
-
d,m=divmod_D4(other); return m
|
402
|
-
end
|
403
|
-
def lmod other
|
404
|
-
# left mod
|
405
|
-
d,m=ldivmod(other); return m
|
406
|
-
end
|
407
|
-
def lmod_D4 other
|
408
|
-
# left mod with D4
|
409
|
-
d,m=ldivmod_D4(other); return m
|
410
|
-
end
|
411
|
-
def gcd other
|
412
|
-
a=self; b=other
|
413
|
-
while true
|
414
|
-
if b==0 ; return a;end
|
415
|
-
a=a.rmod_D4(b)
|
416
|
-
if a==0 ; return b;end
|
417
|
-
b=a.lmod_D4(b)
|
418
|
-
end
|
419
|
-
end
|
420
|
-
def orthogonal_split(o)
|
421
|
-
# [q1,q2]. q = q1 + q2 such that q1 parallel to o, and q2 orthogonal to o.
|
422
|
-
q1 = o * dot_product(o); q2=self-q1; return q1,q2
|
423
|
-
end
|
458
|
+
# Exponential and logarithmic functions
|
459
|
+
def exp
|
460
|
+
# e^(r+uv)=exp(r)(cos(v)+u*sin(v))
|
461
|
+
if is_real?; return Quaternion(Math::exp(@re)); end
|
462
|
+
vec=self.vector; v=vec.abs; u = vec/v;
|
463
|
+
Math::exp(@re)*(Math::cos(v)+u*Math::sin(v))
|
464
|
+
end
|
465
|
+
def log
|
466
|
+
# log(r+uv)=1/2 log(r^2+v^2)+u atan(v/r)
|
467
|
+
if is_real?;
|
468
|
+
if @re>=0; return Quaternion(Math::log(@re));
|
469
|
+
else return Quaternion(Math::log(-@re),Math::PI,0,0);
|
470
|
+
end
|
471
|
+
end
|
472
|
+
vec=self.vector; v=vec.abs; u = vec/v;
|
473
|
+
Math::log(self.abs2.to_f)/2+u*Math::atan2( v, @re)
|
474
|
+
end
|
475
|
+
def ** other
|
476
|
+
# q1^q2 = exp((log q1)*q2)
|
477
|
+
if other.kind_of?(Quaternion); ((self.log)*other).exp
|
478
|
+
elsif other.kind_of?(Complex); ((self.log)*other).exp
|
479
|
+
elsif other.kind_of?(Integer);
|
480
|
+
if other==0; return One;
|
481
|
+
elsif other>0;
|
482
|
+
x = self; q = x; n = other - 1
|
483
|
+
while n != 0
|
484
|
+
while (d, m = n.divmod(2); m == 0); x = x*x; n = d; end
|
485
|
+
q *= x; n -= 1
|
486
|
+
end
|
487
|
+
return q
|
488
|
+
else return self.inverse**(-other)
|
489
|
+
end
|
490
|
+
elsif Quaternion::generic?(other); ((self.log)*other).exp
|
491
|
+
else x, y = other.coerce(self); x ** y
|
492
|
+
end;
|
493
|
+
end
|
494
|
+
def sqrt; self**(0.5); end
|
495
|
+
def sinh; e=exp; return (e-e.inverse)/2; end
|
496
|
+
def cosh; e=exp; return (e+e.inverse)/2; end
|
497
|
+
def tanh; e=exp; e=e*e; return (e-1)/(e+1); end
|
498
|
+
# Trigonometric functions
|
499
|
+
def sin
|
500
|
+
# sin(r+uv)=sin r cosh v + u cos r sinh v
|
501
|
+
vec=self.vector; v=vec.abs; if v==0; return Quaternion(Math::sin(@re)); end
|
502
|
+
u = vec/v; e=Math::exp(v); er=1/e; c=e+er; s=e-er
|
503
|
+
(Math::sin(@re)*c+u*Math::cos(@re)*s)/2
|
504
|
+
end
|
505
|
+
def cos
|
506
|
+
# cos(r+uv)=cos r cosh v - u sin r sinh v
|
507
|
+
vec=self.vector; v=vec.abs; if v==0; return Quaternion(Math::cos(@re)); end
|
508
|
+
u = vec/v; e=Math::exp(v); er=1/e; c=e+er; s=e-er
|
509
|
+
(Math::cos(@re)*c-u*Math::sin(@re)*s)/2
|
510
|
+
end
|
511
|
+
def tan
|
512
|
+
vec=self.vector; v=vec.abs; if v==0; return Quaternion(Math::tan(@re)); end
|
513
|
+
u = vec/v; e=Math::exp(v); er=1/e; c=e+er; s=e-er
|
514
|
+
co=Math::cos(@re); si=Math::sin(@re); (si*c+u*co*s)/(co*c-u*si*s)
|
515
|
+
end
|
424
516
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
end
|
439
|
-
vec=self.vector; v=vec.abs; u = vec/v;
|
440
|
-
Math::log(self.abs2.to_f)/2+u*Math::atan2( v, @re)
|
441
|
-
end
|
442
|
-
def ** other
|
443
|
-
# q1^q2 = exp((log q1)*q2)
|
444
|
-
if other.kind_of?(Quaternion); ((self.log)*other).exp
|
445
|
-
elsif other.kind_of?(Complex); ((self.log)*other).exp
|
446
|
-
elsif other.kind_of?(Integer);
|
447
|
-
if other==0; return One;
|
448
|
-
elsif other>0;
|
449
|
-
x = self; q = x; n = other - 1
|
450
|
-
while n != 0
|
451
|
-
while (d, m = n.divmod(2); m == 0); x = x*x; n = d; end
|
452
|
-
q *= x; n -= 1
|
453
|
-
end
|
454
|
-
return q
|
455
|
-
else return self.inverse**(-other)
|
456
|
-
end
|
457
|
-
elsif Quaternion::generic?(other); ((self.log)*other).exp
|
458
|
-
else x, y = other.coerce(self); x ** y
|
459
|
-
end;
|
460
|
-
end
|
461
|
-
def sqrt; self**(0.5); end
|
462
|
-
def sinh; e=exp; return (e-e.inverse)/2; end
|
463
|
-
def cosh; e=exp; return (e+e.inverse)/2; end
|
464
|
-
def tanh; e=exp; e=e*e; return (e-1)/(e+1); end
|
465
|
-
# Trigonometric functions
|
466
|
-
def sin
|
467
|
-
# sin(r+uv)=sin r cosh v + u cos r sinh v
|
468
|
-
vec=self.vector; v=vec.abs; if v==0; return Quaternion(Math::sin(@re)); end
|
469
|
-
u = vec/v; e=Math::exp(v); er=1/e; c=e+er; s=e-er
|
470
|
-
(Math::sin(@re)*c+u*Math::cos(@re)*s)/2
|
471
|
-
end
|
472
|
-
def cos
|
473
|
-
# cos(r+uv)=cos r cosh v - u sin r sinh v
|
474
|
-
vec=self.vector; v=vec.abs; if v==0; return Quaternion(Math::cos(@re)); end
|
475
|
-
u = vec/v; e=Math::exp(v); er=1/e; c=e+er; s=e-er
|
476
|
-
(Math::cos(@re)*c-u*Math::sin(@re)*s)/2
|
477
|
-
end
|
478
|
-
def tan
|
479
|
-
vec=self.vector; v=vec.abs; if v==0; return Quaternion(Math::tan(@re)); end
|
480
|
-
u = vec/v; e=Math::exp(v); er=1/e; c=e+er; s=e-er
|
481
|
-
co=Math::cos(@re); si=Math::sin(@re); (si*c+u*co*s)/(co*c-u*si*s)
|
482
|
-
end
|
517
|
+
# Inverse trigonometric functions
|
518
|
+
def asin
|
519
|
+
# asin q = -u log(uq+sqrt(1-q^2))
|
520
|
+
q=self; u=unit_vector; -u*((u*q+(1-q*q).sqrt).log)
|
521
|
+
end
|
522
|
+
def acos
|
523
|
+
# acos q = -u log(q+sqrt(q^2-1))
|
524
|
+
q=self; u=unit_vector; -u*((q+(q*q-1).sqrt).log)
|
525
|
+
end
|
526
|
+
def atan
|
527
|
+
# atan q = u/2 log( (u+q)/(u-q) )
|
528
|
+
q=self; u=q.unit_vector; u*((u+q)/(u-q)).log/2
|
529
|
+
end
|
483
530
|
|
484
|
-
# Inverse trigonometric functions
|
485
|
-
def asin
|
486
|
-
# asin q = -u log(uq+sqrt(1-q^2))
|
487
|
-
q=self; u=unit_vector; -u*((u*q+(1-q*q).sqrt).log)
|
488
|
-
end
|
489
|
-
def acos
|
490
|
-
# acos q = -u log(q+sqrt(q^2-1))
|
491
|
-
q=self; u=unit_vector; -u*((q+(q*q-1).sqrt).log)
|
492
|
-
end
|
493
|
-
def atan
|
494
|
-
# atan q = u/2 log( (u+q)/(u-q) )
|
495
|
-
q=self; u=q.unit_vector; u*((u+q)/(u-q)).log/2
|
496
|
-
end
|
497
531
|
|
532
|
+
def hash; @re^@im^@jm^@km; end
|
498
533
|
|
499
|
-
|
534
|
+
def inspect
|
535
|
+
sprintf("Quaternion(%s,%s,%s,%s)",
|
536
|
+
@re.inspect, @im.inspect, @jm.inspect, @km.inspect)
|
537
|
+
end
|
538
|
+
def to_s
|
539
|
+
s=""
|
540
|
+
if @re!=0; s=@re.to_s; end
|
541
|
+
if @im!=0;
|
542
|
+
if s==""; s=sprintf("%si", @im);
|
543
|
+
else if @im>0; s=sprintf("%s+%si",s,@im); else s=sprintf("%s-%si",s,-@im); end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
if @jm!=0;
|
547
|
+
if s==""; s=sprintf("%sj", @jm);
|
548
|
+
else if @jm>0; s=sprintf("%s+%sj",s,@jm); else s=sprintf("%s-%sj",s,-@jm); end
|
549
|
+
end
|
550
|
+
end
|
551
|
+
if @km!=0;
|
552
|
+
if s==""; s=sprintf("%sk", @km);
|
553
|
+
else if @km>0; s=sprintf("%s+%sk",s,@km); else s=sprintf("%s-%sk",s,-@km); end
|
554
|
+
end
|
555
|
+
end
|
556
|
+
if s=="" ; s="0"; end;
|
557
|
+
return s
|
558
|
+
end
|
500
559
|
|
501
|
-
def inspect
|
502
|
-
sprintf("Quaternion(%s,%s,%s,%s)",
|
503
|
-
@re.inspect, @im.inspect, @jm.inspect, @km.inspect)
|
504
|
-
end
|
505
|
-
def to_s
|
506
|
-
s=""
|
507
|
-
if @re!=0; s=@re.to_s; end
|
508
|
-
if @im!=0;
|
509
|
-
if s==""; s=sprintf("%si", @im);
|
510
|
-
else if @im>0; s=sprintf("%s+%si",s,@im); else s=sprintf("%s-%si",s,-@im); end
|
511
|
-
end
|
512
|
-
end
|
513
|
-
if @jm!=0;
|
514
|
-
if s==""; s=sprintf("%sj", @jm);
|
515
|
-
else if @jm>0; s=sprintf("%s+%sj",s,@jm); else s=sprintf("%s-%sj",s,-@jm); end
|
516
|
-
end
|
517
|
-
end
|
518
|
-
if @km!=0;
|
519
|
-
if s==""; s=sprintf("%sk", @km);
|
520
|
-
else if @km>0; s=sprintf("%s+%sk",s,@km); else s=sprintf("%s-%sk",s,-@km); end
|
521
|
-
end
|
522
|
-
end
|
523
|
-
if s=="" ; s="0"; end;
|
524
|
-
return s
|
525
|
-
end
|
526
|
-
|
527
560
|
end # Quaternion
|