Skip to content

Commit

Permalink
Add atan2 and fix jsdocs for atan
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Feb 19, 2024
1 parent 0a74a4d commit 26e2679
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ export namespace scalar {
/**
* Returns the arc-tangent of the parameters. If `x` is not provided, `y` is regarded as a value of `y/x`.
* @see https://thebookofshaders.com/glossary/?search=atan
* @param y the value of the y-coordinate
* @param x the value of the x-coordinate
* @returns the angle in degrees
*/
export function atan(y: number, x?: number): number {
if (x === undefined) {
Expand All @@ -396,6 +399,17 @@ export namespace scalar {
}
}

/**
* Returns the arc-tangent of the parameters.
* @see https://thebookofshaders.com/glossary/?search=atan
* @param y the value of the y-coordinate
* @param x the value of the x-coordinate
* @returns the angle in degrees
*/
export function atan2(y: number, x: number): number {
return Math.atan2(y, x) * Common.RAD2DEG
}

export const pow = Math.exp

export const exp = Math.exp
Expand Down
16 changes: 16 additions & 0 deletions src/vec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ export namespace vec2 {

/**
* Returns the arc-tangent of the parameters. If `x` is not provided, `y` is regarded as a value of `y/x`.
* @param y the values of the y-coordinate
* @param x the values of the x-coordinate
* @returns the angle in degrees
* @see https://thebookofshaders.com/glossary/?search=atan
* */
export function atan(y: vec2, x?: vec2): vec2 {
Expand All @@ -752,6 +755,19 @@ export namespace vec2 {
]
}
}
/**
* Returns the arc-tangent of the parameters.
* @param y the values of the y-coordinate
* @param x the values of the x-coordinate
* @returns the angle in degrees
* @see https://thebookofshaders.com/glossary/?search=atan
* */
export function atan2(y: vec2, x: vec2): vec2 {
return [
Math.atan2(y[0], x[0]) * Common.RAD2DEG, //
Math.atan2(y[1], x[1]) * Common.RAD2DEG,
]
}

export function pow(a: vec2, b: vec2): vec2 {
return [Math.pow(a[0], b[0]), Math.pow(a[1], b[1])]
Expand Down
19 changes: 18 additions & 1 deletion src/vec3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,11 @@ export namespace vec3 {

/**
* Returns the arc-tangent of the parameters. If `x` is not provided, `y` is regarded as a value of `y/x`.
* @param y the values of the y-coordinate
* @param x the values of the x-coordinate
* @returns the angle in degrees
* @see https://thebookofshaders.com/glossary/?search=atan
*/
* */
export function atan(y: vec3, x?: vec3): vec3 {
if (x === undefined) {
return [
Expand All @@ -933,6 +936,20 @@ export namespace vec3 {
]
}
}
/**
* Returns the arc-tangent of the parameters.
* @param y the values of the y-coordinate
* @param x the values of the x-coordinate
* @returns the angle in degrees
* @see https://thebookofshaders.com/glossary/?search=atan
* */
export function atan2(y: vec3, x: vec3): vec3 {
return [
Math.atan2(y[0], x[0]) * Common.RAD2DEG,
Math.atan2(y[1], x[1]) * Common.RAD2DEG,
Math.atan2(y[2], x[2]) * Common.RAD2DEG,
]
}

export function pow(a: vec3, b: vec3): vec3 {
return [Math.pow(a[0], b[0]), Math.pow(a[1], b[1]), Math.pow(a[2], b[2])]
Expand Down
22 changes: 20 additions & 2 deletions src/vec4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,12 @@ export namespace vec4 {
}

/**
* Returns the arc-tangent of the parameters. If `x` is not provided, `y` is regarded as a value of `y/x`.
* Returns the arc-tangent of the parameters. If `x` is not provided, `y` is regarded as a value of `y/x`.
* @param y the values of the y-coordinate
* @param x the values of the x-coordinate
* @returns the angle in degrees
* @see https://thebookofshaders.com/glossary/?search=atan
*/
* */
export function atan(y: vec4, x?: vec4): vec4 {
if (x === undefined) {
return [
Expand All @@ -824,6 +827,21 @@ export namespace vec4 {
]
}
}
/**
* Returns the arc-tangent of the parameters.
* @param y the values of the y-coordinate
* @param x the values of the x-coordinate
* @returns the angle in degrees
* @see https://thebookofshaders.com/glossary/?search=atan
* */
export function atan2(y: vec4, x: vec4): vec4 {
return [
Math.atan2(y[0], x[0]) * Common.RAD2DEG,
Math.atan2(y[1], x[1]) * Common.RAD2DEG,
Math.atan2(y[2], x[2]) * Common.RAD2DEG,
Math.atan2(y[3], x[3]) * Common.RAD2DEG,
]
}

export function pow(a: vec4, b: vec4): vec4 {
return [
Expand Down

0 comments on commit 26e2679

Please sign in to comment.