web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
3.2 KiB

  1. # hoopy
  2. [![Build status](https://gitlab.com/philbooth/hoopy/badges/master/pipeline.svg)](https://gitlab.com/philbooth/hoopy/pipelines)
  3. [![Package status](https://img.shields.io/npm/v/hoopy.svg)](https://www.npmjs.com/package/hoopy)
  4. [![Downloads](https://img.shields.io/npm/dm/hoopy.svg)](https://www.npmjs.com/package/hoopy)
  5. [![License](https://img.shields.io/npm/l/hoopy.svg)](https://opensource.org/licenses/MIT)
  6. Like an array, but rounder.
  7. * [Huh?](#huh)
  8. * [What's it useful for?](#whats-it-useful-for)
  9. * [How do I install it?](#how-do-i-install-it)
  10. * [How do I use it?](#how-do-i-use-it)
  11. * [Loading the library](#loading-the-library)
  12. * [Creating arrays](#creating-arrays)
  13. * [Accessing array items](#accessing-array-items)
  14. * [Growing the array](#growing-the-array)
  15. * [Is there a change log?](#is-there-a-change-log)
  16. * [How do I set up the dev environment?](#how-do-i-set-up-the-dev-environment)
  17. * [What license is it released under?](#what-license-is-it-released-under)
  18. ## Huh?
  19. Hoopy is a circular array
  20. data type.
  21. It extends `Array`
  22. so that out-of-bounds indices
  23. wrap back round
  24. to the start of the array
  25. (or if they're negative indices,
  26. they wrap back round
  27. to the end of the array).
  28. ## What's it useful for?
  29. If you want a fixed-length buffer
  30. for streamed I/O,
  31. Hoopy can do that for you.
  32. ## How do I install it?
  33. Via `npm`:
  34. ```
  35. npm i hoopy --save
  36. ```
  37. Or if you just want the git repo:
  38. ```
  39. git clone git@gitlab.com:philbooth/hoopy.git
  40. ```
  41. ## How do I use it?
  42. ### Loading the library
  43. ```js
  44. const Hoopy = require('hoopy');
  45. ```
  46. ### Creating arrays
  47. ```js
  48. const hoopy = new Hoopy(10);
  49. assert(Array.isArray(hoopy));
  50. ```
  51. You must pass
  52. a `size` argument
  53. to the `Hoopy` constructor,
  54. otherwise it will throw.
  55. ### Accessing array items
  56. ```js
  57. for (let i = 0; i < hoopy.length; ++i) {
  58. hoopy[i] = i;
  59. console.log(hoopy[i]);
  60. }
  61. ```
  62. You can read and write array items
  63. using square brackets for indexing
  64. as you would with a normal array.
  65. However, if you write to
  66. an out-of-bounds index,
  67. it will not increase
  68. the length of the array.
  69. Instead the index is applied
  70. modulo the array length,
  71. wrapping back round to the start.
  72. Negative indices work in reverse,
  73. wrapping back round to the end
  74. of the array.
  75. The methods
  76. `push`, `pop`, `shift` and `unshift`
  77. will throw if called.
  78. Future versions of the library
  79. may implement sane behaviour
  80. for them.
  81. All of the other `Array` methods
  82. work normally.
  83. ### Growing the array
  84. ```js
  85. hoopy.grow(50);
  86. ```
  87. The `grow` method
  88. adds items to the array.
  89. It takes one argument,
  90. which is the number
  91. of items to grow the array by.
  92. The new length of the array
  93. will be the old length
  94. plus the number you pass to `grow`.
  95. If the current state of the array
  96. includes overflowed indices,
  97. `grow` will take care
  98. to move those items
  99. in to the freshly-created
  100. available space,
  101. so that the correct order is maintained
  102. for your data.
  103. The caller is responsible
  104. for ensuring they don't overwrite
  105. unprocessed items.
  106. If you need to increase
  107. the size of the array,
  108. you must call `grow`.
  109. ## Is there a change log?
  110. [Yes](CHANGELOG.md).
  111. ## How do I set up the dev environment?
  112. To install the dependencies:
  113. ```
  114. npm i
  115. ```
  116. To run the tests:
  117. ```
  118. npm t
  119. ```
  120. To lint the code:
  121. ```
  122. npm run lint
  123. ```
  124. ## What license is it released under?
  125. [MIT](LICENSE).