Debian Codegraph @

vendor/github.com/xyproto/gfx/cmplx.go

raw
1 package gfx
2
3 import (
4 "image/color"
5 "math/cmplx"
6 )
7
8 // CmplxSin returns the sine of x.
9 func CmplxSin(x complex128) complex128 {
10 return cmplx.Sin(x)
11 }
12
13 // CmplxSinh returns the hyperbolic sine of x.
14 func CmplxSinh(x complex128) complex128 {
15 return cmplx.Sinh(x)
16 }
17
18 // CmplxCos returns the cosine of x.
19 func CmplxCos(x complex128) complex128 {
20 return cmplx.Cos(x)
21 }
22
23 // CmplxCosh returns the hyperbolic cosine of x.
24 func CmplxCosh(x complex128) complex128 {
25 return cmplx.Cosh(x)
26 }
27
28 // CmplxTan returns the tangent of x.
29 func CmplxTan(x complex128) complex128 {
30 return cmplx.Tan(x)
31 }
32
33 // CmplxTanh returns the hyperbolic tangent of x.
34 func CmplxTanh(x complex128) complex128 {
35 return cmplx.Tanh(x)
36 }
37
38 // CmplxPow returns x**y, the base-x exponential of y.
39 func CmplxPow(x, y complex128) complex128 {
40 return cmplx.Pow(x, y)
41 }
42
43 // CmplxSqrt returns the square root of x.
44 // The result r is chosen so that real(r) ≥ 0 and imag(r) has the same sign as imag(x).
45 func CmplxSqrt(x complex128) complex128 {
46 return cmplx.Sqrt(x)
47 }
48
49 // CmplxPhase returns the phase (also called the argument) of x.
50 // The returned value is in the range [-Pi, Pi].
51 func CmplxPhase(x complex128) float64 {
52 return cmplx.Phase(x)
53 }
54
55 // CmplxPhaseAt returns the color at the phase of the given complex128 value.
56 func (p Palette) CmplxPhaseAt(z complex128) color.Color {
57 t := CmplxPhase(z)/Pi + 1
58
59 if t > 1 {
60 t = 2 - t
61 }
62
63 return p.At(t)
64 }