Number representations

The package is designed to work with complex numbers in different formats, including the native Complex type and the Polar and Spherical types from the ComplexValues package. The package re-exports these types, so you can use them directly.

seg = Segment(0, Polar(3, π/4))
point(seg, (0:4)/4)
5-element Vector{Polar{Float64}}:
   Complex Polar: (modulus = 0.0, angle = 0.0⋅π)
 Complex Polar: (modulus = 0.75, angle = 0.25⋅π)
  Complex Polar: (modulus = 1.5, angle = 0.25⋅π)
 Complex Polar: (modulus = 2.25, angle = 0.25⋅π)
  Complex Polar: (modulus = 3.0, angle = 0.25⋅π)
Complex.(ans)
5-element Vector{ComplexF64}:
                0.0 + 0.0im
 0.5303300858899107 + 0.5303300858899106im
 1.0606601717798214 + 1.0606601717798212im
 1.5909902576697321 + 1.590990257669732im
  2.121320343559643 + 2.1213203435596424im

(The following feature was added most recently and may have rough edges. Please report any issues.)

In addition, the package supports different floating-point types underlying any of the complex number types. This means you can use BigFloats or DoubleFloats to get higher precision.

using DoubleFloats
seg = Segment{DoubleFloat}(-1, 1)
seg(2//3)
3.33333333333333333333333333333332306e-01

Working in higher precision can be tricky: if you ever use a standard Float64 value, it will set a ceiling on the precision of the result. For example, the following code will not give you the expected result:

seg(2/3)
0.33333333333333326

As above, you can use Rational types to avoid premature floating-point conversion, or perform the conversions prior to calls:

seg(DoubleFloat(2) / 3)
3.33333333333333333333333333333329225e-01

Naturally, though, many powers of two can be converted correctly into higher precision without loss:

seg(1//8) - seg(0.125)
0.0

Curves, paths, and regions can be constructed with an explicit AbstractFloat type in braces. If the type is not given, the constructor will use the highest precision of its arguments, or default to Float64 if the inputs are integers or rationals.

setprecision(100)
cir = Circle(BigFloat(1) / 5, 1//5)
Circle{BigFloat} in the complex plane:
   centered at (0.20000000000000000000000000000004 + 0.0im) with radius 0.20000000000000000000000000000004, positively oriented

Again, note the effect of premature float casting:

Circle(BigFloat(1) / 5, 1/5)
Circle{BigFloat} in the complex plane:
   centered at (0.20000000000000000000000000000004 + 0.0im) with radius 0.20000000000000001110223024625157, positively oriented