Coder Social home page Coder Social logo

unitfulangles.jl's Introduction

UnitfulAngles

Build status Build Status Coverage Status

A supplemental units package for Julia's Unitful.jl.

UnitfulAngles.jl introduces all the angular units found in Wikipedia's articles Angle § Units, Angular unit and Circular sector.

In addition to the Radian and Degree units already available in Unitful.jl, the following units are introduced: DoubleTurn, Turn, HalfTurn, Quadrant, Sextant, Octant, ClockPosition, HourAngle, CompassPoint, Hexacontade, BinaryRadian, DiameterPart, Gradian, Arcminute, and Arcsecond.

Because all the trigonometric functions work correctly regardless of the type of their argument, there is no need to convert between the units. However, to specifically convert one unit to the other, use Unitful.jl's uconvert function:

julia> using Unitful, UnitfulAngles

julia> uconvert(u"clockPosition", 128u"brad")
6//1 clockPosition

Special features

  • All the trigonometric functions (sin, sinc, cos, cosc, tan, sec, csc, and cot) work as expected:
    julia> using UnitfulAngles
    
    julia> import UnitfulAngles: °, rad, octant
    
    julia> sin(30°)
    0.5
    
    julia> cos*rad)
    -1.0
    
    julia> tan(1octant)
    1.0
  • In order to get inverse functions (acos, acot, acsc, asec, asin, atan, and atan2) to return a specific unit, specify the desired unit as the first argument:
    julia> import UnitfulAngles.turn
    
    julia> asin(turn, 1)
    0.25 τ
  • As a bonus, you can also convert between an angle and Dates.Time:
    julia> using Unitful, UnitfulAngles, Dates
    
    julia> convert(Dates.Time, 200u"grad")
    12:00:00
    
    julia> convert(u"sextant", Dates.Time(4,0,0))
    1.0 sextant

unitfulangles.jl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

unitfulangles.jl's Issues

fix the need to have a myRad and mydegree

In order not to overwrite the rad and ° units from Unitful.jl, I called my radians and degrees myRad and my°. Ugly. How can I fix this?
I didn't base my angular system on the one already provided in Unitful.jl because tons of the units here can be expressed as a rational number of the full turn. Unitful.jl approach was to base the angles on radians. While that makes total sense, it feels like a shame to lose accuracy by doing the same here. Any input from @ajkeller34 would be appreciated!

Release version 0.6.1

When the compat helper merge #24 happened the project version remained at 0.6.0. We need to change the Project version to 0.6.1 and register with general.

You can see for yourself here that the register thinks that UnitfulAngles is only compatible with Unitful 0.16 which is several versions out of date.

Cannot add UnitfulAngles as package in Julia 1.0.3?

Hello,

I recently updated from Julia 1.0.2 to 1.0.3 and am finding that I cannot add UnitfulAngles? Is there a compatibility problem?

I started this thread on the Julia Discourse, however I haven't gotten helpful comments.

Thank you!

The `as` conflicts with Unitful's attoseconds

#28 added as as an alias for arcsecond that allows prefixes. This however conflicts with seconds * 10^-18 (attoseconds, as).

julia> using Unitful

julia> using UnitfulAngles

julia> 1u"as"
┌ Warning: Symbol as was found in multiple registered unit modules.
│ We will use the one from UnitfulAngles.
└ @ Unitful ~/.julia/packages/Unitful/SUQzL/src/user.jl:715
1 as

help?> Unitful.as
  Unitful.as


  A prefixed unit, equal to 10^-18 s.

  Dimension: 𝐓

  See also: Unitful.s.
''''

Example with directly importing units

You might want to include an example of directly importing and using units as symbols. It's especially nice for degrees.

julia> import Unitful: °, rad

julia> sin(30°)
0.5

julia> cos(pi*rad)
-1.0

julia> import UnitfulAngles: octant

julia> tan(1octant)
1.0

julia> uconvert(octant, 180°)
4.0 octant

Update GitHub workflows

  • run the tests (CI) as part of pull request and pushes to main
  • simplify releases (e.g. tagbot, etc).

prefer exact conversion factors

Maybe the various angle measurements should be expressed in degrees rather than radians since that at leat allows the possibility for exact arithmetic rather than forcing the user to use inexact real numbers too soon.

Looks cool, but way slower

julia> @btime sin(1octant)
  573.302 ns (0 allocations: 0 bytes)

julia> @btime sinpi(1)
  1.048 ns (0 allocations: 0 bytes)

julia> import UnitfulAngles: °, rad, octant
WARNING: could not import UnitfulAngles.° into Main
WARNING: could not import UnitfulAngles.rad into Main

julia> VERSION
v"1.3.0-alpha.0"

I also wanted to let you know the import from the docs didn't work. I may look into both later, just wanted to file so I don't forget.

Error in example: no `rad` or `°`

This example does not run because rad and ° are not defined in UnitfulAngles.

julia> import UnitfulAngles: °, rad, octant
WARNING: could not import UnitfulAngles.° into Main
WARNING: could not import UnitfulAngles.rad into Main

The package uses the definitions of radians and degrees from Unitful.jl (I see there is some history, with these originally redefined in UnitfulAngles). But instead of importing these units it always uses them through u-strings. I think it would make sense to do

import Unitful: rad,  °

That way UnitfulAngles.jl includes these angles without users having to import them separately from Unitful. Note that this does not cause any conflicts, the rad and ° would still be the ones from Unitful (check using @which) and not a redefinition (Julia is awesome!).

I would be willing to make these changes as PR if @yakir12 you agree.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Tests failed: Expression: all((1 * u"turn" ≈ q * u for (q, u) = zip(quantities, units)))

Hi,

During preparing your project for Guix downstream I've faced with failing tests:

Test Failed at /gnu/store/y0jimlwdn54jkqiicdwsjlp0jbb7marz-julia-unitfulangles-0.7.1/share/julia/loadpath/UnitfulAngles/test/runtests.jl:9
  Expression: all((1 * u"turn" ≈ q * u for (q, u) = zip(quantities, units)))
ERROR: LoadError: There was an error during testing
in expression starting at /gnu/store/y0jimlwdn54jkqiicdwsjlp0jbb7marz-julia-unitfulangles-0.7.1/share/julia/loadpath/UnitfulAngles/test/runtests.jl:9
  • Julia v1.8.3
  • UnitfulAngles.jl v0.7.1
  • Unitful.jl v1.12.2

better usability for inverse trig functions

The regular trig functions don't require code changes since you can just use the normal "sin(x)" call, for example. However, asin, acos, etc. require a different call where units are specified. If you just wanted the default of radians, you still need to change your code to handle it.

It might be nice to allow asin(x) where x is Dimensionless. That would allow the UnitfulAngles asin call to be used and return radians, thus allowing people to write code that works with or without units.

Returning Dimensionless from the regular trig functions would then allow you to call asin on sin outputs, giving you units for your output as long as you started with units.

As an aside, I was wondering why you use the "d" version of the trig functions at all. Don't they internally convert to radians again anyway? Would really simplify the code if you just did the calcs in radians since you're doing conversions anyway.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.