Skip to content

Polygon with BigFloats #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zekeriyasari opened this issue Feb 14, 2021 · 4 comments
Closed

Polygon with BigFloats #132

zekeriyasari opened this issue Feb 14, 2021 · 4 comments

Comments

@zekeriyasari
Copy link

zekeriyasari commented Feb 14, 2021

The construction of a polygon with Float64 points such as

hexagon = Polygon(
    [Point(cos(θ), sin(θ)) for θ in 0 : π / 3 : 2π - π / 3]
)

does not throw an error, while the one with BigFloat points such as

hexagon = Polygon(
    [Point(BigFloat(cos(θ)), BigFloat(sin(θ))) for θ in 0 : π / 3 : 2π - π / 3]
)

does throw an error. The error thrown is

ERROR: ArgumentError: cannot reinterpret `Tuple{Point2{BigFloat}, Point2{BigFloat}}` as `Line{2, BigFloat}`, type `Line{2, BigFloat}` is not a bits type
Stacktrace:
 [1] (::Base.var"#throwbits#243")(S::Type, T::Type, U::Type)
   @ Base ./reinterpretarray.jl:16
 [2] reinterpret(#unused#::Type{Line{2, BigFloat}}, a::TupleView{Tuple{Point2{BigFloat}, Point2{BigFloat}}, 2, 1, Vector{Point2{BigFloat}}})
   @ Base ./reinterpretarray.jl:36
 [3] connect
   @ ~/.julia/packages/GeometryBasics/l4gkj/src/viewtypes.jl:77 [inlined]
 [4] LineString(points::Vector{Point2{BigFloat}}, skip::Int64)
   @ GeometryBasics ~/.julia/packages/GeometryBasics/l4gkj/src/basic_types.jl:209
 [5] Polygon(exterior::Vector{Point2{BigFloat}}, skip::Int64)
   @ GeometryBasics ~/.julia/packages/GeometryBasics/l4gkj/src/basic_types.jl:275
 [6] top-level scope
   @ REPL[559]:1

Is there a possible workaround for this error?

@zekeriyasari
Copy link
Author

zekeriyasari commented Feb 14, 2021

The aim was to construct a hexagon. Calling the constructor directly, I think, solves the problem.

using StaticArrays 
using GeometryBasics 

hexagon = GeometryBasics.Ngon(@SVector [Point(BigFloat(cos(θ)), BigFloat(sin(θ))) for θ in 0 : π / 3 : 2π - π / 3])

@SimonDanisch
Copy link
Member

Oh yeah, there is some branch missing to handle non isbits element types...
https://github.com/JuliaGeometry/GeometryBasics.jl/blob/master/src/viewtypes.jl#L77
This needs to check for isbits, and if not isbits copy instead of reinterprete

@visr
Copy link
Member

visr commented May 18, 2021

@zekeriyasari why did you close this? I think #132 (comment) would need to be changed in this package to fix this issue.

@visr visr reopened this May 18, 2021
@asinghvi17
Copy link
Contributor

Looks like this is fixed in v0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants