coordinate-converter

1.0.2 • Public • Published

coordinate-converter

Convert between relative and cartesian coordinates using RelativePoint and CartesianPoint classes.

const { RelativePoint, CartesianPoint } = require('coordinate-converter');

let viewport = {
	width: 500,
	height: 500
};

let topRightQuadrant = new RelativePoint(
	375,
	125,
	viewport.width,
	viewport.height
);

console.log(topRightQuadrant, topRightQuadrant.ToCartesian());
// RelativePoint { x: 375, y: 125, w: 500, h: 500 } CartesianPoint { x: 125, y: 125, w: 500, h: 500 }

viewport.width = 1920;
viewport.height = 1080;

let bottomLeftMargin = new CartesianPoint(
	-940,
	-520,
	viewport.width,
	viewport.height
);

console.log(bottomLeftMargin, bottomLeftMargin.ToRelative());
// CartesianPoint { x: -940, y: -520, w: 1920, h: 1080 } RelativePoint { x: 20, y: 1060, w: 1920, h: 1080 }

Package Sidebar

Install

npm i coordinate-converter

Weekly Downloads

4

Version

1.0.2

License

ISC

Unpacked Size

3.82 kB

Total Files

4

Last publish

Collaborators

  • ahrizona