Skip to content

Commit

Permalink
Initial commit geospatial queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaafanador3 committed Oct 6, 2023
1 parent 36e077f commit 6aa8a60
Show file tree
Hide file tree
Showing 14 changed files with 724 additions and 213 deletions.
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let cxxSettings: [CXXSetting] = [
.define("REALM_VERSION_PATCH", to: String(coreVersion.patch)),
.define("REALM_VERSION_EXTRA", to: "\"\(coreVersion.prereleaseIdentifiers.first ?? "")\""),
.define("REALM_VERSION_STRING", to: "\"\(coreVersion)\""),
.define("REALM_ENABLE_GEOSPATIAL", to: "1"),
]
let testCxxSettings: [CXXSetting] = cxxSettings + [
// Command-line `swift build` resolves header search paths
Expand Down Expand Up @@ -193,6 +194,7 @@ let package = Package(
"Realm/RLMEmbeddedObject.mm",
"Realm/RLMError.mm",
"Realm/RLMEvent.mm",
"Realm/RLMGeospatial.mm",
"Realm/RLMLogger.mm",
"Realm/RLMManagedArray.mm",
"Realm/RLMManagedDictionary.mm",
Expand Down
33 changes: 32 additions & 1 deletion Realm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@
AC3B33AE29DC6CEE0042F3A0 /* RLMLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = AC3B33AB29DC6CEE0042F3A0 /* RLMLogger.h */; settings = {ATTRIBUTES = (Public, ); }; };
AC3B33AF29DC6CEE0042F3A0 /* RLMLogger.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC3B33AC29DC6CEE0042F3A0 /* RLMLogger.mm */; };
AC3B33B029DC6CEE0042F3A0 /* RLMLogger_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = AC3B33AD29DC6CEE0042F3A0 /* RLMLogger_Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
AC7825B92ACD90BE007ABA4B /* Geospatial.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7825B82ACD90BE007ABA4B /* Geospatial.swift */; };
AC7825BD2ACD90DA007ABA4B /* RLMGeospatial.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC7825BA2ACD90DA007ABA4B /* RLMGeospatial.mm */; };
AC7825BF2ACD90DA007ABA4B /* RLMGeospatial.h in Headers */ = {isa = PBXBuildFile; fileRef = AC7825BC2ACD90DA007ABA4B /* RLMGeospatial.h */; settings = {ATTRIBUTES = (Public, ); }; };
AC7825C22ACD917B007ABA4B /* GeospatialTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7825C02ACD916C007ABA4B /* GeospatialTests.swift */; };
AC7D182D261F2F560080E1D2 /* RLMObjectServerPartitionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC7D182B261F2F560080E1D2 /* RLMObjectServerPartitionTests.mm */; };
AC7D182E261F2F560080E1D2 /* SwiftObjectServerPartitionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7D182C261F2F560080E1D2 /* SwiftObjectServerPartitionTests.swift */; };
AC81360F287F21350029F15E /* AsymmetricObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC81360E287F21350029F15E /* AsymmetricObject.swift */; };
Expand Down Expand Up @@ -863,6 +867,11 @@
AC3B33AB29DC6CEE0042F3A0 /* RLMLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMLogger.h; sourceTree = "<group>"; };
AC3B33AC29DC6CEE0042F3A0 /* RLMLogger.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMLogger.mm; sourceTree = "<group>"; };
AC3B33AD29DC6CEE0042F3A0 /* RLMLogger_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMLogger_Private.h; sourceTree = "<group>"; };
AC7825B82ACD90BE007ABA4B /* Geospatial.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Geospatial.swift; sourceTree = "<group>"; };
AC7825BA2ACD90DA007ABA4B /* RLMGeospatial.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMGeospatial.mm; sourceTree = "<group>"; };
AC7825BB2ACD90DA007ABA4B /* RLMGeospatial_Private.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RLMGeospatial_Private.hpp; sourceTree = "<group>"; };
AC7825BC2ACD90DA007ABA4B /* RLMGeospatial.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMGeospatial.h; sourceTree = "<group>"; };
AC7825C02ACD916C007ABA4B /* GeospatialTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeospatialTests.swift; sourceTree = "<group>"; };
AC7D182B261F2F560080E1D2 /* RLMObjectServerPartitionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RLMObjectServerPartitionTests.mm; path = Realm/ObjectServerTests/RLMObjectServerPartitionTests.mm; sourceTree = "<group>"; };
AC7D182C261F2F560080E1D2 /* SwiftObjectServerPartitionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftObjectServerPartitionTests.swift; path = Realm/ObjectServerTests/SwiftObjectServerPartitionTests.swift; sourceTree = "<group>"; };
AC81360E287F21350029F15E /* AsymmetricObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AsymmetricObject.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1313,6 +1322,7 @@
3FC3F9162419B63100E27322 /* EmbeddedObject.swift */,
29B7FDF51C0DA6560023224E /* Error.swift */,
3F7BCEB42834377E00EB6E16 /* Events.swift */,
AC7825B82ACD90BE007ABA4B /* Geospatial.swift */,
5D1534B71CCFF545008976D7 /* LinkingObjects.swift */,
5D660FE41BE98D670021E04F /* List.swift */,
0C3BD4D225C1C5AB007CFDD3 /* Map.swift */,
Expand Down Expand Up @@ -1362,6 +1372,7 @@
3F40C612276D1B05007FEF1A /* CustomObjectCreationTests.swift */,
3F9F53D42718E8E6000EEB4A /* CustomPersistableTestObjects.swift */,
CFFECBA8250646750010F585 /* Decimal128Tests.swift */,
AC7825C02ACD916C007ABA4B /* GeospatialTests.swift */,
CF0D04F02693652E0038A058 /* KeyPathTests.swift */,
5D660FFF1BE98D880021E04F /* KVOTests.swift */,
5D6610001BE98D880021E04F /* ListTests.swift */,
Expand Down Expand Up @@ -1670,6 +1681,9 @@
3FDAB83F290B4CCB00168F24 /* RLMError_Private.hpp */,
3FEE4F3E281C4370009194C7 /* RLMEvent.h */,
3FEE4F3F281C4370009194C7 /* RLMEvent.mm */,
AC7825BC2ACD90DA007ABA4B /* RLMGeospatial.h */,
AC7825BA2ACD90DA007ABA4B /* RLMGeospatial.mm */,
AC7825BB2ACD90DA007ABA4B /* RLMGeospatial_Private.hpp */,
AC3B33AB29DC6CEE0042F3A0 /* RLMLogger.h */,
AC3B33AC29DC6CEE0042F3A0 /* RLMLogger.mm */,
AC3B33AD29DC6CEE0042F3A0 /* RLMLogger_Private.h */,
Expand Down Expand Up @@ -1814,6 +1828,7 @@
AC813612287F21700029F15E /* RLMAsymmetricObject.h in Headers */,
3FD0D7C729675A2E0031C196 /* RLMAsyncTask.h in Headers */,
3FDB67152970720E0052233B /* RLMAsyncTask_Private.h in Headers */,
AC7825BF2ACD90DA007ABA4B /* RLMGeospatial.h in Headers */,
49E12CF2245DB7E800359DF1 /* RLMBSON.h in Headers */,
49E12CF5245DBF8A00359DF1 /* RLMBSON_Private.hpp in Headers */,
5D659EAB1BE04556006515A0 /* RLMCollection.h in Headers */,
Expand Down Expand Up @@ -2121,7 +2136,7 @@
TestTargetID = 53124AB725B71AF600771CE4;
};
5D659E7D1BE04556006515A0 = {
LastSwiftMigration = 1320;
LastSwiftMigration = 1500;
ProvisioningStyle = Automatic;
};
5D660FCB1BE98C560021E04F = {
Expand Down Expand Up @@ -2426,6 +2441,7 @@
CF76F7E924816AAB00890DD2 /* RLMMongoCollection.mm in Sources */,
4993221624129E6600A0EC8E /* RLMNetworkTransport.mm in Sources */,
5D659E8C1BE04556006515A0 /* RLMObject.mm in Sources */,
AC7825BD2ACD90DA007ABA4B /* RLMGeospatial.mm in Sources */,
5D659E8D1BE04556006515A0 /* RLMObjectBase.mm in Sources */,
3F4F3ADB23F71C790048DB43 /* RLMObjectId.mm in Sources */,
5D659E8E1BE04556006515A0 /* RLMObjectSchema.mm in Sources */,
Expand Down Expand Up @@ -2498,6 +2514,7 @@
5B77EACE1DCC5614006AB51D /* ObjectiveCSupport.swift in Sources */,
5D660FF51BE98D670021E04F /* ObjectSchema.swift in Sources */,
5D660FF61BE98D670021E04F /* Optional.swift in Sources */,
AC7825B92ACD90BE007ABA4B /* Geospatial.swift in Sources */,
3FE267D8264308680030F83C /* Persistable.swift in Sources */,
3F149CCB2668112A00111D65 /* PersistedProperty.swift in Sources */,
3F857A49276A507200F9B9B1 /* Projection.swift in Sources */,
Expand Down Expand Up @@ -2547,6 +2564,7 @@
3FB19069265ECF0C00DA7C76 /* ModernObjectTests.swift in Sources */,
3FB1906B265ED23300DA7C76 /* ModernTestObjects.swift in Sources */,
CF986DE225AE3EC70039D287 /* MutableSetTests.swift in Sources */,
AC7825C22ACD917B007ABA4B /* GeospatialTests.swift in Sources */,
3F8824FE1E5E335000586B35 /* ObjectAccessorTests.swift in Sources */,
3F8824FF1E5E335000586B35 /* ObjectCreationTests.swift in Sources */,
CFFECBB525078EC40010F585 /* ObjectIdTests.swift in Sources */,
Expand Down Expand Up @@ -2820,6 +2838,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5D659E761BE03E0D006515A0 /* Realm.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
SWIFT_VERSION = 5.0;
};
name = Static;
};
Expand Down Expand Up @@ -2856,6 +2877,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3FB56E7E250D457A00A6216B /* ObjectServerTests.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = "Realm/ObjectServerTests/ObjectServerTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -2991,13 +3013,20 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5D659E761BE03E0D006515A0 /* Realm.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
5D659ED81BE04556006515A0 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5D659E761BE03E0D006515A0 /* Realm.xcconfig */;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -3091,6 +3120,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3FB56E7E250D457A00A6216B /* ObjectServerTests.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = "Realm/ObjectServerTests/ObjectServerTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3102,6 +3132,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3FB56E7E250D457A00A6216B /* ObjectServerTests.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = "Realm/ObjectServerTests/ObjectServerTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
68 changes: 68 additions & 0 deletions Realm/RLMGeospatial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2023 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

#import <Realm/RLMConstants.h>

RLM_HEADER_AUDIT_BEGIN(nullability)

/// An enum representing different levels of sync-related logging that can be configured.
typedef RLM_CLOSED_ENUM(NSUInteger, RLMGeospatialType) {
RLMGeospatialTypeBox,
/// Only fatal errors will be logged.
RLMGeospatialTypeCircle,
/// Only errors will be logged.
RLMLogLevelTypePolygon,
} NS_SWIFT_NAME(GeospatialType);

@interface RLMGeospatial : NSObject
@end

@protocol RLMSwiftGeospatial
- (RLMGeospatial *)_convertedValue;
@end

@interface RLMGeospatialPoint : NSObject
@property (readonly) double latitude;
@property (readonly) double longitude;

- (instancetype)initWithLatitude:(double)latitude longitude:(double)longitude;
@end

@interface RLMGeospatialBox : RLMGeospatial
@property (readonly, strong) RLMGeospatialPoint *bottomLeft;
@property (readonly, strong) RLMGeospatialPoint *topRight;

- (instancetype)initWithBottomLeft:(RLMGeospatialPoint *)bottomLeft topRight:(RLMGeospatialPoint *)topRight;
- (instancetype)initWithTop:(double)top left:(double)left bottom:(double)bottom right:(double)right;
@end

@interface RLMGeospatialPolygon : RLMGeospatial
@property (readonly, strong) NSArray<RLMGeospatialPoint *> *outerRing;
@property (readonly, strong, nullable) NSArray<NSArray<RLMGeospatialPoint *> *> *holes;

- (instancetype)initWithOuterRing:(NSArray<RLMGeospatialPoint *> *)outerRing holes:(nullable NSArray<NSArray<RLMGeospatialPoint *> *> *)holes;
@end

@interface RLMGeospatialCircle : RLMGeospatial
@property (readonly, strong) RLMGeospatialPoint *center;
@property (readonly) double radians;

- (instancetype)initWithCenter:(RLMGeospatialPoint *)center radians:(double)radians;
@end

RLM_HEADER_AUDIT_END(nullability)
111 changes: 111 additions & 0 deletions Realm/RLMGeospatial.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2023 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

#import "RLMGeospatial.h"

#import <realm/geospatial.hpp>

@implementation RLMGeospatial
- (realm::Geospatial)geoSpatial {
return realm::Geospatial{realm::GeoBox{realm::GeoPoint{1.1, 2.2}, realm::GeoPoint{1.1, 2,2}}};
}
@end

@implementation RLMGeospatialPoint
- (instancetype)initWithLatitude:(double)latitude longitude:(double)longitude {
if (self = [super init]) {
_latitude = latitude;
_longitude = longitude;
}
return self;
}

- (realm::GeoPoint)value {
return realm::GeoPoint{_longitude, _latitude};
}
@end

@implementation RLMGeospatialBox
- (instancetype)initWithBottomLeft:(RLMGeospatialPoint *)bottomLeft topRight:(RLMGeospatialPoint *)topRight {
if (self = [super init]) {
_bottomLeft = bottomLeft;
_topRight = topRight;
}
return self;
}

- (instancetype)initWithTop:(double)top left:(double)left bottom:(double)bottom right:(double)right {
if (self = [super init]) {
_bottomLeft = [[RLMGeospatialPoint alloc] initWithLatitude:bottom longitude:left];
_topRight = [[RLMGeospatialPoint alloc] initWithLatitude:top longitude:right];
}
return self;
}

- (realm::Geospatial)geoSpatial {
realm::GeoBox geo_box{realm::GeoPoint{_bottomLeft.longitude, _bottomLeft.latitude}, realm::GeoPoint{_topRight.longitude, _topRight.latitude}};
return realm::Geospatial{geo_box};
}
@end

@implementation RLMGeospatialPolygon
- (instancetype)initWithOuterRing:(NSArray<RLMGeospatialPoint *> *)outerRing holes:(nullable NSArray<NSArray<RLMGeospatialPoint *> *> *)holes {
if (self = [super init]) {
_outerRing = outerRing;
_holes = holes;
}
return self;
}

- (realm::Geospatial)geoSpatial {
std::vector<std::vector<realm::GeoPoint>> points;
std::vector<realm::GeoPoint> outer_ring;
for (RLMGeospatialPoint *point : _outerRing) {
outer_ring.push_back(point.value);
}
points.push_back(outer_ring);

if (_holes) {
std::vector<realm::GeoPoint> holes;
for (NSArray<RLMGeospatialPoint *> *array_points : _holes) {
for (RLMGeospatialPoint *point : array_points) {
holes.push_back(point.value);
}
}
points.push_back(holes);
}

realm::GeoPolygon geo_polygon{points};
return realm::Geospatial{geo_polygon};
}
@end

@implementation RLMGeospatialCircle
- (instancetype)initWithCenter:(RLMGeospatialPoint *)center radians:(double)radians {
if (self = [super init]) {
_center = center;
_radians = radians;
}
return self;
}

- (realm::Geospatial)geoSpatial {
realm::GeoCircle geo_circle{_radians, _center.value};
return realm::Geospatial{geo_circle};
}
@end
31 changes: 31 additions & 0 deletions Realm/RLMGeospatial_Private.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2023 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

#import <Realm/RLMGeospatial.h>

namespace realm {
class Geospatial;
}

RLM_HEADER_AUDIT_BEGIN(nullability, sendability)

@interface RLMGeospatial ()
- (realm::Geospatial)geoSpatial;
@end

RLM_HEADER_AUDIT_END(nullability, sendability)
Loading

0 comments on commit 6aa8a60

Please sign in to comment.