Table of Contents

Class GeoBounds

Namespace
Trellis.Primitives
Assembly
Trellis.Primitives.dll

A validated spherical-radius search area represented by one or two conservative non-wrapping boxes.

public sealed class GeoBounds : ValueObject, IComparable<ValueObject>, IComparable, IEquatable<ValueObject>
Inheritance
GeoBounds
Implements
Inherited Members
Extension Methods

Remarks

The boxes are a broad prefilter: every coordinate within RadiusMeters is retained, but coordinates outside the radius can also be present and require an exact distance check.

Properties

Boxes

Gets one non-wrapping box, or two boxes ordered west-to-east when the area crosses the antimeridian.

public IReadOnlyList<GeoBoundingBox> Boxes { get; }

Property Value

IReadOnlyList<GeoBoundingBox>

Center

Gets the center used to calculate these bounds.

public GeoCoordinate Center { get; }

Property Value

GeoCoordinate

RadiusMeters

Gets the finite, non-negative spherical radius in meters.

public double RadiusMeters { get; }

Property Value

double

Methods

Contains(GeoCoordinate)

Checks whether a coordinate belongs to at least one conservative prefilter box.

public bool Contains(GeoCoordinate coordinate)

Parameters

coordinate GeoCoordinate

The coordinate to test.

Returns

bool

true when a box contains the stored latitude and longitude.

Remarks

A successful result does not prove the coordinate is within RadiusMeters; apply DistanceMetersTo(GeoCoordinate) for the exact spherical check.

Exceptions

ArgumentNullException

coordinate is null.

Create(GeoCoordinate, double)

Calculates spherical search bounds from trusted input.

public static GeoBounds Create(GeoCoordinate center, double radiusMeters)

Parameters

center GeoCoordinate

The center of the radius search.

radiusMeters double

A finite radius greater than or equal to zero.

Returns

GeoBounds

One or two conservative, non-wrapping boxes.

Exceptions

ArgumentNullException

center is null.

InvalidOperationException

radiusMeters is invalid.

GetEqualityComponents(ref EqualityComponents)

When overridden in a derived class, adds the components that define equality for this value object.

protected override void GetEqualityComponents(ref EqualityComponents components)

Parameters

components EqualityComponents

The sink that collects this value object's equality components.

Examples

protected override void GetEqualityComponents(ref EqualityComponents components)
{
    components.Add(Street);
    components.Add(City);
    components.Add(PostalCode);
}

Remarks

This method is used by Equals(ValueObject?), GetHashCode(), and CompareTo(ValueObject?) to determine equality and ordering. Components must be added in a consistent order.

Guidelines:

  • Add all properties that define the value object's identity
  • For derived classes, call base.GetEqualityComponents(ref components) first
  • Add components in a consistent, deterministic order
  • Do not allocate: the sink exists so comparisons stay allocation-free

TryCreate(GeoCoordinate, double, string?)

Validates a radius and calculates conservative spherical search bounds.

public static Result<GeoBounds> TryCreate(GeoCoordinate center, double radiusMeters, string? fieldName = null)

Parameters

center GeoCoordinate

The center of the radius search.

radiusMeters double

A finite radius greater than or equal to zero.

fieldName string

Optional property name or JSON Pointer for a radius validation failure.

Returns

Result<GeoBounds>

One or two non-wrapping boxes, or a validation failure for the radius.

Remarks

A radius reaching either pole covers every longitude. A radius at least half the mean-Earth circumference covers the world. Bounds include an outward numerical safety margin, scaled near antipodal distances, so spherical floating-point roundoff does not exclude boundaries.