Skip to content
/ vex Public

Your "friendly" helper for performing mathematical operations on vectors.

License

Notifications You must be signed in to change notification settings

uspel/vex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vex

Your "friendly" helper for performing mathematical operations on vectors.

Contents

Features

  • Methods for both mutating and creating new vectors.

Installation

Set up a new creation with the Minepicker Creator CLI and then run the following command to install the latest version of Vex:

minepicker use vex

Vex2

Utilities for two-dimensional vectors.

Vex2 Static Methods

add

Creates a new Vector2 by adding two vectors together.

Vex2.add({ x: 1, y: 1 }, { x: 0, y: 1 });

assign

Creates a new Vector2 by assigning components to a vector.

Vex2.assign({ x: 0, y: 0 }, { y: 1 });

ceil

Creates a new Vector2 by performing a ceiling function on each component of a vector.

Vex2.ceil({ x: 0.2, y: 0.6 });

clamp

Creates a new Vector2 by clamping each component of a vector between those of a minimum and maximum vector.

Vex2.clamp(
  { x: 18, y: 4 },
  { x: 0 }, // Minimum
  { x: 10, y: 10 } // Maximum
);

distance

Calculates the distance between two vectors.

Vex2.distance({ x: 5, y: 0 }, { x: -2, y: 4 });

divide

Creates a new Vector2 by dividing a vector by a scalar value or another vector.

Vex2.divide({ x: 4, y: 8 }, 4);
Vex2.divide({ x: 4, y: 8 }, { x: 4, y: 2 });

dot

Calculates the dot product of two vectors.

Vex2.dot({ x: 5, y: 0 }, { x: -2, y: 4 });

equals

Checks whether two vectors are equal.

Vex2.equals({ x: 5, y: 0 }, { x: -2, y: 4 });

floor

Creates a new Vector2 by performing a floor function on each component of a vector.

Vex2.floor({ x: 0.2, y: 0.6 });

from

Creates a new Vector2 from different data types.

Vex2.from(1, 2);
Vex2.from({ x: 0, y: 1 });
Vex2.from(0);
Vex2.from(Direction.North);
Vex2.from(Direction.North, 5);

lerp

Creates a new Vector2 by using linear interpolation on each component of two vectors.

Vex2.lerp(
  { x: 5, y: 0 }, // Start
  { x: -2, y: 4 }, // End
  0.5 // Interpolant
);

magnitude

Calculates the magnitude of a vector.

Vex2.magnitude({ x: 2, y: 5 });

max

Creates a new Vector2 from the largest values of each component in the provided vectors.

Vex2.max({ x: 5, y: 0 }, { x: -2, y: 4 });

min

Creates a new Vector2 from the smallest values of each component in the provided vectors.

Vex2.min({ x: 5, y: 0 }, { x: -2, y: 4 });

multiply

Creates a new Vector2 by multiplying a vector by a scalar value or another vector.

Vex2.multiply({ x: 4, y: 8 }, 4);
Vex2.multiply({ x: 4, y: 8 }, { x: 4, y: 2 });

normalize

Creates a new Vector2 by normalizing a vector.

Vex2.normalize({ x: 2, y: 5 });

round

Creates a new Vector2 by rounding each component of a vector.

Vex2.round({ x: 0.2, y: 0.6 });

slerp

Creates a new Vector2 by using spherical linear interpolation on each component of two vectors.

Vex2.slerp(
  { x: 5, y: 0 }, // Start
  { x: -2, y: 4 }, // End
  0.5 // Interpolant
);

subtract

Creates a new Vector2 by subtracting the second vector from the first vector.

Vex2.subtract({ x: 1, y: 1 }, { x: 0, y: 1 });

toString

Creates a string representation of a Vector2.

Vex2.toString(
  { x: 0.2, y: 0.6 },
  { fractionDigits: 1 }
);

Vex2 Instance Methods

constructor

Creates a new Vex2 instance from different data types.

const vector = new Vex2(1, 2);
const vector = new Vex2({ x: 0, y: 1 });
const vector = new Vex2(0);
const vector = new Vex2(Direction.Up);
const vector = new Vex2(Direction.Up, 5);

add

Adds another vector to this vector.

vector.add({ x: 0, y: 1 });

assign

Assigns components to this vector.

vector.assign({ y: 1 });

ceil

Performs a ceiling function on each component of this vector.

vector.ceil();

clamp

Clamps all components of this vector between those of a minimum and maximum vector.

vector.clamp(
  { x: 0 }, // Minimum
  { x: 10, y: 10 } // Maximum
);

distance

Calculates the distance between this vector and another vector

vector.distance({ x: -2, y: 4 });

divide

Divides this vector by a scalar value or another vector.

vector.divide(4);
vector.divide({ x: 4, y: 2 });

dot

Calculates the dot product of this vector and another vector.

vector.dot({ x: -2, y: 4 });

equals

Checks whether this vector is equal to another vector.

vector.equals({ x: -2, y: 4 });

floor

Performs a floor function on each component of this vector.

vector.floor();

multiply

Multiplies this vector by a scalar value or another vector.

vector.multiply(4);
vector.multiply({ x: 4, y: 2 });

normalize

Normalizes this vector.

vector.normalize();

round

Rounds each component of this vector.

vector.round();

subtract

Subtracts another vector from this vector

vector.subtract({ x: 0, y: 1 });

toString

Creates a string representation of this vector.

vector.toString({ fractionDigits: 1 });

Vex2 Instance Properties

magnitude

Calculates the magnitude of this vector.

vector.magnitude;

x

The X component of this vector.

vector.x;

y

The Y component of this vector.

vector.y;

Vex3

Utilities for three-dimensional vectors.

Vex3 Static Methods

add

Creates a new Vector3 by adding two vectors together.

Vex3.add(
  { x: 1, y: 1, z: 2 },
  { x: 0, y: 1, z: 5 }
);

assign

Creates a new Vector3 by assigning components to a vector.

Vex3.assign({ x: 0, y: 0, z: 2 }, { y: 1, x: 0 });

ceil

Creates a new Vector3 by performing a ceiling function on each component of a vector.

Vex3.ceil({ x: 0.2, y: 0.6, z: 0.5 });

clamp

Creates a new Vector3 by clamping each component of a vector between those of a minimum and maximum vector.

Vex3.clamp(
  { x: 18, y: 4, z: 0 },
  { x: 0, z: 5 }, // Minimum
  { x: 10, y: 10 } // Maximum
);

distance

Calculates the distance between two vectors.

Vex3.distance(
  { x: 5, y: 0, z: 8 },
  { x: -2, y: 4, z: -12 }
);

divide

Creates a new Vector3 by dividing a vector by a scalar value or another vector.

Vex3.divide({ x: 4, y: 8, z: 18 }, 4);
Vex3.divide(
  { x: 4, y: 8, z: 18 },
  { x: 4, y: 2, z: 3 }
);

dot

Calculates the dot product of two vectors.

Vex3.dot(
  { x: 5, y: 0, z: 8 },
  { x: -2, y: 4, z: -12 }
);

equals

Checks whether two vectors are equal.

Vex3.equals(
  { x: 5, y: 0, z: 8 },
  { x: -2, y: 4, z: -12 }
);

floor

Creates a new Vector3 by performing a floor function on each component of a vector.

Vex3.floor({ x: 0.2, y: 0.6, z: 0.5 });

from

Creates a new Vector3 from different data types.

Vex3.from(1, 2, 3);
Vex3.from({ x: 0, y: 1, z: 5 });
Vex3.from(0);
Vex3.from(Direction.North);
Vex3.from(Direction.North, 5);

lerp

Creates a new Vector3 by using linear interpolation on each component of two vectors.

Vex3.lerp(
  { x: 5, y: 0 }, // Start
  { x: -2, y: 4 }, // End
  0.5 // Interpolant
);

magnitude

Calculates the magnitude of a vector.

Vex3.magnitude({ x: 2, y: 5, z: -3 });

max

Creates a new Vector3 from the largest values of each component in the provided vectors.

Vex3.max(
  { x: 5, y: 0, z: 8 },
  { x: -2, y: 4, z: -12 }
);

min

Creates a new Vector3 from the smallest values of each component in the provided vectors.

Vex3.min(
  { x: 5, y: 0, z: 8 },
  { x: -2, y: 4, z: -12 }
);

multiply

Creates a new Vector3 by multiplying a vector by a scalar value or another vector.

Vex3.multiply({ x: 4, y: 8, z: 18 }, 4);
Vex3.multiply(
  { x: 4, y: 8, z: 18 },
  { x: 4, y: 2, z: 3 }
);

normalize

Creates a new Vector3 by normalizing a vector.

Vex3.normalize({ x: 2, y: 5, z: -3 });

round

Creates a new Vector3 by rounding each component of a vector.

Vex3.round({ x: 0.2, y: 0.6, z: 0.5 });

slerp

Creates a new Vector3 by using spherical linear interpolation on each component of two vectors.

Vex3.slerp(
  { x: 5, y: 0 }, // Start
  { x: -2, y: 4 }, // End
  0.5 // Interpolant
);

subtract

Creates a new Vector3 by subtracting the second vector from the first vector.

Vex3.subtract(
  { x: 1, y: 1, z: 2 },
  { x: 0, y: 1, z: 5 }
);

toString

Creates a string representation of a Vector3.

Vex3.toString(
  { x: 0.2, y: 0.6, z: 0.5 },
  { fractionDigits: 1 }
);

Vex3 Instance Methods

constructor

Creates a new Vex3 instance from different data types.

const vector = new Vex3(1, 2, 3);
const vector = new Vex3({ x: 0, y: 1, z: 5 });
const vector = new Vex3(0);
const vector = new Vex3(Direction.North);
const vector = new Vex3(Direction.North, 5);

add

Adds another vector to this vector.

vector.add({ x: 0, y: 1, z: 5 });

assign

Assigns components to this vector.

vector.assign({ y: 1, z: 0 });

ceil

Performs a ceiling function on each component of this vector.

vector.ceil();

clamp

Clamps all components of this vector between those of a minimum and maximum vector.

vector.clamp(
  { x: 0, z: 5 }, // Minimum
  { x: 10, y: 10 } // Maximum
);

distance

Calculates the distance between this vector and another vector

vector.distance({ x: -2, y: 4, z: 18 });

divide

Divides this vector by a scalar value or another vector.

vector.divide(4);
vector.divide({ x: 4, y: 2, z: 3 });

dot

Calculates the dot product of this vector and another vector.

vector.dot({ x: -2, y: 4, z: 18 });

equals

Checks whether this vector is equal to another vector.

vector.equals({ x: -2, y: 4, z: 18 });

floor

Performs a floor function on each component of this vector.

vector.floor();

multiply

Multiplies this vector by a scalar value or another vector.

vector.multiply(4);
vector.multiply({ x: 4, y: 2, z: 3 });

normalize

Normalizes this vector.

vector.normalize();

round

Rounds each component of this vector.

vector.round();

subtract

Subtracts another vector from this vector

vector.subtract({ x: 0, y: 1, z: 5 });

toString

Creates a string representation of this vector.

const command = `setblock ${vector} air destroy`;
vector.toString({ fractionDigits: 1 });

Vex3 Instance Properties

magnitude

Calculates the magnitude of this vector.

vector.magnitude;

x

The X component of this vector.

vector.x;

y

The Y component of this vector.

vector.y;

z

The Z component of this vector.

vector.z;

About

Your "friendly" helper for performing mathematical operations on vectors.

Resources

License

Stars

Watchers

Forks