facets 1.3.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (589) hide show
  1. data/{doc/AUTHORS → AUTHORS} +12 -3
  2. data/README +35 -29
  3. data/WARNING +56 -0
  4. data/demo/annotation/demo_annotation.rb +22 -0
  5. data/demo/ansicolor/cdiff.rb +20 -0
  6. data/demo/ansicolor/example.rb +82 -0
  7. data/demo/io-reactor/chatserver.rb +347 -0
  8. data/demo/lisp/game.rb +47 -0
  9. data/lib/facet/all.rb +1 -0
  10. data/lib/facet/annattr.rb +1 -0
  11. data/lib/facet/class/to_proc.rb +1 -0
  12. data/lib/facet/cookie.rb +1 -0
  13. data/lib/facet/dir/self/descend.rb +1 -0
  14. data/lib/facet/enumerable/count.rb +1 -0
  15. data/lib/facet/hash/to_proc.rb +1 -0
  16. data/lib/facet/hashbuilder.rb +1 -0
  17. data/lib/facet/http.rb +1 -0
  18. data/lib/facet/httpaccess.rb +1 -0
  19. data/lib/facet/kernel/__get__.rb +1 -0
  20. data/lib/facet/kernel/__set__.rb +1 -0
  21. data/lib/facet/kernel/cache.rb +1 -0
  22. data/lib/facet/kernel/respond.rb +1 -0
  23. data/lib/facet/lazy.rb +1 -0
  24. data/lib/facet/module/class.rb +1 -0
  25. data/lib/facet/module/nodef.rb +1 -0
  26. data/lib/facet/opencascade.rb +1 -0
  27. data/lib/facet/pqueue.rb +1 -0
  28. data/lib/facet/taskable.rb +1 -0
  29. data/lib/facets.rb +98 -37
  30. data/lib/facets/core/all.rb +5 -0
  31. data/lib/facets/core/class/to_proc.rb +25 -0
  32. data/lib/facets/core/dir/self/ascend.rb +2 -1
  33. data/lib/facets/core/dir/self/descend.rb +11 -0
  34. data/lib/facets/core/enumerable/accumulate.rb +2 -2
  35. data/lib/facets/core/enumerable/count.rb +54 -0
  36. data/lib/facets/core/enumerable/cross.rb +3 -0
  37. data/lib/facets/core/enumerable/graph.rb +8 -4
  38. data/lib/facets/core/enumerable/self/cross.rb +11 -5
  39. data/lib/facets/core/hash/to_proc.rb +34 -0
  40. data/lib/facets/core/hash/traverse.rb +10 -5
  41. data/lib/facets/core/kernel/__class__.rb +1 -1
  42. data/lib/facets/core/kernel/__get__.rb +5 -0
  43. data/lib/facets/core/kernel/__set__.rb +2 -0
  44. data/lib/facets/core/kernel/assign_from.rb +1 -1
  45. data/lib/facets/core/kernel/assign_with.rb +11 -3
  46. data/lib/facets/core/kernel/bool.rb +1 -1
  47. data/lib/facets/core/kernel/cache.rb +31 -0
  48. data/lib/facets/core/kernel/demo.rb +4 -0
  49. data/lib/facets/core/kernel/get_by_id.rb +1 -0
  50. data/lib/facets/core/kernel/in.rb +1 -1
  51. data/lib/facets/core/kernel/instance_assign.rb +2 -3
  52. data/lib/facets/core/kernel/method.rb +25 -7
  53. data/lib/facets/core/kernel/methods.rb +1 -1
  54. data/lib/facets/core/kernel/new.rb +1 -1
  55. data/lib/facets/core/kernel/object_class.rb +1 -1
  56. data/lib/facets/core/kernel/object_hexid.rb +1 -1
  57. data/lib/facets/core/kernel/own.rb +1 -1
  58. data/lib/facets/core/kernel/require_all.rb +1 -0
  59. data/lib/facets/core/kernel/require_esc.rb +4 -2
  60. data/lib/facets/core/kernel/require_facet.rb +2 -0
  61. data/lib/facets/core/kernel/require_local.rb +1 -0
  62. data/lib/facets/core/kernel/respond.rb +14 -0
  63. data/lib/facets/core/kernel/send_as.rb +1 -1
  64. data/lib/facets/core/kernel/silence_warnings.rb +1 -1
  65. data/lib/facets/core/kernel/singleton.rb +3 -1
  66. data/lib/facets/core/matchdata/matchtree.rb +13 -3
  67. data/lib/facets/core/module/class.rb +3 -0
  68. data/lib/facets/core/module/integrate.rb +31 -4
  69. data/lib/facets/core/module/{undef.rb → nodef.rb} +8 -3
  70. data/lib/facets/core/module/revisal.rb +5 -5
  71. data/lib/facets/more/annattr.rb +147 -0
  72. data/lib/facets/more/annotation.rb +32 -136
  73. data/lib/facets/more/ansicode.rb +89 -100
  74. data/lib/facets/more/aspects.rb +28 -0
  75. data/lib/facets/more/association.rb +88 -47
  76. data/lib/facets/more/basicobject.rb +51 -33
  77. data/lib/facets/more/bbcode.rb +21 -34
  78. data/lib/facets/more/binaryreader.rb +62 -33
  79. data/lib/facets/more/bitmask.rb +24 -24
  80. data/lib/facets/more/blankslate.rb +4 -0
  81. data/lib/facets/more/builderobject.rb +16 -20
  82. data/lib/facets/more/bytes.rb +43 -24
  83. data/lib/facets/more/classinherit.rb +15 -31
  84. data/lib/facets/more/classmethods.rb +19 -29
  85. data/lib/facets/more/cloneable.rb +42 -30
  86. data/lib/facets/more/consoleapp.rb +42 -22
  87. data/lib/facets/more/cookie.rb +565 -0
  88. data/lib/facets/more/coroutine.rb +17 -21
  89. data/lib/facets/more/crypt.rb +33 -12
  90. data/lib/facets/more/dictionary.rb +27 -36
  91. data/lib/facets/more/downloader.rb +21 -17
  92. data/lib/facets/more/elementor.rb +22 -0
  93. data/lib/facets/more/enumerablepass.rb +19 -27
  94. data/lib/facets/more/expirable.rb +18 -28
  95. data/lib/facets/more/filelist.rb +33 -32
  96. data/lib/facets/more/floatstring.rb +31 -40
  97. data/lib/facets/more/functor.rb +15 -25
  98. data/lib/facets/more/hashbuilder.rb +76 -0
  99. data/lib/facets/more/heap.rb +29 -36
  100. data/lib/facets/more/htmlbuilder.rb +22 -24
  101. data/lib/facets/more/htmlhelper.rb +89 -0
  102. data/lib/facets/more/http.rb +570 -0
  103. data/lib/facets/more/httpaccess.rb +1608 -0
  104. data/lib/facets/more/inheritor.rb +29 -21
  105. data/lib/facets/more/interval.rb +21 -25
  106. data/lib/facets/more/ioredirect.rb +21 -25
  107. data/lib/facets/more/json.rb +27 -17
  108. data/lib/facets/more/lazy.rb +238 -0
  109. data/lib/facets/more/lisp.rb +24 -27
  110. data/lib/facets/more/lisp_format.rb +93 -85
  111. data/lib/facets/more/lrucache.rb +17 -27
  112. data/lib/facets/more/mathconstants.rb +22 -40
  113. data/lib/facets/more/methodprobe.rb +56 -61
  114. data/lib/facets/more/mock.rb +24 -17
  115. data/lib/facets/more/multipliers.rb +21 -17
  116. data/lib/facets/more/multiton.rb +18 -24
  117. data/lib/facets/more/nackclass.rb +17 -21
  118. data/lib/facets/more/nilcomparable.rb +28 -30
  119. data/lib/facets/more/nullclass.rb +16 -15
  120. data/lib/facets/more/one.rb +94 -58
  121. data/lib/facets/more/opencascade.rb +187 -0
  122. data/lib/facets/more/openobject.rb +89 -66
  123. data/lib/facets/more/orderedhash.rb +4 -0
  124. data/lib/facets/more/ormsupport.rb +18 -29
  125. data/lib/facets/more/overload.rb +39 -3
  126. data/lib/facets/more/paramix.rb +16 -24
  127. data/lib/facets/more/pathlist.rb +17 -23
  128. data/lib/facets/more/pool.rb +21 -29
  129. data/lib/facets/more/pqueue.rb +190 -0
  130. data/lib/facets/more/preinitialize.rb +17 -18
  131. data/lib/facets/more/progressbar.rb +19 -15
  132. data/lib/facets/more/promoteself.rb +17 -21
  133. data/lib/facets/more/quaternion.rb +379 -346
  134. data/lib/facets/more/recorder.rb +15 -20
  135. data/lib/facets/more/reference.rb +25 -22
  136. data/lib/facets/more/rexmlbuilder.rb +21 -6
  137. data/lib/facets/more/rtals.rb +27 -24
  138. data/lib/facets/more/semaphore.rb +15 -28
  139. data/lib/facets/more/snapshot.rb +45 -41
  140. data/lib/facets/more/stateparser.rb +25 -35
  141. data/lib/facets/more/statichash.rb +37 -29
  142. data/lib/facets/more/syncarray.rb +18 -26
  143. data/lib/facets/more/synchash.rb +17 -26
  144. data/lib/facets/more/system.rb +25 -17
  145. data/lib/facets/more/tagiterator.rb +15 -39
  146. data/lib/facets/more/taskable.rb +417 -0
  147. data/lib/facets/more/timer.rb +22 -26
  148. data/lib/facets/more/times.rb +23 -23
  149. data/lib/facets/more/tracepoint.rb +25 -24
  150. data/lib/facets/more/tuple.rb +25 -42
  151. data/lib/facets/more/typecast.rb +27 -29
  152. data/lib/facets/more/uninheritable.rb +15 -22
  153. data/lib/facets/more/units.rb +23 -29
  154. data/lib/facets/more/xmlbuilder.rb +20 -22
  155. data/lib/facets/more/xmlhelper.rb +18 -21
  156. data/lib/facets/more/xoxo.rb +23 -11
  157. data/lib/facets/more/yamlstruct.rb +25 -22
  158. data/test/lib/facets/core/array/test_at_rand.rb +1 -1
  159. data/test/lib/facets/core/array/test_delete_unless.rb +1 -1
  160. data/test/lib/facets/core/array/test_delete_values.rb +1 -1
  161. data/test/lib/facets/core/array/test_delete_values_at.rb +1 -1
  162. data/test/lib/facets/core/array/test_first.rb +1 -1
  163. data/test/lib/facets/core/array/test_head.rb +1 -1
  164. data/test/lib/facets/core/array/test_last_index.rb +1 -1
  165. data/test/lib/facets/core/array/test_merge.rb +1 -1
  166. data/test/lib/facets/core/array/test_mid.rb +1 -1
  167. data/test/lib/facets/core/array/test_middle.rb +1 -1
  168. data/test/lib/facets/core/array/test_op_fetch.rb +1 -1
  169. data/test/lib/facets/core/array/test_op_store.rb +1 -1
  170. data/test/lib/facets/core/array/test_pick.rb +1 -1
  171. data/test/lib/facets/core/array/test_pos.rb +1 -1
  172. data/test/lib/facets/core/array/test_pot.rb +1 -1
  173. data/test/lib/facets/core/array/test_pull.rb +1 -1
  174. data/test/lib/facets/core/array/test_rand_index.rb +1 -1
  175. data/test/lib/facets/core/array/test_rand_subset.rb +1 -1
  176. data/test/lib/facets/core/array/test_range.rb +1 -1
  177. data/test/lib/facets/core/array/test_rotate.rb +1 -1
  178. data/test/lib/facets/core/array/test_select.rb +1 -1
  179. data/test/lib/facets/core/array/test_shuffle.rb +1 -1
  180. data/test/lib/facets/core/array/test_thru.rb +1 -1
  181. data/test/lib/facets/core/array/test_to_b.rb +1 -1
  182. data/test/lib/facets/core/array/test_to_h.rb +1 -1
  183. data/test/lib/facets/core/array/test_to_hash.rb +1 -1
  184. data/test/lib/facets/core/binding/self/test_of_caller.rb +1 -1
  185. data/test/lib/facets/core/binding/test___LINE__.rb +1 -1
  186. data/test/lib/facets/core/binding/test_call_stack.rb +1 -1
  187. data/test/lib/facets/core/binding/test_called.rb +1 -1
  188. data/test/lib/facets/core/binding/test_caller.rb +1 -1
  189. data/test/lib/facets/core/binding/test_defined.rb +1 -1
  190. data/test/lib/facets/core/binding/test_eval.rb +1 -1
  191. data/test/lib/facets/core/binding/test_local_variables.rb +1 -1
  192. data/test/lib/facets/core/binding/test_method_name.rb +1 -1
  193. data/test/lib/facets/core/binding/test_op_fetch.rb +1 -1
  194. data/test/lib/facets/core/binding/test_op_store.rb +1 -1
  195. data/test/lib/facets/core/binding/test_self.rb +1 -1
  196. data/test/lib/facets/core/class/test_cattr.rb +1 -1
  197. data/test/lib/facets/core/class/test_descendents.rb +1 -1
  198. data/test/lib/facets/core/class/test_method_name.rb +1 -1
  199. data/test/lib/facets/core/class/test_remove_descendents.rb +1 -1
  200. data/test/lib/facets/core/class/test_unix_path.rb +1 -1
  201. data/test/lib/facets/core/comparable/test_at_least.rb +1 -1
  202. data/test/lib/facets/core/comparable/test_clip.rb +1 -1
  203. data/test/lib/facets/core/comparable/test_cmp.rb +1 -1
  204. data/test/lib/facets/core/continuation/self/test_create.rb +1 -1
  205. data/test/lib/facets/core/date/test_days_in_month.rb +1 -1
  206. data/test/lib/facets/core/date/test_days_of_month.rb +1 -1
  207. data/test/lib/facets/core/date/test_stamp.rb +1 -1
  208. data/test/lib/facets/core/date/test_to_date.rb +1 -1
  209. data/test/lib/facets/core/date/test_to_s.rb +1 -1
  210. data/test/lib/facets/core/date/test_to_time.rb +1 -1
  211. data/test/lib/facets/core/dir/self/test_ancestor.rb +1 -1
  212. data/test/lib/facets/core/dir/self/test_ascend.rb +1 -1
  213. data/test/lib/facets/core/enumerable/self/test_combinations.rb +1 -1
  214. data/test/lib/facets/core/enumerable/self/test_cross.rb +1 -1
  215. data/test/lib/facets/core/enumerable/test_collect_with_index.rb +1 -1
  216. data/test/lib/facets/core/enumerable/test_commonality.rb +1 -1
  217. data/test/lib/facets/core/enumerable/test_compact_collect.rb +1 -1
  218. data/test/lib/facets/core/enumerable/test_count.rb +38 -0
  219. data/test/lib/facets/core/enumerable/test_cross.rb +1 -1
  220. data/test/lib/facets/core/enumerable/test_each_combination.rb +1 -1
  221. data/test/lib/facets/core/enumerable/test_each_pair.rb +1 -1
  222. data/test/lib/facets/core/enumerable/test_each_slice.rb +1 -1
  223. data/test/lib/facets/core/enumerable/test_each_unique_pair.rb +1 -1
  224. data/test/lib/facets/core/enumerable/test_entropy.rb +1 -1
  225. data/test/lib/facets/core/enumerable/test_every.rb +1 -1
  226. data/test/lib/facets/core/enumerable/test_ew.rb +1 -1
  227. data/test/lib/facets/core/enumerable/test_filter_collect.rb +1 -1
  228. data/test/lib/facets/core/enumerable/test_find_collisions.rb +1 -1
  229. data/test/lib/facets/core/enumerable/test_frequency.rb +1 -1
  230. data/test/lib/facets/core/enumerable/test_graph.rb +1 -1
  231. data/test/lib/facets/core/enumerable/test_ideal_entropy.rb +1 -1
  232. data/test/lib/facets/core/enumerable/test_none.rb +1 -1
  233. data/test/lib/facets/core/enumerable/test_occur.rb +1 -1
  234. data/test/lib/facets/core/enumerable/test_one.rb +1 -1
  235. data/test/lib/facets/core/enumerable/test_op_pow.rb +1 -1
  236. data/test/lib/facets/core/enumerable/test_partition_by.rb +1 -1
  237. data/test/lib/facets/core/enumerable/test_permute.rb +1 -1
  238. data/test/lib/facets/core/enumerable/test_probability.rb +1 -1
  239. data/test/lib/facets/core/enumerable/test_to_h.rb +1 -1
  240. data/test/lib/facets/core/enumerable/test_uniq_by.rb +1 -1
  241. data/test/lib/facets/core/file/self/test_create.rb +1 -1
  242. data/test/lib/facets/core/file/self/test_open_as_string.rb +1 -1
  243. data/test/lib/facets/core/file/self/test_read_list.rb +1 -1
  244. data/test/lib/facets/core/file/self/test_sanitize.rb +1 -1
  245. data/test/lib/facets/core/file/self/test_split_all.rb +1 -1
  246. data/test/lib/facets/core/float/test_round_at.rb +1 -1
  247. data/test/lib/facets/core/float/test_round_to.rb +1 -1
  248. data/test/lib/facets/core/hash/self/test_zipnew.rb +1 -1
  249. data/test/lib/facets/core/hash/test_alias.rb +1 -1
  250. data/test/lib/facets/core/hash/test_assert_has_keys.rb +1 -1
  251. data/test/lib/facets/core/hash/test_assert_has_only_keys.rb +1 -1
  252. data/test/lib/facets/core/hash/test_at.rb +1 -1
  253. data/test/lib/facets/core/hash/test_collate.rb +1 -1
  254. data/test/lib/facets/core/hash/test_each.rb +1 -1
  255. data/test/lib/facets/core/hash/test_each_with_index.rb +1 -1
  256. data/test/lib/facets/core/hash/test_each_with_key.rb +1 -1
  257. data/test/lib/facets/core/hash/test_graph.rb +1 -1
  258. data/test/lib/facets/core/hash/test_has_keys.rb +1 -1
  259. data/test/lib/facets/core/hash/test_has_only_keys.rb +1 -1
  260. data/test/lib/facets/core/hash/test_inverse.rb +1 -1
  261. data/test/lib/facets/core/hash/test_keys_to_s.rb +1 -1
  262. data/test/lib/facets/core/hash/test_keys_to_sym.rb +1 -1
  263. data/test/lib/facets/core/hash/test_op_fetch.rb +1 -1
  264. data/test/lib/facets/core/hash/test_op_lshift.rb +1 -1
  265. data/test/lib/facets/core/hash/test_rand_key.rb +1 -1
  266. data/test/lib/facets/core/hash/test_rand_pair.rb +1 -1
  267. data/test/lib/facets/core/hash/test_rand_value.rb +1 -1
  268. data/test/lib/facets/core/hash/test_replace_each.rb +1 -1
  269. data/test/lib/facets/core/hash/test_shuffle.rb +1 -1
  270. data/test/lib/facets/core/hash/test_slice.rb +1 -1
  271. data/test/lib/facets/core/hash/test_swap.rb +1 -1
  272. data/test/lib/facets/core/hash/test_swapkey.rb +1 -1
  273. data/test/lib/facets/core/hash/test_to_h.rb +1 -1
  274. data/test/lib/facets/core/hash/test_to_ostruct.rb +1 -1
  275. data/test/lib/facets/core/hash/test_to_ostruct_recurse.rb +1 -1
  276. data/test/lib/facets/core/hash/test_traverse.rb +1 -1
  277. data/test/lib/facets/core/hash/test_update_each.rb +1 -1
  278. data/test/lib/facets/core/hash/test_update_keys.rb +1 -1
  279. data/test/lib/facets/core/hash/test_update_values.rb +1 -1
  280. data/test/lib/facets/core/hash/test_weave.rb +1 -1
  281. data/test/lib/facets/core/integer/test_factorial.rb +1 -1
  282. data/test/lib/facets/core/integer/test_multiple.rb +1 -1
  283. data/test/lib/facets/core/integer/test_ordinal.rb +1 -1
  284. data/test/lib/facets/core/integer/test_times_collect.rb +1 -1
  285. data/test/lib/facets/core/kernel/test___class__.rb +1 -1
  286. data/test/lib/facets/core/kernel/test_as.rb +1 -1
  287. data/test/lib/facets/core/kernel/test_assign_from.rb +1 -1
  288. data/test/lib/facets/core/kernel/test_assign_with.rb +1 -1
  289. data/test/lib/facets/core/kernel/test_bool.rb +1 -1
  290. data/test/lib/facets/core/kernel/test_bug.rb +1 -1
  291. data/test/lib/facets/core/kernel/test_call_stack.rb +1 -1
  292. data/test/lib/facets/core/kernel/test_called.rb +1 -1
  293. data/test/lib/facets/core/kernel/test_constant.rb +1 -1
  294. data/test/lib/facets/core/kernel/test_copy.rb +1 -1
  295. data/test/lib/facets/core/kernel/test_deep_copy.rb +1 -1
  296. data/test/lib/facets/core/kernel/test_demo.rb +1 -1
  297. data/test/lib/facets/core/kernel/test_fn.rb +1 -1
  298. data/test/lib/facets/core/kernel/test_generate_method_name.rb +1 -1
  299. data/test/lib/facets/core/kernel/test_get_by_id.rb +1 -1
  300. data/test/lib/facets/core/kernel/test_here.rb +1 -1
  301. data/test/lib/facets/core/kernel/test_in.rb +1 -1
  302. data/test/lib/facets/core/kernel/test_maybe.rb +1 -1
  303. data/test/lib/facets/core/kernel/test_metaclass.rb +1 -1
  304. data/test/lib/facets/core/kernel/test_method.rb +1 -1
  305. data/test/lib/facets/core/kernel/test_methodname.rb +1 -1
  306. data/test/lib/facets/core/kernel/test_methods.rb +1 -1
  307. data/test/lib/facets/core/kernel/test_new.rb +1 -1
  308. data/test/lib/facets/core/kernel/test_object_class.rb +1 -1
  309. data/test/lib/facets/core/kernel/test_object_hexid.rb +1 -1
  310. data/test/lib/facets/core/kernel/test_require_all.rb +1 -1
  311. data/test/lib/facets/core/kernel/test_require_esc.rb +1 -1
  312. data/test/lib/facets/core/kernel/test_require_facet.rb +1 -1
  313. data/test/lib/facets/core/kernel/test_resc.rb +1 -1
  314. data/test/lib/facets/core/kernel/test_returning.rb +1 -1
  315. data/test/lib/facets/core/kernel/test_send_as.rb +1 -1
  316. data/test/lib/facets/core/kernel/test_set_from.rb +1 -1
  317. data/test/lib/facets/core/kernel/test_set_with.rb +1 -1
  318. data/test/lib/facets/core/kernel/test_silently.rb +1 -1
  319. data/test/lib/facets/core/kernel/test_singleton.rb +1 -1
  320. data/test/lib/facets/core/kernel/test_superior.rb +1 -1
  321. data/test/lib/facets/core/kernel/test_supermethod.rb +1 -1
  322. data/test/lib/facets/core/kernel/test_this.rb +1 -1
  323. data/test/lib/facets/core/kernel/test_to_b.rb +1 -1
  324. data/test/lib/facets/core/kernel/test_to_bool.rb +1 -1
  325. data/test/lib/facets/core/kernel/test_uri.rb +1 -1
  326. data/test/lib/facets/core/kernel/test_val.rb +1 -1
  327. data/test/lib/facets/core/kernel/test_with_accessor.rb +1 -1
  328. data/test/lib/facets/core/matchdata/test_match.rb +1 -1
  329. data/test/lib/facets/core/matchdata/test_matchtree.rb +7 -2
  330. data/test/lib/facets/core/module/test_abstract.rb +1 -1
  331. data/test/lib/facets/core/module/test_alias_module_function.rb +1 -1
  332. data/test/lib/facets/core/module/test_ancestor.rb +1 -1
  333. data/test/lib/facets/core/module/test_basename.rb +1 -1
  334. data/test/lib/facets/core/module/test_by_name.rb +1 -1
  335. data/test/lib/facets/core/module/test_clone_using.rb +1 -1
  336. data/test/lib/facets/core/module/test_dirname.rb +1 -1
  337. data/test/lib/facets/core/module/test_equate_on.rb +1 -1
  338. data/test/lib/facets/core/module/test_generate_instance_method_name.rb +1 -1
  339. data/test/lib/facets/core/module/test_include_as.rb +1 -1
  340. data/test/lib/facets/core/module/test_inherit.rb +1 -1
  341. data/test/lib/facets/core/module/test_initializer.rb +1 -1
  342. data/test/lib/facets/core/module/test_instance_methods.rb +1 -1
  343. data/test/lib/facets/core/module/test_integrate.rb +1 -1
  344. data/test/lib/facets/core/module/test_memoize.rb +1 -1
  345. data/test/lib/facets/core/module/test_modspace.rb +1 -1
  346. data/test/lib/facets/core/module/test_namespace.rb +1 -1
  347. data/test/lib/facets/core/module/test_nesting.rb +1 -1
  348. data/test/lib/facets/core/module/{test_undef.rb → test_nodef.rb} +5 -5
  349. data/test/lib/facets/core/module/test_on_included.rb +1 -1
  350. data/test/lib/facets/core/module/test_redef.rb +1 -1
  351. data/test/lib/facets/core/module/test_redefine_method.rb +1 -1
  352. data/test/lib/facets/core/module/test_redirect.rb +1 -1
  353. data/test/lib/facets/core/module/test_redirect_method.rb +1 -1
  354. data/test/lib/facets/core/module/test_remove.rb +1 -1
  355. data/test/lib/facets/core/module/test_rename.rb +1 -1
  356. data/test/lib/facets/core/module/test_rename_method.rb +1 -1
  357. data/test/lib/facets/core/module/test_revisal.rb +1 -1
  358. data/test/lib/facets/core/module/test_shadow_method.rb +1 -1
  359. data/test/lib/facets/core/module/test_sort_on.rb +1 -1
  360. data/test/lib/facets/core/module/test_this.rb +1 -1
  361. data/test/lib/facets/core/module/test_wrap.rb +1 -1
  362. data/test/lib/facets/core/module/test_wrap_method.rb +1 -1
  363. data/test/lib/facets/core/nilclass/test_blank.rb +1 -1
  364. data/test/lib/facets/core/nilclass/test_empty.rb +1 -1
  365. data/test/lib/facets/core/nilclass/test_include.rb +1 -1
  366. data/test/lib/facets/core/nilclass/test_op_fetch.rb +1 -1
  367. data/test/lib/facets/core/nilclass/test_size.rb +1 -1
  368. data/test/lib/facets/core/nilclass/test_to_h.rb +1 -1
  369. data/test/lib/facets/core/numeric/test_approx.rb +1 -1
  370. data/test/lib/facets/core/numeric/test_ceil_multiple.rb +1 -1
  371. data/test/lib/facets/core/numeric/test_succ.rb +1 -1
  372. data/test/lib/facets/core/numeric/test_to_b.rb +1 -1
  373. data/test/lib/facets/core/ostruct/test___merge__.rb +1 -1
  374. data/test/lib/facets/core/ostruct/test___update__.rb +1 -1
  375. data/test/lib/facets/core/ostruct/test_op_fetch.rb +1 -1
  376. data/test/lib/facets/core/ostruct/test_op_store.rb +1 -1
  377. data/test/lib/facets/core/proc/test_compose.rb +1 -1
  378. data/test/lib/facets/core/proc/test_to_method.rb +1 -1
  379. data/test/lib/facets/core/range/test_to_r.rb +1 -1
  380. data/test/lib/facets/core/range/test_to_range.rb +1 -1
  381. data/test/lib/facets/core/range/test_umbrella.rb +1 -1
  382. data/test/lib/facets/core/range/test_within.rb +1 -1
  383. data/test/lib/facets/core/regexp/test_arity.rb +1 -1
  384. data/test/lib/facets/core/regexp/test_to_re.rb +1 -1
  385. data/test/lib/facets/core/regexp/test_to_regexp.rb +1 -1
  386. data/test/lib/facets/core/string/self/test_interpolate.rb +1 -1
  387. data/test/lib/facets/core/string/self/test_patterns.rb +1 -1
  388. data/test/lib/facets/core/string/self/test_rand_letter.rb +1 -1
  389. data/test/lib/facets/core/string/test_align_center.rb +1 -1
  390. data/test/lib/facets/core/string/test_at_rand.rb +1 -1
  391. data/test/lib/facets/core/string/test_basename.rb +1 -1
  392. data/test/lib/facets/core/string/test_blank.rb +1 -1
  393. data/test/lib/facets/core/string/test_bracket.rb +1 -1
  394. data/test/lib/facets/core/string/test_camelcase.rb +1 -1
  395. data/test/lib/facets/core/string/test_camelize.rb +1 -1
  396. data/test/lib/facets/core/string/test_capitalized.rb +1 -1
  397. data/test/lib/facets/core/string/test_chars.rb +1 -1
  398. data/test/lib/facets/core/string/test_cmp.rb +1 -1
  399. data/test/lib/facets/core/string/test_demodulize.rb +1 -1
  400. data/test/lib/facets/core/string/test_downcase.rb +1 -1
  401. data/test/lib/facets/core/string/test_dresner.rb +1 -1
  402. data/test/lib/facets/core/string/test_each_char.rb +1 -1
  403. data/test/lib/facets/core/string/test_each_word.rb +1 -1
  404. data/test/lib/facets/core/string/test_first.rb +1 -1
  405. data/test/lib/facets/core/string/test_fold.rb +1 -1
  406. data/test/lib/facets/core/string/test_frequency.rb +1 -1
  407. data/test/lib/facets/core/string/test_humanize.rb +1 -1
  408. data/test/lib/facets/core/string/test_indent.rb +1 -1
  409. data/test/lib/facets/core/string/test_index_all.rb +1 -1
  410. data/test/lib/facets/core/string/test_last.rb +1 -1
  411. data/test/lib/facets/core/string/test_line_wrap.rb +1 -1
  412. data/test/lib/facets/core/string/test_lines.rb +1 -1
  413. data/test/lib/facets/core/string/test_lowercase.rb +1 -1
  414. data/test/lib/facets/core/string/test_margin.rb +1 -1
  415. data/test/lib/facets/core/string/test_methodize.rb +1 -1
  416. data/test/lib/facets/core/string/test_modulize.rb +1 -1
  417. data/test/lib/facets/core/string/test_mscan.rb +1 -1
  418. data/test/lib/facets/core/string/test_natcmp.rb +1 -1
  419. data/test/lib/facets/core/string/test_nchar.rb +1 -1
  420. data/test/lib/facets/core/string/test_pathize.rb +1 -1
  421. data/test/lib/facets/core/string/test_pop.rb +1 -1
  422. data/test/lib/facets/core/string/test_pot.rb +1 -1
  423. data/test/lib/facets/core/string/test_probability.rb +1 -1
  424. data/test/lib/facets/core/string/test_push.rb +1 -1
  425. data/test/lib/facets/core/string/test_quote.rb +1 -1
  426. data/test/lib/facets/core/string/test_rand_byte.rb +1 -1
  427. data/test/lib/facets/core/string/test_rand_index.rb +1 -1
  428. data/test/lib/facets/core/string/test_range.rb +1 -1
  429. data/test/lib/facets/core/string/test_range_all.rb +1 -1
  430. data/test/lib/facets/core/string/test_range_of_line.rb +1 -1
  431. data/test/lib/facets/core/string/test_regesc.rb +1 -1
  432. data/test/lib/facets/core/string/test_shatter.rb +1 -1
  433. data/test/lib/facets/core/string/test_shift.rb +1 -1
  434. data/test/lib/facets/core/string/test_shuffle.rb +1 -1
  435. data/test/lib/facets/core/string/test_similarity.rb +1 -1
  436. data/test/lib/facets/core/string/test_singular.rb +1 -1
  437. data/test/lib/facets/core/string/test_soundex.rb +1 -1
  438. data/test/lib/facets/core/string/test_succ.rb +1 -1
  439. data/test/lib/facets/core/string/test_to_a.rb +1 -1
  440. data/test/lib/facets/core/string/test_to_b.rb +1 -1
  441. data/test/lib/facets/core/string/test_to_const.rb +1 -1
  442. data/test/lib/facets/core/string/test_to_date.rb +1 -1
  443. data/test/lib/facets/core/string/test_to_proc.rb +1 -1
  444. data/test/lib/facets/core/string/test_to_re.rb +1 -1
  445. data/test/lib/facets/core/string/test_to_time.rb +1 -1
  446. data/test/lib/facets/core/string/test_unix_crypt.rb +1 -1
  447. data/test/lib/facets/core/string/test_unpack.rb +1 -1
  448. data/test/lib/facets/core/string/test_unshift.rb +1 -1
  449. data/test/lib/facets/core/string/test_upcase.rb +1 -1
  450. data/test/lib/facets/core/string/test_whitespace.rb +1 -1
  451. data/test/lib/facets/core/string/test_word_filter.rb +1 -1
  452. data/test/lib/facets/core/string/test_word_wrap.rb +1 -1
  453. data/test/lib/facets/core/string/test_words.rb +1 -1
  454. data/test/lib/facets/core/symbol/test_camelcase.rb +1 -1
  455. data/test/lib/facets/core/symbol/test_camelize.rb +1 -1
  456. data/test/lib/facets/core/symbol/test_capitalize.rb +1 -1
  457. data/test/lib/facets/core/symbol/test_capitalized.rb +1 -1
  458. data/test/lib/facets/core/symbol/test_downcase.rb +1 -1
  459. data/test/lib/facets/core/symbol/test_not.rb +1 -1
  460. data/test/lib/facets/core/symbol/test_pad.rb +1 -1
  461. data/test/lib/facets/core/symbol/test_succ.rb +1 -1
  462. data/test/lib/facets/core/symbol/test_to_const.rb +1 -1
  463. data/test/lib/facets/core/symbol/test_to_proc.rb +1 -1
  464. data/test/lib/facets/core/symbol/test_to_str.rb +1 -1
  465. data/test/lib/facets/core/symbol/test_underscore.rb +1 -1
  466. data/test/lib/facets/core/symbol/test_upcase.rb +1 -1
  467. data/test/lib/facets/core/time/test_change.rb +1 -1
  468. data/test/lib/facets/core/time/test_elapse.rb +1 -1
  469. data/test/lib/facets/core/time/test_stamp.rb +1 -1
  470. data/test/lib/facets/core/time/test_to_date.rb +1 -1
  471. data/test/lib/facets/core/time/test_to_s.rb +1 -1
  472. data/test/lib/facets/core/time/test_to_time.rb +1 -1
  473. data/test/lib/facets/more/test_annattr.rb +39 -0
  474. data/test/lib/facets/more/test_annotatedattr.rb +39 -0
  475. data/test/lib/facets/more/test_annotation.rb +1 -22
  476. data/test/lib/facets/more/test_ansicode.rb +1 -1
  477. data/test/lib/facets/more/test_association.rb +6 -1
  478. data/test/lib/facets/more/test_basicobject.rb +1 -1
  479. data/test/lib/facets/more/test_bbcode.rb +1 -1
  480. data/test/lib/facets/more/test_binaryreader.rb +64 -0
  481. data/test/lib/facets/more/test_bitmask.rb +1 -1
  482. data/test/lib/facets/more/test_bytes.rb +1 -1
  483. data/test/lib/facets/more/test_classinherit.rb +1 -1
  484. data/test/lib/facets/more/test_classmethods.rb +1 -1
  485. data/test/lib/facets/more/test_coroutine.rb +1 -1
  486. data/test/lib/facets/more/test_crypt.rb +1 -1
  487. data/test/lib/facets/more/test_dictionary.rb +1 -1
  488. data/test/lib/facets/more/test_elementor.rb +1 -1
  489. data/test/lib/facets/more/test_enumerablepass.rb +1 -1
  490. data/test/lib/facets/more/test_floatstring.rb +1 -1
  491. data/test/lib/facets/more/test_functor.rb +1 -1
  492. data/test/lib/facets/more/test_htmlbuilder.rb +1 -1
  493. data/test/lib/facets/more/test_inheritor.rb +1 -1
  494. data/test/lib/facets/more/test_interval.rb +1 -1
  495. data/test/lib/facets/more/test_json.rb +1 -1
  496. data/test/lib/facets/more/test_lisp.rb +1 -1
  497. data/test/lib/facets/more/test_lisp_format.rb +1 -1
  498. data/test/lib/facets/more/test_lrucache.rb +1 -1
  499. data/test/lib/facets/more/test_mathconstants.rb +1 -1
  500. data/test/lib/facets/more/test_methodprobe.rb +1 -1
  501. data/test/lib/facets/more/test_multipliers.rb +1 -1
  502. data/test/lib/facets/more/test_multiton.rb +1 -1
  503. data/test/lib/facets/more/test_nackclass.rb +1 -1
  504. data/test/lib/facets/more/test_nilcomparable.rb +1 -1
  505. data/test/lib/facets/more/test_opencascade.rb +66 -0
  506. data/test/lib/facets/more/test_openobject.rb +14 -2
  507. data/test/lib/facets/more/test_overload.rb +1 -1
  508. data/test/lib/facets/more/test_paramix.rb +1 -1
  509. data/test/lib/facets/more/test_pqueue.rb +39 -0
  510. data/test/lib/facets/more/test_preinitialize.rb +1 -1
  511. data/test/lib/facets/more/test_promoteself.rb +1 -1
  512. data/test/lib/facets/more/test_recorder.rb +1 -1
  513. data/test/lib/facets/more/test_snapshot.rb +1 -1
  514. data/test/lib/facets/more/test_statichash.rb +11 -11
  515. data/test/lib/facets/more/test_syncarray.rb +1 -1
  516. data/test/lib/facets/more/test_synchash.rb +1 -1
  517. data/test/lib/facets/more/test_tagiterator.rb +1 -1
  518. data/test/lib/facets/more/test_taskable.rb +151 -0
  519. data/test/lib/facets/more/test_timer.rb +1 -1
  520. data/test/lib/facets/more/test_times.rb +1 -1
  521. data/test/lib/facets/more/test_tuple.rb +1 -1
  522. data/test/lib/facets/more/test_typecast.rb +1 -1
  523. data/test/lib/facets/more/test_uninheritable.rb +1 -1
  524. data/test/lib/facets/more/test_units.rb +1 -1
  525. data/test/lib/facets/more/test_xmlbuilder.rb +1 -1
  526. data/test/lib/facets/more/test_xmlhelper.rb +1 -1
  527. data/test/lib/facets/more/test_xoxo.rb +1 -1
  528. data/test/lib/facets/more/test_yamlstruct.rb +1 -1
  529. metadata +1243 -1247
  530. data/ProjectInfo +0 -89
  531. data/Rakefile +0 -181
  532. data/doc/CHANGELOG +0 -284
  533. data/doc/TODO +0 -73
  534. data/doc/noauto +0 -63
  535. data/lib/facet/array.rb +0 -1
  536. data/lib/facet/class.rb +0 -1
  537. data/lib/facet/comparable.rb +0 -1
  538. data/lib/facet/continuation.rb +0 -1
  539. data/lib/facet/date.rb +0 -1
  540. data/lib/facet/dir.rb +0 -1
  541. data/lib/facet/enumerable.rb +0 -1
  542. data/lib/facet/file.rb +0 -1
  543. data/lib/facet/fileutils.rb +0 -1
  544. data/lib/facet/float.rb +0 -1
  545. data/lib/facet/gem.rb +0 -1
  546. data/lib/facet/hash.rb +0 -1
  547. data/lib/facet/integer.rb +0 -1
  548. data/lib/facet/kernel.rb +0 -1
  549. data/lib/facet/logger.rb +0 -1
  550. data/lib/facet/matchdata.rb +0 -1
  551. data/lib/facet/module.rb +0 -1
  552. data/lib/facet/module/undef.rb +0 -1
  553. data/lib/facet/nilclass.rb +0 -1
  554. data/lib/facet/numeric.rb +0 -1
  555. data/lib/facet/pathname.rb +0 -1
  556. data/lib/facet/proc.rb +0 -1
  557. data/lib/facet/range.rb +0 -1
  558. data/lib/facet/regexp.rb +0 -1
  559. data/lib/facet/string.rb +0 -1
  560. data/lib/facet/symbol.rb +0 -1
  561. data/lib/facet/time.rb +0 -1
  562. data/lib/facet/unboundmethod.rb +0 -1
  563. data/lib/facets/core/array.rb +0 -35
  564. data/lib/facets/core/class.rb +0 -11
  565. data/lib/facets/core/comparable.rb +0 -5
  566. data/lib/facets/core/continuation.rb +0 -1
  567. data/lib/facets/core/date.rb +0 -6
  568. data/lib/facets/core/dir.rb +0 -4
  569. data/lib/facets/core/enumerable.rb +0 -42
  570. data/lib/facets/core/file.rb +0 -8
  571. data/lib/facets/core/fileutils.rb +0 -8
  572. data/lib/facets/core/float.rb +0 -4
  573. data/lib/facets/core/gem.rb +0 -4
  574. data/lib/facets/core/hash.rb +0 -40
  575. data/lib/facets/core/integer.rb +0 -9
  576. data/lib/facets/core/kernel.rb +0 -69
  577. data/lib/facets/core/logger.rb +0 -2
  578. data/lib/facets/core/matchdata.rb +0 -3
  579. data/lib/facets/core/module.rb +0 -43
  580. data/lib/facets/core/nilclass.rb +0 -9
  581. data/lib/facets/core/numeric.rb +0 -6
  582. data/lib/facets/core/pathname.rb +0 -2
  583. data/lib/facets/core/proc.rb +0 -3
  584. data/lib/facets/core/range.rb +0 -4
  585. data/lib/facets/core/regexp.rb +0 -3
  586. data/lib/facets/core/string.rb +0 -91
  587. data/lib/facets/core/symbol.rb +0 -13
  588. data/lib/facets/core/time.rb +0 -8
  589. 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
- # Ruby License
5
+ # Ruby License
7
6
  #
8
- # This module is free software. You may use, modify, and/or redistribute this
9
- # software under the same terms as Ruby.
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
- # This program is distributed in the hope that it will be useful, but WITHOUT
12
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
- # FOR A PARTICULAR PURPOSE.
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
- # Revision History ::
18
- # --------------------------------------------------------------------------
19
- # 05.10.29 trans Deprecated default_instance_variables.
20
- # 05.08.28 trans Moved default_instance_variables to Module.
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
- #:title: Preinitialize
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-2003 Satoru Takabayashi
5
- # All rights reserved.
3
+ # == Copyright (C) 2001 Satoru Takabayashi
6
4
  #
7
- # This is free software with ABSOLUTELY NO WARRANTY.
5
+ # Ruby License
8
6
  #
9
- # You can redistribute it and/or modify it under the terms
10
- # of Ruby's licence.
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
- # :title: Console Progress Bar
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 fukumoto
3
+ # == Copyright (c) 2005 Thomas Sawyer
5
4
  #
6
- # Ruby License
5
+ # Ruby License
7
6
  #
8
- # This module is free software. You may use, modify, and/or redistribute this
9
- # software under the same terms as Ruby.
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
- # This program is distributed in the hope that it will be useful, but WITHOUT
12
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
- # FOR A PARTICULAR PURPOSE.
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
- # Revision History ::
17
- # --------------------------------------------------------------------------
18
- # 2005-07-10 Trans * Started.
19
- # ==========================================================================
20
- #++
21
-
22
- #:title: PromoteSelf
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
- # K.Kodama 2002,9,23
2
- # This program is distributed freely
3
- # in the sense of GNU General Public License or ruby's.
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
- #warn "This Quaternion class is still very experimental version."
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
- # i^2 = j^2 = k^2 = -1,
15
- # i j = k, j k = i, k i = j,
16
- # j i = -k, k j = -i, i k = -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
- # q=|q|( cos t1 + sin t1 ( i cos t2 + sin t2 ( j cos t3 + k sin t3 ))).
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| is known as the magnitude of the quaternion,
39
- # t1 is the amplitude(or angle),
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
- if a.kind_of?(Quaternion);
193
- a;
194
- elsif a.kind_of?(Complex) and b.kind_of?(Complex);
195
- Quaternion.new(a.real, a.image, b.real, b.image)
196
- elsif a.kind_of?(Complex);
197
- Quaternion.new(a.real, a.image)
198
- else
199
- Quaternion.new(a,b,c,d);
200
- end
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
- attr :re
205
- attr :im
206
- attr :jm
207
- attr :km
208
- def image; return @im; end
209
- def real_part; return @re; end
210
- def real; return @re; end
211
- def to_c; return Complex(@re,@im); end
212
- def to_c2; return Complex(@jm,@km); end
213
- def to_a; return [@re, @im, @jm, @km]; end
214
- def Quaternion::generic?(other)
215
- return (other.kind_of?(Complex) or Complex.generic?(other));
216
- end
217
- def initialize(a=0,b=0,c=0,d=0)
218
- raise "non numeric 1st arg `#{a.inspect}'" if !a.kind_of? Numeric;
219
- raise "non numeric 2nd arg `#{b.inspect}'" if !b.kind_of? Numeric;
220
- raise "non numeric 3rd arg `#{c.inspect}'" if !c.kind_of? Numeric;
221
- raise "non numeric 4th arg `#{d.inspect}'" if !d.kind_of? Numeric;
222
- @re=a; @im=b; @jm=c; @km=d
223
- end
224
- private :initialize
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
- Zero=Quaternion(0)
227
- One=Quaternion(1)
228
- I=Quaternion(0,1)
229
- J=Quaternion(0,0,1)
230
- K=Quaternion(0,0,0,1)
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
- def Quaternion::polar(m,t1=0,t2=0,t3=0)
233
- # q=
234
- # m*cos(t1)
235
- # +m*sin(t1)cos(t2)i
236
- # +m*sin(t1)sin(t2)cos(t3)j
237
- # +m*sin(t1)sin(t2)sin(t3)k
238
- # m is known as the magnitude,
239
- # t1 is the amplitude(or angle) of the quaternion,
240
- # t2 and t3 are the latitude (or co-latitude) and longitude respectively.
241
- if m.kind_of?(Array) and (m.size==4); t1=m[1]; t2=m[2]; t3=m[3]; m=m[0]; end;
242
- s=m
243
- r_part=s*Math.cos(t1); s=s*Math.sin(t1)
244
- i_part=s*Math.cos(t2); s=s*Math.sin(t2)
245
- j_part=s*Math.cos(t3); k_part=s*Math.sin(t3)
246
- new(r_part, i_part, j_part, k_part)
247
- end
248
- def amplitude; Math.atan2(Math.sqrt((@im*@im+@jm*@jm+@km*@km).to_f),@re.to_f); end
249
- def latitude; Math.atan2(Math.sqrt((@jm*@jm+@km*@km).to_f),@im.to_f); end
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
- def round; Quaternion(@re.round,@im.round,@jm.round,@km.round);end
257
- def round_D4
258
- # round to D4 lattice
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
- def is_real?; @im==0 and @jm==0 and @km==0; end
276
- def is_complex?; @jm==0 and @km==0; end
277
- def is_quaternion?; not(is_complex?); end
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
- def vector; Quaternion(0,@im,@jm,@km); end
280
- def is_vector?; @re==0; end
281
- def to_v; return [@im, @jm, @km]; end
282
- def Quaternion::vector(v)
283
- # 3-D vector v=[x,y,z]
284
- Quaternion(0,v[0],v[1],v[2])
285
- end
286
- def unit_vector
287
- if is_real?; return Quaternion(0,1); end
288
- m=Math::sqrt((@im*@im+@jm*@jm+@km*@km).to_f)
289
- Quaternion(0,@im/m,@jm/m,@km/m);
290
- end
291
- def is_unit_vector?; @re==0 and abs2==1; end
292
- def Quaternion::rotation(v,t)
293
- # t-rotatin along the 3-D vector v
294
- (Quaternion::vector(v).unit_vector) * Math::sin(t/2) + Math::cos(t/2)
295
- end
296
- def rotate(r); r * self * r.conjugate / r.abs2; end
297
- def rotate_angle; amplitude/2; end
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
- # Arithmetic
300
- def coerce(other)
301
- if other.kind_of?(Complex); return Quaternion(other), self
302
- elsif Complex::generic?(other); return Quaternion(other), self
303
- else super
304
- end
305
- end
306
- def <=> (other); self.abs <=> other.abs; end
307
- def == (other)
308
- if other.kind_of?(Quaternion)
309
- return (@re==other.re and @im==other.im and @jm==other.jm and @km==other.km)
310
- elsif other.kind_of?(Complex)
311
- @re==other.real and @im==other.image and @jm==0 and @km==0
312
- elsif Complex.generic?(other)
313
- @re==other and @im==0 and @jm==0 and @km==0
314
- else x , y = other.coerce(self); x == y
315
- end
316
- end
317
- def + (other)
318
- if other.kind_of?(Quaternion)
319
- Quaternion(@re+other.re,@im+other.im,@jm+other.jm,@km+other.km)
320
- elsif other.kind_of?(Complex)
321
- Quaternion(@re+other.real,@im+other.image, @jm, @km)
322
- elsif Complex.generic?(other)
323
- Quaternion(@re+other.real,@im, @jm, @km)
324
- else x , y = other.coerce(self); x + y
325
- end
326
- end
327
- def - (other)
328
- if other.kind_of?(Quaternion)
329
- Quaternion(@re-other.re,@im-other.im,@jm-other.jm,@km-other.km)
330
- elsif other.kind_of?(Complex)
331
- Quaternion(@re-other.real,@im-other.image, @jm, @km)
332
- elsif Complex.generic?(other)
333
- Quaternion(@re-other.real,@im, @jm, @km)
334
- else x , y = other.coerce(self); x - y
335
- end
336
- end
337
- def * (other)
338
- if other.kind_of?(Quaternion)
339
- Quaternion(@re*other.re-@im*other.im-@jm*other.jm-@km*other.km,
340
- @re*other.im+@im*other.re+@jm*other.km-@km*other.jm,
341
- @re*other.jm-@im*other.km+@jm*other.re+@km*other.im,
342
- @re*other.km+@im*other.jm-@jm*other.im+@km*other.re)
343
- elsif other.kind_of?(Complex)
344
- Quaternion(@re*other.real - @im*other.image,
345
- @re*other.image + @im*other.real,
346
- @jm*other.real + @km*other.image,
347
- @km*other.real - @jm*other.image)
348
- elsif Complex.generic?(other)
349
- Quaternion(@re * other, @im * other, @jm * other, @km * other)
350
- else x , y = other.coerce(self); x * y
351
- end
352
- end
353
- def dot_product other
354
- (self*other.conjugate).re
355
- end
356
- def cross_product other
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
- # Exponential and logarithmic functions
426
- def exp
427
- # e^(r+uv)=exp(r)(cos(v)+u*sin(v))
428
- if is_real?; return Quaternion(Math::exp(@re)); end
429
- vec=self.vector; v=vec.abs; u = vec/v;
430
- Math::exp(@re)*(Math::cos(v)+u*Math::sin(v))
431
- end
432
- def log
433
- # log(r+uv)=1/2 log(r^2+v^2)+u atan(v/r)
434
- if is_real?;
435
- if @re>=0; return Quaternion(Math::log(@re));
436
- else return Quaternion(Math::log(-@re),Math::PI,0,0);
437
- end
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
- def hash; @re^@im^@jm^@km; end
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