# gl-cross
**Repository Path**: nodets/gl-cross
## Basic Information
- **Project Name**: gl-cross
- **Description**: 3D cross product library for JavaScript/TypeScript, supporting ESM, CommonJS, and IIFE formats. Optimized for both regular arrays and `Float64Array` with zero memory allocation in critical paths.
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-10-19
- **Last Updated**: 2025-10-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# gl-cross
A high-performance 3D cross product library for JavaScript/TypeScript, supporting ESM, CommonJS, and IIFE formats. Optimized for both regular arrays and `Float64Array`and `Float32Array` with zero memory allocation in critical paths.
## Features
- **Dual APIs**: `cross` (for regular arrays) and `cross64` (for `Float64Array`)and `cross32` (for `Float32Array`).
- **Zero Allocation**: Reuses output vectors to avoid garbage collection.
- **Multi-Format Support**: ESM, CommonJS, and IIFE (global variable: `crossproduct`).
- **Type Safety**: Strict TypeScript types (included in distribution).
## Installation
### via npm
```bash
npm install gl-cross
```
### via CDN (IIFE)
```html
```
## Usage
### 1. ESM (ES Modules)
```typescript
// Import both functions
import { cross, cross64,cross32 } from 'gl-cross';
// Regular array usage
const outArray: [number, number, number] = [0, 0, 0];
cross(outArray, [1, 2, 3], [4, 5, 6]);
console.log(outArray); // [-3, 6, -3]
// Float64Array usage (high performance)
const out64 = new Float64Array(3);
cross64(out64, new Float64Array([1, 2, 3]), new Float64Array([4, 5, 6]));
console.log(Array.from(out64)); // [-3, 6, -3]
// Float32Array usage (high performance)
const out32 = new Float32Array(3);
cross64(out64, new Float32Array([1, 2, 3]), new Float32Array([4, 5, 6]));
console.log(Array.from(out32)); // [-3, 6, -3]
```
### 2. CommonJS
```javascript
const { cross, cross64 } = require('gl-cross');
// Regular array example
const out = [0, 0, 0];
cross(out, [1, 0, 0], [0, 1, 0]);
console.log(out); // [0, 0, 1]
```
### 3. IIFE (Global Variable)
```html
```
## API
### `cross(out, a, b)`
Computes the cross product of two 3D arrays.
- **Parameters**:
- `out`: `[number, number, number]` — Output array (will be overwritten, required).
- `a`: `[number, number, number]` — First input vector.
- `b`: `[number, number, number]` — Second input vector.
- **Returns**: The `out` array (same reference as input).
### `cross64(out, a, b)`
Computes the cross product of two 3D `Float64Array` vectors (optimized for performance).
- **Parameters**:
- `out`: `Float64Array` — Output buffer (length 3, will be overwritten, required).
- `a`: `Float64Array` — First input vector (length 3).
- `b`: `Float64Array` — Second input vector (length 3).
- **Returns**: The `out` buffer (same reference as input).
### `cross32(out, a, b)`
Computes the cross product of two 3D `Float32Array` vectors (optimized for performance).
- **Parameters**:
- `out`: `Float32Array` — Output buffer (length 3, will be overwritten, required).
- `a`: `Float32Array` — First input vector (length 3).
- `b`: `Float32Array` — Second input vector (length 3).
- **Returns**: The `out` buffer (same reference as input).
## Module Formats
- **ESM**: `dist/esm/index.js` (for modern bundlers like Webpack, Rollup).
- **CommonJS**: `dist/cjs/index.js` (for Node.js).
- **IIFE**: `dist/iife/gl-cross.js` (global variable: `crossproduct`).
Minified version: `dist/iife/gl-cross.min.js`.
## Performance
- **Operations per Second**: ~180 million (for `cross64` in Node.js 20+).
- **Memory Efficiency**: `cross64` uses 50% less memory than array-based approaches (24 bytes per vector vs. ~48 bytes).
- **GC Friendly**: No temporary allocations when reusing `out` vectors.