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
Center
Gets the center used to calculate these bounds.
public GeoCoordinate Center { get; }
Property Value
RadiusMeters
Gets the finite, non-negative spherical radius in meters.
public double RadiusMeters { get; }
Property Value
Methods
Contains(GeoCoordinate)
Checks whether a coordinate belongs to at least one conservative prefilter box.
public bool Contains(GeoCoordinate coordinate)
Parameters
coordinateGeoCoordinateThe coordinate to test.
Returns
Remarks
A successful result does not prove the coordinate is within RadiusMeters; apply DistanceMetersTo(GeoCoordinate) for the exact spherical check.
Exceptions
- ArgumentNullException
coordinateis null.
Create(GeoCoordinate, double)
Calculates spherical search bounds from trusted input.
public static GeoBounds Create(GeoCoordinate center, double radiusMeters)
Parameters
centerGeoCoordinateThe center of the radius search.
radiusMetersdoubleA finite radius greater than or equal to zero.
Returns
- GeoBounds
One or two conservative, non-wrapping boxes.
Exceptions
- ArgumentNullException
centeris null.- InvalidOperationException
radiusMetersis 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
componentsEqualityComponentsThe 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
centerGeoCoordinateThe center of the radius search.
radiusMetersdoubleA finite radius greater than or equal to zero.
fieldNamestringOptional property name or JSON Pointer for a radius validation failure.
Returns
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.