Repository navigation
Compare Feature property values in equality - #235
Merged
Merged
Conversation
The hash is based on a rotation-canonical, quantized representation of the ring vertices, consistent with the shift-insensitive equality of these types (compareShifted). Purely additive, no behavior changes.
- JSONValue: a Hashable/Sendable/Codable JSON value enum with numeric normalization (3.0 == 3), created from property-style Sendable values - properties(as:)/foreignMembers(as:): decode into any Decodable type, with JSONDecoder strategy support and real DecodingErrors - jsonValue(for:)/jsonForeignMember(for:): pattern matching accessors - intValue/doubleValue/boolValue/stringValue(for:) and foreign member equivalents: coercing scalar accessors - Feature(encodedProperties:): create a Feature from Encodable properties (distinct label to keep dictionary-literal call sites resolving to the [String: Sendable] initializer) - Hashable conformances for Point, MultiPoint, LineString, MultiLineString, GeometryCollection, Feature, and FeatureCollection, consistent with their Equatable implementations - Existing accessors and Equatable behavior are unchanged
Two features are now equal when their property values match, compared after JSONValue normalization (a property stored as 3.0 equals one stored as 3). Values that are not JSON-compatible (e.g. Data) are regarded as equal when present on both sides, keeping == reflexive. The Feature hash is updated accordingly. Note: this is a behavior change — features with the same property keys but different values were previously regarded as equal. Resolves the keys-only equality TODO in Feature.
Resolve conflicts: keep the deep property-value equality (== and hash) from this branch, adopt the JSONValue extensions, bulk jsonProperties()/ jsonForeignMembers() conversions, and tests from main (#234). Also fix pre-existing redundant #require warnings in PolygonTests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #232. Completes #231. Stacked on #234.
What
Feature.==now compares property values, not just keys (resolving the keys-only TODO inFeature.swift):JSONValuenormalization, so a property stored as3.0equals one stored as3, and nested objects/arrays compare deeply.Data) are regarded as equal when present on both sides — keeping==reflexive, documented on the API.Feature.hash(into:)hashes the normalized values (non-JSON-compatible values hash to a fixed bucket, consistent with the==fallback).Behavior change
Features with the same property keys but different values were previously regarded as equal (documented keys-only behavior); they are now unequal. Code relying on that (e.g.
Set/Dictionarysemantics) would observe different results — see #232 for the compatibility discussion; a semver bump is appropriate for the release containing this.Verification
3vs3.0), deep nested comparison, non-JSON fallback + reflexivity,Set<Feature>deduplication.