Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hscmap/angle

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hscmap/angle

Simple angle unit converter for TypeScript

  • 0.7.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Weekly downloads
 
Created
Source

Angle

Simple angle unit converter for TypeScript

Install

npm install --save @hscmap/angle

Example

import { Angle, EquatorialCoord } from "@hscmap/angle"


function equal(a: number, b: number) {
    return Math.abs(a / b - 1) <= 1.e-6 || Math.abs((a - 1) / (b - 1) - 1) <= 1.e-6
}

function assertEqual(a: number, b: number) {
    console.assert(equal(a, b))
}


function assetArrayEqual(a: number[], b: number[]) {
    console.assert(a.every((c, i) => equal(c, b[i])))
}


assertEqual(Angle.fromRad(Math.PI / 4).deg, 45)
assertEqual(Angle.fromDeg(45).rad, Math.PI / 4)
assertEqual(Angle.fromAmin(60).deg, 1)
assertEqual(Angle.fromAsec(1).deg, 1 / 3600)
assertEqual(Angle.fromDeg(1).amin, 60)
assertEqual(Angle.fromDeg(1).asec, 3600)


!(function eq2xyz() {
    assetArrayEqual(EquatorialCoord.fromDeg(0, 0).xyz, [1, 0, 0])
    assetArrayEqual(EquatorialCoord.fromDeg(90, 0).xyz, [0, 1, 0])
    assetArrayEqual(EquatorialCoord.fromDeg(90, 90).xyz, [0, 0, 1])
    assetArrayEqual(EquatorialCoord.fromDeg(0, -45).xyz, [Math.SQRT1_2, 0, -Math.SQRT1_2])
    assetArrayEqual(EquatorialCoord.fromDeg(-45, -45).xyz, [1 / 2, - 1 / 2, -Math.SQRT1_2])
})()


!(function xyz2eq() {
    function assertADEqual(eq: EquatorialCoord, a: Angle, d: Angle) {
        assetArrayEqual([eq.a.rad, eq.d.rad], [a.rad, d.rad])
    }

    assertADEqual(EquatorialCoord.fromXyz([1, 0, 0]), Angle.fromDeg(0), Angle.fromDeg(0))
    assertADEqual(EquatorialCoord.fromXyz([0, 1, 0]), Angle.fromDeg(90), Angle.fromDeg(0))
    assertADEqual(EquatorialCoord.fromXyz([0, 0, 1]), Angle.fromDeg(0), Angle.fromDeg(90))
    assertADEqual(EquatorialCoord.fromXyz([Math.SQRT1_2, 0, -Math.SQRT1_2]), Angle.fromDeg(0), Angle.fromDeg(-45))
    assertADEqual(EquatorialCoord.fromXyz([1/2, -1/2, -Math.SQRT1_2]), Angle.fromDeg(315), Angle.fromDeg(-45))
})()


!(function simple_coord_parse() {
    const eq = EquatorialCoord.parse(`29 41`)
    assertEqual(eq.a.deg, 29)
    assertEqual(eq.d.deg, 41)
})()


!(function m81_coord_parse() {
    const eq = EquatorialCoord.parse(`(RA, α) 09h 55m 33.17306s (Dec, δ) +69° 03′ 55.0610″`)
    assertEqual(eq.a.deg, 148.88822108386302)
    assertEqual(eq.d.deg, 69.06529472246791)
})()


!(function m81_coord_unparse() {
    const eq = EquatorialCoord.parse(`(RA, α) 09h 55m 33.17306s (Dec, δ) +69° 03′ 55.0610″`)
    const { a, d } = eq.toString()
    console.assert(a == '09:55:33.1731')
    console.assert(d == '+69:03:55.0610')
})()

FAQs

Package last updated on 05 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc