Float32Array.hx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js.lib;
  23. import js.lib.intl.NumberFormat.NumberFormatOptions;
  24. /**
  25. The `Float32Array` typed array represents an array of 32-bit floating point numbers
  26. (corresponding to the C float data type) in the platform byte order. If control over byte order is
  27. needed, use `DataView` instead. The contents are initialized to `0`. Once established, you can
  28. reference elements in the array using the object's methods, or using standard array index
  29. syntax (that is, using bracket notation)
  30. Documentation [Float32Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  31. **/
  32. @:native("Float32Array")
  33. extern class Float32Array implements ArrayBufferView implements ArrayAccess<Float> {
  34. /**
  35. Returns a number value of the element size. 4 in the case of an `Float32Array`.
  36. */
  37. static final BYTES_PER_ELEMENT:Int;
  38. /**
  39. Creates a new `Float32Array` from an array-like or iterable object. See also [Array.from()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from).
  40. */
  41. @:overload(function(source:{}, ?mapFn:(value:Float) -> Int, ?thisArg:Any):Float32Array {})
  42. @:pure static function from(source:{}, ?mapFn:(value:Float, index:Int) -> Int, ?thisArg:Any):Float32Array;
  43. /**
  44. Creates a new `Float32Array` with a variable number of arguments. See also [Array.of()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of).
  45. */
  46. @:pure static function of(elements:haxe.extern.Rest<Dynamic>):Float32Array;
  47. /**
  48. Returns a number value of the element size.
  49. */
  50. @:native("BYTES_PER_ELEMENT")
  51. final BYTES_PER_ELEMENT_:Int;
  52. /**
  53. Returns the `ArrayBuffer` referenced by the `Float32Array` Fixed at construction time and thus read only.
  54. */
  55. final buffer:ArrayBuffer;
  56. /**
  57. Returns the length (in bytes) of the `Float32Array` from the start of its `ArrayBuffer`. Fixed at construction time and thus read only.
  58. */
  59. final byteLength:Int;
  60. /**
  61. Returns the offset (in bytes) of the `Float32Array` from the start of its `ArrayBuffer`. Fixed at construction time and thus read only.
  62. */
  63. final byteOffset:Int;
  64. /**
  65. Returns the number of elements hold in the `Float32Array`. Fixed at construction time and thus read only.
  66. */
  67. final length:Int;
  68. /** @throws DOMError */
  69. @:overload(function(length:Int):Void {})
  70. @:overload(function(object:{}):Void {})
  71. @:pure function new(buffer:ArrayBuffer, ?byteOffset:Int, ?length:Int):Void;
  72. /**
  73. Copies a sequence of array elements within the array.
  74. See also [Array.prototype.copyWithin()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin).
  75. */
  76. function copyWithin(target:Int, start:Int, ?end:Int):Float32Array;
  77. /**
  78. Returns a new Array Iterator object that contains the key/value pairs for each index in the array.
  79. See also [Array.prototype.entries()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries).
  80. */
  81. @:pure function entries():js.lib.Iterator<KeyValue<Int, Float>>;
  82. /**
  83. Tests whether all elements in the array pass the test provided by a function.
  84. See also [Array.prototype.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every).
  85. */
  86. @:overload(function(callback:(currentValue:Float) -> Bool, ?thisArg:Any):Bool {})
  87. @:overload(function(callback:(currentValue:Float, index:Int) -> Bool, ?thisArg:Any):Bool {})
  88. function every(callback:(currentValue:Float, index:Int, array:Float32Array) -> Bool, ?thisArg:Any):Bool;
  89. /**
  90. Fills all the elements of an array from a start index to an end index with a static value.
  91. See also [Array.prototype.fill()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill).
  92. */
  93. function fill(value:Float, ?start:Int, ?end:Int):Float32Array;
  94. /**
  95. Creates a new array with all of the elements of this array for which the provided filtering function returns true.
  96. See also [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).
  97. */
  98. @:overload(function(callback:(element:Float) -> Bool, ?thisArg:Any):Float32Array {})
  99. @:overload(function(callback:(element:Float, index:Int) -> Bool, ?thisArg:Any):Float32Array {})
  100. function filter(callback:(element:Float, index:Int, array:Float32Array) -> Bool, ?thisArg:Any):Float32Array;
  101. /**
  102. Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found.
  103. See also [Array.prototype.find()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find).
  104. */
  105. @:overload(function(callback:(element:Float) -> Bool, ?thisArg:Any):Null<Int> {})
  106. @:overload(function(callback:(element:Float, index:Int) -> Bool, ?thisArg:Any):Null<Int> {})
  107. function find(callback:(element:Float, index:Int, array:Float32Array) -> Bool, ?thisArg:Any):Null<Int>;
  108. /**
  109. Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found.
  110. See also [Array.prototype.findIndex()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex).
  111. */
  112. @:overload(function(callback:(element:Float) -> Bool, ?thisArg:Any):Int {})
  113. @:overload(function(callback:(element:Float, index:Int) -> Bool, ?thisArg:Any):Int {})
  114. function findIndex(callback:(element:Float, index:Int, array:Float32Array) -> Bool, ?thisArg:Any):Int;
  115. /**
  116. Calls a function for each element in the array.
  117. See also [Array.prototype.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach).
  118. */
  119. @:overload(function(callback:(element:Float) -> Void, ?thisArg:Any):Void {})
  120. @:overload(function(callback:(element:Float, index:Int) -> Void, ?thisArg:Any):Void {})
  121. function forEach(callback:(element:Float, index:Int, array:Float32Array) -> Void, ?thisArg:Any):Void;
  122. /**
  123. Determines whether a typed array includes a certain element, returning true or false as appropriate.
  124. See also [Array.prototype.includes()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes).
  125. */
  126. @:pure function includes(searchElement:Float, ?fromIndex:Int):Bool;
  127. /**
  128. Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
  129. See also [Array.prototype.indexOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf).
  130. */
  131. @:pure function indexOf(searchElement:Float, ?fromIndex:Int):Int;
  132. /**
  133. Joins all elements of an array into a string.
  134. See also [Array.prototype.join()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join).
  135. */
  136. @:pure function join(?separator:String):String;
  137. /**
  138. Returns a new Array Iterator that contains the keys for each index in the array.
  139. See also [Array.prototype.keys()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys).
  140. */
  141. @:pure function keys():js.lib.Iterator<Int>;
  142. /**
  143. Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
  144. See also [Array.prototype.lastIndexOf()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf).
  145. */
  146. @:pure function lastIndexOf(searchElement:Float, ?fromIndex:Int):Int;
  147. /**
  148. Creates a new array with the results of calling a provided function on every element in this array.
  149. See also [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map).
  150. */
  151. @:overload(function(callback:(element:Float) -> Float, ?thisArg:Any):Float32Array {})
  152. @:overload(function(callback:(element:Float, index:Int) -> Float, ?thisArg:Any):Float32Array {})
  153. function map(callback:(element:Float, index:Int, array:Float32Array) -> Float, ?thisArg:Any):Float32Array;
  154. /**
  155. Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
  156. See also [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
  157. */
  158. @:overload(function<T>(callback:(previousValue:T, currentValue:Float) -> T, initialValue:T):T {})
  159. @:overload(function<T>(callback:(previousValue:T, currentValue:Float, index:Int) -> T, initialValue:T):T {})
  160. @:overload(function(callbackfn:(previousValue:Float, currentValue:Float) -> Int):Float {})
  161. @:overload(function(callbackfn:(previousValue:Float, currentValue:Float, index:Int) -> Int):Float {})
  162. @:overload(function(callbackfn:(previousValue:Float, currentValue:Float, index:Int, array:Float32Array) -> Int):Float {})
  163. function reduce<T>(callback:(previousValue:T, currentValue:Float, index:Int, array:Float32Array) -> T, initialValue:T):T;
  164. /**
  165. Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
  166. See also [Array.prototype.reduceRight()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight).
  167. */
  168. @:overload(function<T>(callback:(previousValue:T, currentValue:Float) -> T, initialValue:T):T {})
  169. @:overload(function<T>(callback:(previousValue:T, currentValue:Float, index:Int) -> T, initialValue:T):T {})
  170. @:overload(function(callbackfn:(previousValue:Float, currentValue:Float) -> Int):Float {})
  171. @:overload(function(callbackfn:(previousValue:Float, currentValue:Float, index:Int) -> Int):Float {})
  172. @:overload(function(callbackfn:(previousValue:Float, currentValue:Float, index:Int, array:Float32Array) -> Int):Float {})
  173. function reduceRight<T>(callback:(previousValue:T, currentValue:Float, index:Int, array:Float32Array) -> T, initialValue:T):T;
  174. /**
  175. Reverses the order of the elements of an array — the first becomes the last, and the last becomes the first.
  176. See also [Array.prototype.reverse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse).
  177. */
  178. function reverse():Float32Array;
  179. /**
  180. Stores multiple values in the typed array, reading input values from a specified array.
  181. */
  182. @:overload(function(array:Int8Array, ?offset:Int):Void {})
  183. @:overload(function(array:Uint8Array, ?offset:Int):Void {})
  184. @:overload(function(array:Uint8ClampedArray, ?offset:Int):Void {})
  185. @:overload(function(array:Int16Array, ?offset:Int):Void {})
  186. @:overload(function(array:Uint16Array, ?offset:Int):Void {})
  187. @:overload(function(array:Int32Array, ?offset:Int):Void {})
  188. @:overload(function(array:Uint32Array, ?offset:Int):Void {})
  189. @:overload(function(array:Float32Array, ?offset:Int):Void {})
  190. @:overload(function(array:Float64Array, ?offset:Int):Void {})
  191. @:overload(function(array:Array<Int>, ?offset:Int):Void {})
  192. function set(array:Array<Float>, ?offset:Int):Void;
  193. /**
  194. Extracts a section of an array and returns a new array.
  195. See also [Array.prototype.slice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice).
  196. */
  197. @:pure function slice(?start:Int, ?end:Int):Float32Array;
  198. /**
  199. Returns true if at least one element in this array satisfies the provided testing function.
  200. See also [Array.prototype.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
  201. */
  202. @:overload(function(callback:(element:Float) -> Bool, ?thisArg:Any):Bool {})
  203. @:overload(function(callback:(element:Float, index:Int) -> Bool, ?thisArg:Any):Bool {})
  204. function some(callback:(element:Float, index:Int, array:Float32Array) -> Bool, ?thisArg:Any):Bool;
  205. /**
  206. Sorts the elements of an array in place and returns the array.
  207. See also [Array.prototype.sort()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).
  208. */
  209. function sort(?compareFn:(x:Float, y:Float) -> Int):Float32Array;
  210. /**
  211. Returns a new TypedArray from the given start and end element index.
  212. */
  213. @:pure function subarray(?begin:Int, ?end:Int):Float32Array;
  214. /**
  215. Returns a new Array Iterator object that contains the values for each index in the array.
  216. See also [Array.prototype.values()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values).
  217. */
  218. @:pure function values():js.lib.Iterator<Float>;
  219. /**
  220. Returns a string representing the array and its elements.
  221. See also [Array.prototype.toString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString).
  222. */
  223. @:pure function toLocaleString(?locales:String, ?options:NumberFormatOptions):String;
  224. /**
  225. Returns a string representing the array and its elements.
  226. See also [Array.prototype.toString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString).
  227. */
  228. @:pure function toString():String;
  229. }