Skip to content

Intersection with empty input should return dimension-appropriate empty geometry #694

@peterstace

Description

@peterstace

Currently, Intersection returns GEOMETRYCOLLECTION EMPTY when one or both inputs are empty:

if a.IsEmpty() || b.IsEmpty() {
    return Geometry{}, nil
}

However, when envelopes are disjoint (but inputs are non-empty), it returns a dimension-appropriate empty geometry:

if envelopesDisjoint(a, b) {
    return createEmptyResult(minInt(a.Dimension(), b.Dimension())), nil
}

For consistency, the empty input case should also return createEmptyResult(minInt(a.Dimension(), b.Dimension())). This would allow combining the two conditions:

if a.IsEmpty() || b.IsEmpty() || envelopesDisjoint(a, b) {
    return createEmptyResult(minInt(a.Dimension(), b.Dimension())), nil
}

The existing tests expect GEOMETRYCOLLECTION EMPTY for empty inputs, so they would need to be updated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    improveImprove (or remove) an existing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions