| 1 | package Acme::MITHALDU::XSGrabBag; | ||
| 2 | use strictures; | ||
| 3 | use Exporter 'import'; | ||
| 4 | use Acme::MITHALDU::XSGrabBag::Inline (); | ||
| 5 | |||
| 6 | our $VERSION = '1.161260'; # VERSION | ||
| 7 | |||
| 8 | # ABSTRACT: a bunch of XS math functions i'm not sure where to shove yet | ||
| 9 | |||
| 10 | # | ||
| 11 | # This file is part of Acme-MITHALDU-XSGrabBag | ||
| 12 | # | ||
| 13 | # | ||
| 14 | # Christian Walde has dedicated the work to the Commons by waiving all of his | ||
| 15 | # or her rights to the work worldwide under copyright law and all related or | ||
| 16 | # neighboring legal rights he or she had in the work, to the extent allowable by | ||
| 17 | # law. | ||
| 18 | # | ||
| 19 | # Works under CC0 do not require attribution. When citing the work, you should | ||
| 20 | # not imply endorsement by the author. | ||
| 21 | # | ||
| 22 | |||
| 23 | our @EXPORT_OK = qw( | ||
| 24 | mix | ||
| 25 | deg2rad | ||
| 26 | rad2deg | ||
| 27 | dot2_product | ||
| 28 | ); | ||
| 29 | |||
| 30 | Acme::MITHALDU::XSGrabBag::Inline->import( | ||
| 31 | C => join "\n", | ||
| 32 | _mix(), | ||
| 33 | _deg2rad(), | ||
| 34 | _rad2deg(), | ||
| 35 | _dot2_product(), | ||
| 36 | ); | ||
| 37 | |||
| 38 | |||
| 39 | sub _mix { | ||
| 40 | <<'...'; | ||
| 41 | int mix(int a, int b, int c) { | ||
| 42 | a -= b; a -= c; a ^= (c>>13); | ||
| 43 | b -= c; b -= a; b ^= (a<<8); | ||
| 44 | c -= a; c -= b; c ^= (b>>13); | ||
| 45 | a -= b; a -= c; a ^= (c>>12); | ||
| 46 | b -= c; b -= a; b ^= (a<<16); | ||
| 47 | c -= a; c -= b; c ^= (b>>5); | ||
| 48 | a -= b; a -= c; a ^= (c>>3); | ||
| 49 | b -= c; b -= a; b ^= (a<<10); | ||
| 50 | c -= a; c -= b; c ^= (b>>15); | ||
| 51 | return c; | ||
| 52 | } | ||
| 53 | ... | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub _deg2rad { | ||
| 58 | <<'...'; | ||
| 59 | float deg2rad(float degrees) { | ||
| 60 | return 0.0174532925 * degrees; | ||
| 61 | } | ||
| 62 | ... | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | sub _rad2deg { | ||
| 67 | <<'...'; | ||
| 68 | float rad2deg(float radians) { | ||
| 69 | return 57.2957795786 * radians; | ||
| 70 | } | ||
| 71 | ... | ||
| 72 | } | ||
| 73 | |||
| 74 | |||
| 75 | sub _dot2_product { | ||
| 76 | <<'...'; | ||
| 77 | int dot2_product( int xa, int ya, int xb, int yb ) { | ||
| 78 | int sum = 0; | ||
| 79 | sum += xa * xb; | ||
| 80 | sum += ya * yb; | ||
| 81 | return sum; | ||
| 82 | } | ||
| 83 | ... | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; | ||
| 87 | |||
| 88 | __END__ |