Skip to content

RegionIntersection/RegionUnion do not promote mixed real types #21

Description

@tobydriscoll

Summary

RegionIntersection and RegionUnion cannot combine regions whose real-type parameters differ (e.g. a Float64 region with a BigFloat region).

Details

In src/regions.jl, both structs declare their fields with the same type parameter as the struct, and there is no promoting constructor:

struct RegionIntersection{T} <: AbstractRegion{T}
    one::AbstractRegion{T}
    two::AbstractRegion{T}
end

The corresponding operations are only defined for matching T:

function intersect(R1::AbstractRegion{T}, R2::AbstractRegion{T}) where {T}
    return RegionIntersection(R1, R2)
end

RegionUnion / union have the same shape.

As a result, R_f64 ∩ R_big (and the union equivalent) raises a MethodError because there is no method accepting two different real types. There is an existing # TODO: promote different floating types to common type comment near the struct definitions.

Proposed fix

Add a constructor / method that promotes the two regions to a common real type (via promote_type and convert_real_type) before storing them, so that the stored field types are consistent with the struct's T parameter. Apply to both RegionIntersection/intersect and RegionUnion/union.

Notes

This was previously tracked in a todo.txt file, which has since been removed in favor of GitHub issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions