Skip to content

paintvecSimple 2D Vector Math for JavaScript

A lightweight, immutable library for 2D geometry operations with TypeScript support

Quick Example

typescript
import { Vec2, Rect, Transform } from 'paintvec'

// Create vectors
const pos = new Vec2(100, 200)
const pos2 = pos.add(new Vec2(50, 30)).mul(new Vec2(10, 20))

// Work with rectangles  
const rect = new Rect(new Vec2(0), new Vec2(100, 200))
const rect2 = new Rect(new Vec2(50, 50), new Vec2(100, 200))
const intersection = Rect.intersection(rect, rect2)

// Apply transforms
const transform = Transform.translate(new Vec2(100, 200))
  .merge(Transform.scale(new Vec2(2)))
  .merge(Transform.rotate(Math.PI / 4))

const transformed = pos.transform(transform)

Installation

sh
npm install paintvec
sh
yarn add paintvec
sh
pnpm add paintvec

Released under the MIT License.