├── LICENSE ├── QuadTree.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── swiftpm │ │ └── Package.resolved └── xcuserdata │ └── aheze.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── QuadTree ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── Models │ ├── Cell.swift │ ├── Global.swift │ ├── Isoline.swift │ ├── Point.swift │ └── Unused.swift ├── QuadTree.entitlements ├── QuadTreeApp.swift ├── Rendering.swift ├── Utilities.swift └── ViewModel.swift └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Andrew Zheng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /QuadTree.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 56; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3CF755E82B3CAD8A00E4708E /* QuadTreeApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF755E72B3CAD8A00E4708E /* QuadTreeApp.swift */; }; 11 | 3CF755EA2B3CAD8A00E4708E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF755E92B3CAD8A00E4708E /* ContentView.swift */; }; 12 | 3CF755EC2B3CAD8B00E4708E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3CF755EB2B3CAD8B00E4708E /* Assets.xcassets */; }; 13 | 3CF755F72B3CADDD00E4708E /* Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF755F62B3CADDD00E4708E /* Cell.swift */; }; 14 | 3CF755FA2B3CB47F00E4708E /* Point.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF755F92B3CB47F00E4708E /* Point.swift */; }; 15 | 3CF755FD2B3CF68E00E4708E /* Collections in Frameworks */ = {isa = PBXBuildFile; productRef = 3CF755FC2B3CF68E00E4708E /* Collections */; }; 16 | 3CF755FF2B3CF68E00E4708E /* DequeModule in Frameworks */ = {isa = PBXBuildFile; productRef = 3CF755FE2B3CF68E00E4708E /* DequeModule */; }; 17 | 3CF756012B3CF68E00E4708E /* OrderedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = 3CF756002B3CF68E00E4708E /* OrderedCollections */; }; 18 | 3CF756032B3CF7DE00E4708E /* Global.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF756022B3CF7DE00E4708E /* Global.swift */; }; 19 | 3CF756052B3CFB0A00E4708E /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF756042B3CFB0A00E4708E /* Utilities.swift */; }; 20 | 3CF756072B3CFBDA00E4708E /* Rendering.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF756062B3CFBDA00E4708E /* Rendering.swift */; }; 21 | 3CF756092B3CFBFA00E4708E /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF756082B3CFBFA00E4708E /* ViewModel.swift */; }; 22 | 3CF7560B2B3D36F200E4708E /* Isoline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF7560A2B3D36F200E4708E /* Isoline.swift */; }; 23 | 3CF7560D2B3D774E00E4708E /* Unused.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF7560C2B3D774E00E4708E /* Unused.swift */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 3CF755E42B3CAD8A00E4708E /* QuadTree.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = QuadTree.app; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 3CF755E72B3CAD8A00E4708E /* QuadTreeApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuadTreeApp.swift; sourceTree = ""; }; 29 | 3CF755E92B3CAD8A00E4708E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 30 | 3CF755EB2B3CAD8B00E4708E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 3CF755ED2B3CAD8B00E4708E /* QuadTree.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = QuadTree.entitlements; sourceTree = ""; }; 32 | 3CF755F62B3CADDD00E4708E /* Cell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cell.swift; sourceTree = ""; }; 33 | 3CF755F92B3CB47F00E4708E /* Point.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Point.swift; sourceTree = ""; }; 34 | 3CF756022B3CF7DE00E4708E /* Global.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Global.swift; sourceTree = ""; }; 35 | 3CF756042B3CFB0A00E4708E /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; }; 36 | 3CF756062B3CFBDA00E4708E /* Rendering.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rendering.swift; sourceTree = ""; }; 37 | 3CF756082B3CFBFA00E4708E /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = ""; }; 38 | 3CF7560A2B3D36F200E4708E /* Isoline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Isoline.swift; sourceTree = ""; }; 39 | 3CF7560C2B3D774E00E4708E /* Unused.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unused.swift; sourceTree = ""; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | 3CF755E12B3CAD8A00E4708E /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | 3CF755FD2B3CF68E00E4708E /* Collections in Frameworks */, 48 | 3CF755FF2B3CF68E00E4708E /* DequeModule in Frameworks */, 49 | 3CF756012B3CF68E00E4708E /* OrderedCollections in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | 3CF755DB2B3CAD8A00E4708E = { 57 | isa = PBXGroup; 58 | children = ( 59 | 3CF755E62B3CAD8A00E4708E /* QuadTree */, 60 | 3CF755E52B3CAD8A00E4708E /* Products */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | 3CF755E52B3CAD8A00E4708E /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 3CF755E42B3CAD8A00E4708E /* QuadTree.app */, 68 | ); 69 | name = Products; 70 | sourceTree = ""; 71 | }; 72 | 3CF755E62B3CAD8A00E4708E /* QuadTree */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 3CF755F82B3CADE100E4708E /* Models */, 76 | 3CF755E72B3CAD8A00E4708E /* QuadTreeApp.swift */, 77 | 3CF756062B3CFBDA00E4708E /* Rendering.swift */, 78 | 3CF756082B3CFBFA00E4708E /* ViewModel.swift */, 79 | 3CF755E92B3CAD8A00E4708E /* ContentView.swift */, 80 | 3CF756042B3CFB0A00E4708E /* Utilities.swift */, 81 | 3CF755EB2B3CAD8B00E4708E /* Assets.xcassets */, 82 | 3CF755ED2B3CAD8B00E4708E /* QuadTree.entitlements */, 83 | ); 84 | path = QuadTree; 85 | sourceTree = ""; 86 | }; 87 | 3CF755F82B3CADE100E4708E /* Models */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 3CF756022B3CF7DE00E4708E /* Global.swift */, 91 | 3CF755F62B3CADDD00E4708E /* Cell.swift */, 92 | 3CF755F92B3CB47F00E4708E /* Point.swift */, 93 | 3CF7560A2B3D36F200E4708E /* Isoline.swift */, 94 | 3CF7560C2B3D774E00E4708E /* Unused.swift */, 95 | ); 96 | path = Models; 97 | sourceTree = ""; 98 | }; 99 | /* End PBXGroup section */ 100 | 101 | /* Begin PBXNativeTarget section */ 102 | 3CF755E32B3CAD8A00E4708E /* QuadTree */ = { 103 | isa = PBXNativeTarget; 104 | buildConfigurationList = 3CF755F32B3CAD8B00E4708E /* Build configuration list for PBXNativeTarget "QuadTree" */; 105 | buildPhases = ( 106 | 3CF755E02B3CAD8A00E4708E /* Sources */, 107 | 3CF755E12B3CAD8A00E4708E /* Frameworks */, 108 | 3CF755E22B3CAD8A00E4708E /* Resources */, 109 | ); 110 | buildRules = ( 111 | ); 112 | dependencies = ( 113 | ); 114 | name = QuadTree; 115 | packageProductDependencies = ( 116 | 3CF755FC2B3CF68E00E4708E /* Collections */, 117 | 3CF755FE2B3CF68E00E4708E /* DequeModule */, 118 | 3CF756002B3CF68E00E4708E /* OrderedCollections */, 119 | ); 120 | productName = QuadTree; 121 | productReference = 3CF755E42B3CAD8A00E4708E /* QuadTree.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 3CF755DC2B3CAD8A00E4708E /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | BuildIndependentTargetsInParallel = 1; 131 | LastSwiftUpdateCheck = 1500; 132 | LastUpgradeCheck = 1500; 133 | TargetAttributes = { 134 | 3CF755E32B3CAD8A00E4708E = { 135 | CreatedOnToolsVersion = 15.0; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 3CF755DF2B3CAD8A00E4708E /* Build configuration list for PBXProject "QuadTree" */; 140 | compatibilityVersion = "Xcode 14.0"; 141 | developmentRegion = en; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 3CF755DB2B3CAD8A00E4708E; 148 | packageReferences = ( 149 | 3CF755FB2B3CF68E00E4708E /* XCRemoteSwiftPackageReference "swift-collections" */, 150 | ); 151 | productRefGroup = 3CF755E52B3CAD8A00E4708E /* Products */; 152 | projectDirPath = ""; 153 | projectRoot = ""; 154 | targets = ( 155 | 3CF755E32B3CAD8A00E4708E /* QuadTree */, 156 | ); 157 | }; 158 | /* End PBXProject section */ 159 | 160 | /* Begin PBXResourcesBuildPhase section */ 161 | 3CF755E22B3CAD8A00E4708E /* Resources */ = { 162 | isa = PBXResourcesBuildPhase; 163 | buildActionMask = 2147483647; 164 | files = ( 165 | 3CF755EC2B3CAD8B00E4708E /* Assets.xcassets in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXSourcesBuildPhase section */ 172 | 3CF755E02B3CAD8A00E4708E /* Sources */ = { 173 | isa = PBXSourcesBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | 3CF756052B3CFB0A00E4708E /* Utilities.swift in Sources */, 177 | 3CF756072B3CFBDA00E4708E /* Rendering.swift in Sources */, 178 | 3CF755FA2B3CB47F00E4708E /* Point.swift in Sources */, 179 | 3CF7560D2B3D774E00E4708E /* Unused.swift in Sources */, 180 | 3CF755EA2B3CAD8A00E4708E /* ContentView.swift in Sources */, 181 | 3CF755E82B3CAD8A00E4708E /* QuadTreeApp.swift in Sources */, 182 | 3CF756032B3CF7DE00E4708E /* Global.swift in Sources */, 183 | 3CF756092B3CFBFA00E4708E /* ViewModel.swift in Sources */, 184 | 3CF7560B2B3D36F200E4708E /* Isoline.swift in Sources */, 185 | 3CF755F72B3CADDD00E4708E /* Cell.swift in Sources */, 186 | ); 187 | runOnlyForDeploymentPostprocessing = 0; 188 | }; 189 | /* End PBXSourcesBuildPhase section */ 190 | 191 | /* Begin XCBuildConfiguration section */ 192 | 3CF755F12B3CAD8B00E4708E /* Debug */ = { 193 | isa = XCBuildConfiguration; 194 | buildSettings = { 195 | ALWAYS_SEARCH_USER_PATHS = NO; 196 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 197 | CLANG_ANALYZER_NONNULL = YES; 198 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 199 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 200 | CLANG_ENABLE_MODULES = YES; 201 | CLANG_ENABLE_OBJC_ARC = YES; 202 | CLANG_ENABLE_OBJC_WEAK = YES; 203 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 204 | CLANG_WARN_BOOL_CONVERSION = YES; 205 | CLANG_WARN_COMMA = YES; 206 | CLANG_WARN_CONSTANT_CONVERSION = YES; 207 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 208 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 209 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 210 | CLANG_WARN_EMPTY_BODY = YES; 211 | CLANG_WARN_ENUM_CONVERSION = YES; 212 | CLANG_WARN_INFINITE_RECURSION = YES; 213 | CLANG_WARN_INT_CONVERSION = YES; 214 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 215 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 216 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 217 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 218 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 219 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 220 | CLANG_WARN_STRICT_PROTOTYPES = YES; 221 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 222 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 223 | CLANG_WARN_UNREACHABLE_CODE = YES; 224 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 225 | COPY_PHASE_STRIP = NO; 226 | DEBUG_INFORMATION_FORMAT = dwarf; 227 | ENABLE_STRICT_OBJC_MSGSEND = YES; 228 | ENABLE_TESTABILITY = YES; 229 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 230 | GCC_C_LANGUAGE_STANDARD = gnu17; 231 | GCC_DYNAMIC_NO_PIC = NO; 232 | GCC_NO_COMMON_BLOCKS = YES; 233 | GCC_OPTIMIZATION_LEVEL = 0; 234 | GCC_PREPROCESSOR_DEFINITIONS = ( 235 | "DEBUG=1", 236 | "$(inherited)", 237 | ); 238 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 239 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 240 | GCC_WARN_UNDECLARED_SELECTOR = YES; 241 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 242 | GCC_WARN_UNUSED_FUNCTION = YES; 243 | GCC_WARN_UNUSED_VARIABLE = YES; 244 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 245 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 246 | MTL_FAST_MATH = YES; 247 | ONLY_ACTIVE_ARCH = YES; 248 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 249 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 250 | }; 251 | name = Debug; 252 | }; 253 | 3CF755F22B3CAD8B00E4708E /* Release */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | ALWAYS_SEARCH_USER_PATHS = NO; 257 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 258 | CLANG_ANALYZER_NONNULL = YES; 259 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 261 | CLANG_ENABLE_MODULES = YES; 262 | CLANG_ENABLE_OBJC_ARC = YES; 263 | CLANG_ENABLE_OBJC_WEAK = YES; 264 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_COMMA = YES; 267 | CLANG_WARN_CONSTANT_CONVERSION = YES; 268 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 271 | CLANG_WARN_EMPTY_BODY = YES; 272 | CLANG_WARN_ENUM_CONVERSION = YES; 273 | CLANG_WARN_INFINITE_RECURSION = YES; 274 | CLANG_WARN_INT_CONVERSION = YES; 275 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 276 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 277 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 279 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | COPY_PHASE_STRIP = NO; 287 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 288 | ENABLE_NS_ASSERTIONS = NO; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 291 | GCC_C_LANGUAGE_STANDARD = gnu17; 292 | GCC_NO_COMMON_BLOCKS = YES; 293 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 294 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 295 | GCC_WARN_UNDECLARED_SELECTOR = YES; 296 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 297 | GCC_WARN_UNUSED_FUNCTION = YES; 298 | GCC_WARN_UNUSED_VARIABLE = YES; 299 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 300 | MTL_ENABLE_DEBUG_INFO = NO; 301 | MTL_FAST_MATH = YES; 302 | SWIFT_COMPILATION_MODE = wholemodule; 303 | }; 304 | name = Release; 305 | }; 306 | 3CF755F42B3CAD8B00E4708E /* Debug */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 311 | CODE_SIGN_ENTITLEMENTS = QuadTree/QuadTree.entitlements; 312 | CODE_SIGN_STYLE = Automatic; 313 | CURRENT_PROJECT_VERSION = 1; 314 | DEVELOPMENT_TEAM = WV6XDLHK3W; 315 | ENABLE_HARDENED_RUNTIME = YES; 316 | ENABLE_PREVIEWS = YES; 317 | GENERATE_INFOPLIST_FILE = YES; 318 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; 319 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; 320 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; 321 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; 322 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; 323 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; 324 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; 325 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; 326 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 327 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 328 | IPHONEOS_DEPLOYMENT_TARGET = 17.0; 329 | LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; 330 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; 331 | MACOSX_DEPLOYMENT_TARGET = 14.0; 332 | MARKETING_VERSION = 1.0; 333 | PRODUCT_BUNDLE_IDENTIFIER = app.getfind.QuadTree; 334 | PRODUCT_NAME = "$(TARGET_NAME)"; 335 | SDKROOT = auto; 336 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; 337 | SWIFT_EMIT_LOC_STRINGS = YES; 338 | SWIFT_VERSION = 5.0; 339 | TARGETED_DEVICE_FAMILY = "1,2"; 340 | }; 341 | name = Debug; 342 | }; 343 | 3CF755F52B3CAD8B00E4708E /* Release */ = { 344 | isa = XCBuildConfiguration; 345 | buildSettings = { 346 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 347 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 348 | CODE_SIGN_ENTITLEMENTS = QuadTree/QuadTree.entitlements; 349 | CODE_SIGN_STYLE = Automatic; 350 | CURRENT_PROJECT_VERSION = 1; 351 | DEVELOPMENT_TEAM = WV6XDLHK3W; 352 | ENABLE_HARDENED_RUNTIME = YES; 353 | ENABLE_PREVIEWS = YES; 354 | GENERATE_INFOPLIST_FILE = YES; 355 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; 356 | "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; 357 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; 358 | "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES; 359 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES; 360 | "INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphonesimulator*]" = YES; 361 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphoneos*]" = UIStatusBarStyleDefault; 362 | "INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault; 363 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 364 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 365 | IPHONEOS_DEPLOYMENT_TARGET = 17.0; 366 | LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; 367 | "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks"; 368 | MACOSX_DEPLOYMENT_TARGET = 14.0; 369 | MARKETING_VERSION = 1.0; 370 | PRODUCT_BUNDLE_IDENTIFIER = app.getfind.QuadTree; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | SDKROOT = auto; 373 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; 374 | SWIFT_EMIT_LOC_STRINGS = YES; 375 | SWIFT_VERSION = 5.0; 376 | TARGETED_DEVICE_FAMILY = "1,2"; 377 | }; 378 | name = Release; 379 | }; 380 | /* End XCBuildConfiguration section */ 381 | 382 | /* Begin XCConfigurationList section */ 383 | 3CF755DF2B3CAD8A00E4708E /* Build configuration list for PBXProject "QuadTree" */ = { 384 | isa = XCConfigurationList; 385 | buildConfigurations = ( 386 | 3CF755F12B3CAD8B00E4708E /* Debug */, 387 | 3CF755F22B3CAD8B00E4708E /* Release */, 388 | ); 389 | defaultConfigurationIsVisible = 0; 390 | defaultConfigurationName = Release; 391 | }; 392 | 3CF755F32B3CAD8B00E4708E /* Build configuration list for PBXNativeTarget "QuadTree" */ = { 393 | isa = XCConfigurationList; 394 | buildConfigurations = ( 395 | 3CF755F42B3CAD8B00E4708E /* Debug */, 396 | 3CF755F52B3CAD8B00E4708E /* Release */, 397 | ); 398 | defaultConfigurationIsVisible = 0; 399 | defaultConfigurationName = Release; 400 | }; 401 | /* End XCConfigurationList section */ 402 | 403 | /* Begin XCRemoteSwiftPackageReference section */ 404 | 3CF755FB2B3CF68E00E4708E /* XCRemoteSwiftPackageReference "swift-collections" */ = { 405 | isa = XCRemoteSwiftPackageReference; 406 | repositoryURL = "https://github.com/apple/swift-collections.git"; 407 | requirement = { 408 | kind = upToNextMajorVersion; 409 | minimumVersion = 1.0.6; 410 | }; 411 | }; 412 | /* End XCRemoteSwiftPackageReference section */ 413 | 414 | /* Begin XCSwiftPackageProductDependency section */ 415 | 3CF755FC2B3CF68E00E4708E /* Collections */ = { 416 | isa = XCSwiftPackageProductDependency; 417 | package = 3CF755FB2B3CF68E00E4708E /* XCRemoteSwiftPackageReference "swift-collections" */; 418 | productName = Collections; 419 | }; 420 | 3CF755FE2B3CF68E00E4708E /* DequeModule */ = { 421 | isa = XCSwiftPackageProductDependency; 422 | package = 3CF755FB2B3CF68E00E4708E /* XCRemoteSwiftPackageReference "swift-collections" */; 423 | productName = DequeModule; 424 | }; 425 | 3CF756002B3CF68E00E4708E /* OrderedCollections */ = { 426 | isa = XCSwiftPackageProductDependency; 427 | package = 3CF755FB2B3CF68E00E4708E /* XCRemoteSwiftPackageReference "swift-collections" */; 428 | productName = OrderedCollections; 429 | }; 430 | /* End XCSwiftPackageProductDependency section */ 431 | }; 432 | rootObject = 3CF755DC2B3CAD8A00E4708E /* Project object */; 433 | } 434 | -------------------------------------------------------------------------------- /QuadTree.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /QuadTree.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /QuadTree.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "swift-collections", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/apple/swift-collections.git", 7 | "state" : { 8 | "revision" : "d029d9d39c87bed85b1c50adee7c41795261a192", 9 | "version" : "1.0.6" 10 | } 11 | } 12 | ], 13 | "version" : 2 14 | } 15 | -------------------------------------------------------------------------------- /QuadTree.xcodeproj/xcuserdata/aheze.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | QuadTree.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /QuadTree/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /QuadTree/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "scale" : "1x", 11 | "size" : "16x16" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "scale" : "2x", 16 | "size" : "16x16" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "scale" : "1x", 21 | "size" : "32x32" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "scale" : "2x", 26 | "size" : "32x32" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "scale" : "1x", 31 | "size" : "128x128" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "scale" : "2x", 36 | "size" : "128x128" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "scale" : "1x", 41 | "size" : "256x256" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "scale" : "2x", 46 | "size" : "256x256" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "scale" : "1x", 51 | "size" : "512x512" 52 | }, 53 | { 54 | "idiom" : "mac", 55 | "scale" : "2x", 56 | "size" : "512x512" 57 | } 58 | ], 59 | "info" : { 60 | "author" : "xcode", 61 | "version" : 1 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /QuadTree/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /QuadTree/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Charts 10 | import SwiftUI 11 | 12 | struct ContentView: View { 13 | @StateObject var viewModel = ViewModel() 14 | 15 | var body: some View { 16 | VStack { 17 | 18 | Color.clear 19 | .frame(width: viewModel.viewportSize.width, height: viewModel.viewportSize.height) 20 | .overlay { 21 | chart 22 | } 23 | } 24 | .padding() 25 | .navigationTitle("Quadtree") 26 | } 27 | 28 | var chart: some View { 29 | Chart { 30 | ForEach(viewModel.graphCurves) { graphCurve in 31 | ForEach(graphCurve.points, id: \.x) { point in 32 | LineMark(x: .value("x", point.x), y: .value("y", point.y), series: .value("Series", "\(graphCurve.id.uuidString)")) 33 | .foregroundStyle(Color.blue) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #Preview { 41 | ContentView() 42 | } 43 | -------------------------------------------------------------------------------- /QuadTree/Models/Cell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Cell.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Frame { 12 | var bL: ValuedPoint 13 | var bR: ValuedPoint 14 | var tL: ValuedPoint 15 | var tR: ValuedPoint 16 | 17 | // In 2 dimensions, vertices = [bottom-left, bottom-right, top-left, top-right] points 18 | var vertices: [ValuedPoint] { 19 | [self.bL, self.bR, self.tL, self.tR] 20 | } 21 | } 22 | 23 | class Cell { 24 | var frame: Frame 25 | var depth: Int 26 | var children: [Cell] 27 | var parent: Cell? 28 | 29 | // 0, 1, 2, or 3 30 | // 4 corners 31 | var childDirection: Int 32 | 33 | init(frame: Frame, depth: Int, children: [Cell], parent: Cell?, childDirection: Int) { 34 | self.frame = frame 35 | self.depth = depth 36 | self.children = children 37 | self.parent = parent 38 | self.childDirection = childDirection 39 | } 40 | 41 | func computeChildren(function: (Point) -> Double) { 42 | guard self.children.isEmpty else { 43 | fatalError("Already has children") 44 | } 45 | 46 | let vertices = self.frame.vertices 47 | for index in vertices.indices { 48 | let vertex = vertices[index] 49 | 50 | let xMin = (frame.bL.point.x + vertex.point.x) / 2 51 | let xMax = (frame.tR.point.x + vertex.point.x) / 2 52 | let yMin = (frame.bL.point.y + vertex.point.y) / 2 53 | let yMax = (frame.tR.point.y + vertex.point.y) / 2 54 | let frame = Global.frameFromCorners(xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax, function: function) 55 | 56 | let newQuad = Cell(frame: frame, depth: depth + 1, children: [], parent: self, childDirection: index) 57 | self.children.append(newQuad) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /QuadTree/Models/Global.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Global.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Collections 10 | import Foundation 11 | import simd // for sign 12 | 13 | enum Global {} 14 | 15 | // MARK: - Frame 16 | 17 | extension Global { 18 | // get frame of vertices from each corner 19 | static func frameFromCorners( 20 | xMin: Double, 21 | xMax: Double, 22 | yMin: Double, 23 | yMax: Double, 24 | function: (Point) -> Double 25 | ) -> Frame { 26 | let bLPoint = Point(x: xMin, y: yMin) 27 | let bRPoint = Point(x: xMax, y: yMin) 28 | let tLPoint = Point(x: xMin, y: yMax) 29 | let tRPoint = Point(x: xMax, y: yMax) 30 | 31 | let bL = ValuedPoint(point: bLPoint, value: function(bLPoint)) 32 | let bR = ValuedPoint(point: bRPoint, value: function(bRPoint)) 33 | let tL = ValuedPoint(point: tLPoint, value: function(tLPoint)) 34 | let tR = ValuedPoint(point: tRPoint, value: function(tRPoint)) 35 | 36 | let frame = Frame(bL: bL, bR: bR, tL: tL, tR: tR) 37 | return frame 38 | } 39 | 40 | static func binarySearchZero( 41 | p1: ValuedPoint, 42 | p2: ValuedPoint, 43 | function: (Point) -> Double, 44 | tolerance: Double 45 | ) -> (valuedPoint: ValuedPoint, isZero: Bool) { 46 | let distanceX = abs(p2.point.x - p1.point.x) 47 | let distanceY = abs(p2.point.y - p1.point.y) 48 | 49 | // Use isZero to make sure it's not an asymptote like at x=0 on f(x,y) = 1/(xy) - 1 50 | if distanceX < tolerance, distanceY < tolerance { 51 | // Binary search stop condition: too small to matter 52 | let valuedPoint = ValuedPoint.intersectZero(p1: p1, p2: p2, function: function) 53 | 54 | let isZero: Bool = { 55 | if valuedPoint.value == 0 { 56 | return true 57 | } 58 | 59 | if 60 | // prevent ≈inf from registering as a zero 61 | abs(valuedPoint.value) < 1e200, 62 | sign(valuedPoint.value - p1.value) == sign(p2.value - valuedPoint.value) 63 | { 64 | return true 65 | } 66 | 67 | return false 68 | }() 69 | 70 | return (valuedPoint, isZero) 71 | } else { 72 | // binary search 73 | 74 | let midpoint = ValuedPoint.midpoint(p1: p1, p2: p2, function: function) 75 | if midpoint.value == 0 { 76 | return (midpoint, true) 77 | 78 | } else if (midpoint.value > 0) == (p1.value > 0) { 79 | // (Group "0" with negatives) 80 | 81 | return binarySearchZero(p1: midpoint, p2: p2, function: function, tolerance: tolerance) 82 | } else { 83 | // negatives 84 | return binarySearchZero(p1: p1, p2: midpoint, function: function, tolerance: tolerance) 85 | } 86 | } 87 | } 88 | } 89 | 90 | // MARK: - Cell 91 | 92 | extension Global { 93 | static func buildTree( 94 | function: (Point) -> Double, 95 | xMin: Double, 96 | xMax: Double, 97 | yMin: Double, 98 | yMax: Double, 99 | minDepth: Int, 100 | maxCells: Int, 101 | tolerance: Double 102 | ) -> Cell { 103 | // 4 branches 104 | let branchingFactor = 4 105 | 106 | let maxCellFromMinDepth = Int(pow(Double(branchingFactor), Double(minDepth))) 107 | 108 | // min_depth takes precedence over max_quads 109 | let maxCells = max(maxCellFromMinDepth, maxCells) 110 | 111 | let frame = Global.frameFromCorners(xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax, function: function) 112 | 113 | // root's childDirection is 0, even though none is reasonable 114 | let root = Cell(frame: frame, depth: 0, children: [], parent: nil, childDirection: 0) 115 | 116 | var quadQueue: Deque = [root] 117 | var leafCount = 1 118 | 119 | while !quadQueue.isEmpty && leafCount < maxCells { 120 | guard let currentQuad = quadQueue.popFirst() else { 121 | print("No current quad?") 122 | break 123 | } 124 | 125 | if currentQuad.depth < minDepth || shouldDescendDeepCell(cell: currentQuad, tolerance: tolerance) { 126 | currentQuad.computeChildren(function: function) 127 | quadQueue.append(contentsOf: currentQuad.children) 128 | 129 | // add 4 for the new quads, subtract 1 for the old quad not being a leaf anymore 130 | leafCount += branchingFactor - 1 131 | } 132 | } 133 | 134 | return root 135 | } 136 | 137 | static func shouldDescendDeepCell(cell: Cell, tolerance: Double) -> Bool { 138 | let distanceX = cell.frame.tR.point.x - cell.frame.bL.point.x 139 | let distanceY = cell.frame.tR.point.y - cell.frame.bL.point.y 140 | 141 | let adjustedTolerance = 10 * tolerance 142 | if distanceX < adjustedTolerance && distanceY < adjustedTolerance { 143 | // Too small of a cell to be worth descending 144 | // We compare to 10*tol instead of tol because the simplices are smaller than the quads 145 | // The factor 10 itself is arbitrary. 146 | return false 147 | } else if cell.frame.vertices.allSatisfy({ $0.value.isNaN }) { 148 | // in a region where the function is undefined 149 | return false 150 | } else if cell.frame.vertices.contains(where: { $0.value.isNaN }) { 151 | // straddling defined and undefined 152 | 153 | return true 154 | } else { 155 | // simple approach: only descend if we cross the isoline 156 | // (check if at least one of the vertex values has a different sign) 157 | // TODO: This could very much be improved: 158 | // e.g. by incorporating gradient or second-derivative 159 | // tests, etc., to cancel descending in approximately linear regions 160 | for valuedPoint in cell.frame.vertices.dropFirst() { 161 | if sign(valuedPoint.value) != sign(cell.frame.bL.value) { 162 | return true 163 | } 164 | } 165 | 166 | return false 167 | } 168 | } 169 | } 170 | 171 | // MARK: Triangle 172 | 173 | extension Global { 174 | // a, b, c, d should be clockwise oriented, with center on the inside of that quad 175 | static func fourTriangles( 176 | a: ValuedPoint, 177 | b: ValuedPoint, 178 | c: ValuedPoint, 179 | d: ValuedPoint, 180 | center: ValuedPoint 181 | ) -> (Triangle, Triangle, Triangle, Triangle) { 182 | let triangles = ( 183 | Triangle(vertices: [a, b, center]), 184 | Triangle(vertices: [b, c, center]), 185 | Triangle(vertices: [c, d, center]), 186 | Triangle(vertices: [d, a, center]) 187 | ) 188 | 189 | return triangles 190 | } 191 | } 192 | 193 | // MARK: - Isoline 194 | 195 | extension Global { 196 | // Get the curve representing fn([x,y])=0 on pmin[0] ≤ x ≤ pmax[0] ∩ pmin[1] ≤ y ≤ pmax[1] 197 | // Returns as a list of curves, where each curve is a list of points 198 | static func plotIsoline( 199 | function: @escaping (Point) -> Double, 200 | xMin: Double, 201 | xMax: Double, 202 | yMin: Double, 203 | yMax: Double, 204 | minDepth: Int = 6, 205 | maxCells: Int = 20000, 206 | tolerance: Double? = nil 207 | ) -> [[Point]] { 208 | let tol: Double 209 | if let tolerance { 210 | tol = tolerance 211 | } else { 212 | tol = (xMax - xMin) / 1000 213 | } 214 | 215 | let root = buildTree(function: function, xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax, minDepth: minDepth, maxCells: maxCells, tolerance: tol) 216 | let triangulator = Triangulator(root: root, function: function) 217 | let triangles = triangulator.triangulate() 218 | let curveTracer = CurveTracer(triangles: triangles, function: function, tolerance: tol) 219 | let curves = curveTracer.trace() 220 | return curves 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /QuadTree/Models/Isoline.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Isoline.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class Triangle { 12 | var vertices: [ValuedPoint] 13 | 14 | // The order of triangle "next" is such that, when walking along the isoline in the direction of next, 15 | // you keep positive function values on your right and negative function values on your left. 16 | var next: Triangle? 17 | var previous: Triangle? 18 | var visited = false 19 | 20 | init(vertices: [ValuedPoint], next: Triangle? = nil, previous: Triangle? = nil, visited: Bool = false) { 21 | self.vertices = vertices 22 | self.next = next 23 | self.previous = previous 24 | self.visited = visited 25 | } 26 | 27 | func setNext(other: Triangle) { 28 | next = other 29 | other.previous = self 30 | } 31 | } 32 | 33 | // While triangulating, also compute the isolines. 34 | // 35 | // Divides each quad into 8 triangles from the quad's center. This simplifies 36 | // adjacencies between triangles for the general case of multiresolution quadtrees. 37 | // 38 | // Based on Manson, Josiah, and Scott Schaefer. "Isosurfaces 39 | // over simplicial partitions of multiresolution grids." Computer Graphics Forum. 40 | // Vol. 29. No. 2. Oxford, UK: Blackwell Publishing Ltd, 2010. 41 | // (https://people.engr.tamu.edu/schaefer/research/iso_simplicial.pdf), 42 | // but this does not currently implement placing dual vertices based on the gradient. 43 | class Triangulator { 44 | var triangles = [Triangle]() 45 | 46 | // ID to triangle 47 | var hangingNext = [Point: Triangle]() 48 | 49 | var root: Cell 50 | 51 | var function: (Point) -> Double 52 | 53 | init(root: Cell, function: @escaping (Point) -> Double) { 54 | self.root = root 55 | self.function = function 56 | } 57 | 58 | func triangulate() -> [Triangle] { 59 | triangulate(inside: root) 60 | return triangles 61 | } 62 | 63 | func triangulate(inside quad: Cell) { 64 | guard !quad.children.isEmpty else { 65 | return 66 | } 67 | 68 | for child in quad.children { 69 | triangulate(inside: child) 70 | } 71 | 72 | // bL, bR 73 | triangulateCrossingRow(a: quad.children[0], b: quad.children[1]) 74 | 75 | // tL, tR 76 | triangulateCrossingRow(a: quad.children[2], b: quad.children[3]) 77 | 78 | // bL, tL 79 | triangulateCrossingColumn(a: quad.children[0], b: quad.children[2]) 80 | 81 | // bR, tR 82 | triangulateCrossingColumn(a: quad.children[1], b: quad.children[3]) 83 | } 84 | 85 | func triangulateCrossingRow(a: Cell, b: Cell) { 86 | // Quad b should be to the right (greater x values) than quad a 87 | 88 | if !a.children.isEmpty, !b.children.isEmpty { 89 | // bR cell | bL cell 90 | triangulateCrossingRow(a: a.children[1], b: b.children[0]) 91 | 92 | // tR cell | tL cell 93 | triangulateCrossingRow(a: a.children[3], b: b.children[2]) 94 | } else if !a.children.isEmpty { 95 | // bR cell | big cell to right 96 | triangulateCrossingRow(a: a.children[1], b: b) 97 | 98 | // tR cell | big cell to right 99 | triangulateCrossingRow(a: a.children[3], b: b) 100 | } else if !b.children.isEmpty { 101 | // big cell to left | bL cell 102 | triangulateCrossingRow(a: a, b: b.children[0]) 103 | 104 | // big cell to left | tL cell 105 | triangulateCrossingRow(a: a, b: b.children[2]) 106 | } else { 107 | // a and b are minimal 2-cells (need to have triangles in between) 108 | let faceDualA = getFaceDual(frame: a.frame) 109 | let faceDualB = getFaceDual(frame: b.frame) 110 | 111 | // Add the four triangles from the centers of a and b to the shared edge between them 112 | if a.depth < b.depth { 113 | // a is a big cell, b is small cell 114 | // 115 | // +---+---+---+---+ 116 | // | | b | | 117 | // + a +---+---+ 118 | // | | | | 119 | // +---+---+---+---+ 120 | // 121 | // add line segment a to midpoint of b's left edge 122 | // result has 2 triangles in each cell 123 | let edgeDual = getEdgeDual(p1: b.frame.tL, p2: b.frame.bL) 124 | 125 | // triangles arranged like a diamond 126 | let triangles = Global.fourTriangles( 127 | a: b.frame.tL, 128 | b: faceDualB, 129 | c: b.frame.bL, 130 | d: faceDualA, 131 | center: edgeDual 132 | ) 133 | 134 | addFourTriangles(triangles: triangles) 135 | } else { 136 | // a is a small cell, b is a big cell 137 | // OR: same depth, a and b are adjacent horizontally 138 | let edgeDual = getEdgeDual(p1: a.frame.tR, p2: a.frame.bR) 139 | 140 | // result of code for same depth 141 | // +---+---+---+---+ 142 | // | / | \ | 143 | // + a + b + 144 | // | \ | / | 145 | // +---+---+---+---+ 146 | let triangles = Global.fourTriangles( 147 | a: a.frame.tR, 148 | b: faceDualB, 149 | c: a.frame.bR, 150 | d: faceDualA, 151 | center: edgeDual 152 | ) 153 | 154 | addFourTriangles(triangles: triangles) 155 | } 156 | } 157 | } 158 | 159 | // Mostly a copy-paste of triangulate_crossing_row. For n-dimensions, 160 | // want to pass a dir index into a shared triangulate_crossing_dir function instead 161 | func triangulateCrossingColumn(a: Cell, b: Cell) { 162 | if !a.children.isEmpty, !b.children.isEmpty { 163 | // tL cell | bL cell 164 | triangulateCrossingColumn(a: a.children[2], b: b.children[0]) 165 | 166 | // tR cell | bT cell 167 | triangulateCrossingColumn(a: a.children[3], b: b.children[1]) 168 | } else if !a.children.isEmpty { 169 | triangulateCrossingColumn(a: a.children[2], b: b) 170 | triangulateCrossingColumn(a: a.children[3], b: b) 171 | } else if !b.children.isEmpty { 172 | triangulateCrossingColumn(a: a, b: b.children[0]) 173 | triangulateCrossingColumn(a: a, b: b.children[1]) 174 | } else { 175 | // a and b are minimal 2-cells (need to have triangles in between) 176 | 177 | let faceDualA = getFaceDual(frame: a.frame) 178 | let faceDualB = getFaceDual(frame: b.frame) 179 | 180 | // Add the four triangles from the centers of a and b to the shared edge between them 181 | if a.depth < b.depth { 182 | // b is smaller 183 | let edgeDual = getEdgeDual(p1: b.frame.bL, p2: b.frame.bR) 184 | let triangles = Global.fourTriangles( 185 | a: b.frame.bL, 186 | b: faceDualB, 187 | c: b.frame.bR, 188 | d: faceDualA, 189 | center: edgeDual 190 | ) 191 | addFourTriangles(triangles: triangles) 192 | } else { 193 | let edgeDual = getEdgeDual(p1: a.frame.tL, p2: a.frame.tR) 194 | let triangles = Global.fourTriangles( 195 | a: a.frame.tL, 196 | b: faceDualB, 197 | c: a.frame.tR, 198 | d: faceDualA, 199 | center: edgeDual 200 | ) 201 | addFourTriangles(triangles: triangles) 202 | } 203 | } 204 | } 205 | 206 | func addFourTriangles(triangles: (Triangle, Triangle, Triangle, Triangle)) { 207 | nextSandwichTriangles(a: triangles.0, b: triangles.1, c: triangles.2) 208 | nextSandwichTriangles(a: triangles.1, b: triangles.2, c: triangles.3) 209 | nextSandwichTriangles(a: triangles.2, b: triangles.3, c: triangles.0) 210 | nextSandwichTriangles(a: triangles.3, b: triangles.0, c: triangles.1) 211 | self.triangles.append(triangles.0) 212 | self.triangles.append(triangles.1) 213 | self.triangles.append(triangles.2) 214 | self.triangles.append(triangles.3) 215 | } 216 | 217 | func nextSandwichTriangles(a: Triangle, b: Triangle, c: Triangle) { 218 | // Find the "next" triangle for the triangle b. See Triangle for a description of the curve orientation. 219 | // We assume the triangles are oriented such that they share common vertices 220 | // center←[2]≡b[2]≡c[2] and x←a[1]≡b[0], y←b[1]≡c[0] 221 | 222 | let center = b.vertices[2] 223 | let x = b.vertices[0] 224 | let y = b.vertices[1] 225 | 226 | // Simple connections: inside the same four triangles 227 | // (Group 0 with negatives) 228 | if center.value > 0, y.value <= 0 { 229 | b.setNext(other: c) 230 | } 231 | 232 | // (Group 0 with negatives) 233 | if x.value > 0, center.value <= 0 { 234 | b.setNext(other: a) 235 | } 236 | 237 | // More difficult connections: complete a hanging connection 238 | // or wait for another triangle to complete this 239 | // We index using (double) the midpoint of the hanging edge 240 | let doubleMidpointX = x.point.x + y.point.x 241 | let doubleMidpointY = x.point.y + y.point.y 242 | 243 | // use as a key 244 | let doubleMidpoint = Point(x: doubleMidpointX, y: doubleMidpointY) 245 | 246 | // (Group 0 with negatives) 247 | if y.value > 0, x.value <= 0 { 248 | if let matchingTriangle = hangingNext[doubleMidpoint] { 249 | b.setNext(other: matchingTriangle) 250 | } else { 251 | hangingNext[doubleMidpoint] = b 252 | } 253 | } else if y.value <= 0, x.value > 0 { 254 | if let matchingTriangle = hangingNext[doubleMidpoint] { 255 | matchingTriangle.setNext(other: b) 256 | } else { 257 | hangingNext[doubleMidpoint] = b 258 | } 259 | } 260 | } 261 | } 262 | 263 | extension Triangulator { 264 | // Returns the dual point on an edge p1--p2 265 | func getEdgeDual(p1: ValuedPoint, p2: ValuedPoint) -> ValuedPoint { 266 | if (p1.value > 0) != (p2.value > 0) { 267 | // The edge crosses the isoline, so take the midpoint 268 | return ValuedPoint.midpoint(p1: p1, p2: p2, function: function) 269 | } 270 | 271 | let dt = Double(0.01) 272 | 273 | // ∇f(p1) is the gradient (derivative) of the function at p1 274 | // We intersect the planes with normals <∇f(p1), -1> and <∇f(p2), -1> 275 | 276 | // move slightly from p1 to p2. df = ∆f, so ∆f/∆t = 100*df1 near p1 277 | let point1X = p1.point.x * (1 - dt) + p2.point.x * dt 278 | let point1Y = p1.point.y * (1 - dt) + p2.point.y * dt 279 | let point1 = Point(x: point1X, y: point1Y) 280 | let df1 = function(point1) 281 | 282 | // move slightly from p2 to p1. df = ∆f, so ∆f/∆t = -100*df2 near p2 283 | let point2X = p1.point.x * dt + p2.point.x * (1 - dt) 284 | let point2Y = p1.point.y * dt + p2.point.y * (1 - dt) 285 | let point2 = Point(x: point2X, y: point2Y) 286 | let df2 = function(point2) 287 | 288 | // (Group 0 with negatives) 289 | if (df1 > 0) == (df2 > 0) { 290 | // The function either increases → ← or ← →, so a lerp would shoot out of bounds 291 | // Take the midpoint 292 | return ValuedPoint.midpoint(p1: p1, p2: p2, function: function) 293 | } else { 294 | // Function increases → 0 → or ← 0 ← 295 | let v1 = ValuedPoint(point: p1.point, value: df1) 296 | let v2 = ValuedPoint(point: p2.point, value: df2) 297 | return ValuedPoint.intersectZero(p1: v1, p2: v2, function: function) 298 | } 299 | } 300 | 301 | func getFaceDual(frame: Frame) -> ValuedPoint { 302 | // TODO: proper face dual 303 | return ValuedPoint.midpoint(p1: frame.bL, p2: frame.tR, function: function) 304 | } 305 | } 306 | 307 | class CurveTracer { 308 | var triangles: [Triangle] 309 | var function: (Point) -> Double 310 | var tolerance: Double 311 | 312 | var activeCurve = [Point]() 313 | 314 | init(triangles: [Triangle], function: @escaping (Point) -> Double, tolerance: Double) { 315 | self.triangles = triangles 316 | self.function = function 317 | self.tolerance = tolerance 318 | } 319 | 320 | func trace() -> [[Point]] { 321 | var curves = [[Point]]() 322 | 323 | for triangle in triangles { 324 | if !triangle.visited, triangle.next != nil { 325 | activeCurve = [] 326 | marchTriangle(triangle: triangle) 327 | 328 | // triangle.next is not None, so there should be at least one segment 329 | curves.append(activeCurve) 330 | } 331 | } 332 | 333 | return curves 334 | } 335 | 336 | func marchTriangle(triangle: Triangle) { 337 | let startTriangle = triangle 338 | var triangle: Triangle? = triangle 339 | var closedLoop = false 340 | 341 | // Iterate backwards to the start of a connected curve 342 | while let previous = triangle?.previous { 343 | triangle = previous 344 | // check if points to the same address 345 | if previous === startTriangle { 346 | closedLoop = true 347 | break 348 | } 349 | } 350 | 351 | while let unwrappedTriangle = triangle, !unwrappedTriangle.visited { 352 | for index in 0 ..< 3 { 353 | let startIndex = index 354 | let endIndex = (index + 1) % 3 // cycle through the vertices 355 | marchEdge(p1: unwrappedTriangle.vertices[startIndex], p2: unwrappedTriangle.vertices[endIndex]) 356 | } 357 | unwrappedTriangle.visited = true 358 | triangle = unwrappedTriangle.next 359 | } 360 | 361 | if closedLoop { 362 | // check if it's not empty 363 | if let first = activeCurve.first { 364 | // close back the loop 365 | activeCurve.append(first) 366 | } 367 | } 368 | } 369 | 370 | func marchEdge(p1: ValuedPoint, p2: ValuedPoint) { 371 | // (Group 0 with negatives) 372 | if p1.value > 0, p2.value <= 0 { 373 | let (intersection, isZero) = Global.binarySearchZero(p1: p1, p2: p2, function: function, tolerance: tolerance) 374 | if isZero { 375 | activeCurve.append(intersection.point) 376 | } 377 | } 378 | } 379 | } 380 | -------------------------------------------------------------------------------- /QuadTree/Models/Point.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Point.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Point: Equatable, Hashable { 12 | var x: Double 13 | var y: Double 14 | } 15 | 16 | // a point with the function value at the point 17 | struct ValuedPoint { 18 | var point: Point 19 | var value: Double 20 | 21 | static func midpoint(p1: ValuedPoint, p2: ValuedPoint, function: (Point) -> Double) -> ValuedPoint { 22 | let midpointX = (p1.point.x + p2.point.x) / 2 23 | let midpointY = (p1.point.y + p2.point.y) / 2 24 | let midpoint = Point(x: midpointX, y: midpointY) 25 | let valuedPoint = ValuedPoint(point: midpoint, value: function(midpoint)) 26 | return valuedPoint 27 | } 28 | 29 | // Find the point on line p1--p2 with value 0 30 | // linear interpolation 31 | static func intersectZero(p1: ValuedPoint, p2: ValuedPoint, function: (Point) -> Double) -> ValuedPoint { 32 | // get difference between values 33 | let denominator = p1.value - p2.value 34 | 35 | // Calculate the "pull" for p1 and p2 36 | // if k1 is super small, then "pull" towards k2 37 | let k1 = -p2.value / denominator 38 | let k2 = p1.value / denominator 39 | 40 | // Apply weights 41 | let pointX = (k1 * p1.point.x) + (k2 * p2.point.x) 42 | let pointY = (k1 * p1.point.y) + (k2 * p2.point.y) 43 | 44 | let point = Point(x: pointX, y: pointY) 45 | let valuedPoint = ValuedPoint(point: point, value: function(point)) 46 | return valuedPoint 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /QuadTree/Models/Unused.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Unused.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/28/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | // Unused functions, for 3D isosurfaces 12 | extension Cell { 13 | func getLeavesInDirection(axis: Int, direction: Int) -> AnyIterator { 14 | return AnyIterator { 15 | if !self.children.isEmpty { 16 | // 01 (1) for x axis (horizontal) 17 | // 10 (2) for y axis (vertical) 18 | let mask = 1 << axis 19 | 20 | // 2 dimensions 21 | // 00 (0) 22 | // 01 (1) 23 | // 10 (2) 24 | // 11 (3) 25 | for index in 0 ..< 4 { 26 | // (index & mask) possible values and their meanings: 27 | // For x axis (mask = 01):   For y axis (mask = 10): 28 | // 00 & 01 = 00 (0)   00 & 10 = 00 (0) -> bL 29 | // 01 & 01 = 01 (1)   01 & 10 = 00 (0) -> bR 30 | // 10 & 01 = 00 (0)   10 & 10 = 10 (2) -> tL 31 | // 11 & 01 = 01 (1)   11 & 10 = 10 (2) -> tR 32 | 33 | // For the x-axis, children with an index of 1 or 3 (binary 01 or 11) will satisfy ((index & mask) > 0). 34 | // For the y-axis, children with an index of 2 or 3 (binary 10 or 11) will satisfy this condition. 35 | // The comparison ((index & mask) > 0) == (direction > 0) ensures that only children on the specified direction are considered. 36 | // If direction is 0, it targets the negative direction (left or bottom), 37 | // and if direction is 1, it targets the positive direction (right or top). 38 | if ((index & mask) > 0) == (direction > 0) { 39 | let leaves = self.children[index].getLeavesInDirection(axis: axis, direction: direction) 40 | for leaf in leaves { 41 | return leaf 42 | } 43 | } 44 | } 45 | 46 | return nil 47 | } else { 48 | return self 49 | } 50 | } 51 | } 52 | 53 | // Same arguments as get_leaves_in_direction. 54 | // Returns the quad (with depth <= self.depth) that shares a (dim-1)-cell 55 | // with self, where that (dim-1)-cell is the side of self defined by 56 | // axis and dir. 57 | func walkInDirection(axis: Int, direction: Int) -> Cell? { 58 | // 01 (1) for x axis (horizontal) 59 | // 10 (2) for y axis (vertical) 60 | let mask = 1 << axis 61 | 62 | // childDirection possible values: 63 | // 00 (0) bL 64 | // 01 (1) bR 65 | // 10 (2) tL 66 | // 11 (3) tR 67 | 68 | // (childDirection & mask) returns true if on the positive side 69 | if ((self.childDirection & mask) > 0) == (direction > 0) { 70 | // on the right side of the parent cell and moving right (or analogous) 71 | // so need to go up through the parent's parent 72 | 73 | if let parent { 74 | let parentWalked = parent.walkInDirection(axis: axis, direction: direction) 75 | 76 | if let parentWalked, !parentWalked.children.isEmpty { 77 | // end at same depth, in the adjacent cell 78 | // from a to b 79 | // 80 | // +---+---+ +---+---+ 81 | // | | | | | | 82 | // +---+---+ +---+---+ 83 | // | | a | | b | | 84 | // +---+---+ +---+---+ 85 | // 86 | 87 | // If you are moving along the x-axis and childDirection is 01 (bottom-right), 88 | // XOR with 01 (x-axis mask) changes it to 00 (bottom-left). 89 | // 90 | // If moving along the y-axis and childDirection is 10 (top-left), 91 | // XOR with 10 (y-axis mask) changes it to 00 (bottom-left). 92 | return parentWalked.children[self.childDirection ^ mask] 93 | } else { 94 | // end at lesser depth (bigger quad) 95 | return parentWalked 96 | } 97 | } else { 98 | return nil 99 | } 100 | } else { 101 | // try to get a sibling cell 102 | if let parent { 103 | return parent.children[self.childDirection ^ mask] 104 | } else { 105 | return nil 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /QuadTree/QuadTree.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /QuadTree/QuadTreeApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // QuadTreeApp.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | @main 12 | struct QuadTreeApp: App { 13 | var body: some Scene { 14 | WindowGroup { 15 | ContentView() 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /QuadTree/Rendering.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Rendering.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct GraphCurve: Identifiable { 12 | var id = UUID() 13 | var points: [Point] 14 | } 15 | 16 | struct DisplayedCell: Identifiable { 17 | var id = UUID() 18 | var cell: Cell 19 | var frame: CGRect 20 | } 21 | 22 | extension Cell { 23 | public func levelOrderTraversal(visit: (Cell) -> Void) { 24 | visit(self) 25 | var queue = [Cell]() 26 | children.forEach { queue.append($0) } 27 | 28 | while !queue.isEmpty { 29 | let node = queue.removeFirst() 30 | visit(node) 31 | node.children.forEach { queue.append($0) } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /QuadTree/Utilities.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Utilities.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class TimeElapsed: CustomStringConvertible { 12 | private let startTime: CFAbsoluteTime 13 | private var endTime: CFAbsoluteTime? 14 | 15 | init() { 16 | startTime = CFAbsoluteTimeGetCurrent() 17 | } 18 | 19 | var description: String { 20 | time 21 | } 22 | 23 | var time: String { 24 | let format = String(format: "%.5f", duration) 25 | let string = "[\(format)s]" 26 | return string 27 | } 28 | 29 | var duration: Double { 30 | let endTime = CFAbsoluteTimeGetCurrent() 31 | return endTime - startTime 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /QuadTree/ViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewModel.swift 3 | // QuadTree 4 | // 5 | // Created by Andrew Zheng (github.com/aheze) on 12/27/23. 6 | // Copyright © 2023 Andrew Zheng. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | class ViewModel: ObservableObject { 12 | // MARK: - Configuration 13 | 14 | @Published var viewportSize = CGSize(width: 500, height: 500) 15 | let xDomain = Double(-10) ... Double(10) 16 | let yDomain = Double(-10) ... Double(10) 17 | var domainWidth: Double { xDomain.upperBound - xDomain.lowerBound } 18 | var domainHeight: Double { yDomain.upperBound - yDomain.lowerBound } 19 | 20 | // function to render 21 | func function(point: Point) -> Double { 22 | let x = point.x 23 | let y = point.y 24 | 25 | // return y * pow(x - y, 2) - (4 * x) - 8 26 | // return pow(x, 2) + pow(y, 2) - 5 27 | return tan(pow(x, 2) + pow(y, 2)) - 1 28 | } 29 | 30 | // MARK: - Rendering 31 | 32 | @Published var displayedCells = [DisplayedCell]() 33 | @Published var graphCurves = [GraphCurve]() 34 | 35 | init() { 36 | let timer = TimeElapsed() 37 | 38 | let curves = Global.plotIsoline( 39 | function: function, 40 | xMin: xDomain.lowerBound, 41 | xMax: xDomain.upperBound, 42 | yMin: yDomain.lowerBound, 43 | yMax: yDomain.upperBound 44 | ) 45 | 46 | print("curves: \(curves.count), \(timer)") 47 | 48 | let graphCurves = curves.map { points in 49 | GraphCurve(points: points) 50 | } 51 | 52 | self.graphCurves = graphCurves 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Implicit Curves 2 | 3 | Swift implementation of Jared Hughes's isosurfaces library. 4 | 5 | Graph implicit curves! 6 | 7 | y * pow(x - y, 2) - (4 * x) - 8 | pow(x, 2) + pow(y, 2) - 5 | tan(pow(x, 2) + pow(y, 2)) - 1 8 | --- | --- | --- 9 | ![a line and a two curves](https://github.com/aheze/QuadTree/assets/49819455/42af00e1-53d6-48bc-b634-759ffef39a83) | ![circle](https://github.com/aheze/QuadTree/assets/49819455/a19983dc-d246-40c5-bf36-4edef82421cc) | ![many nested circles with rendering artifacts near the edges due to rounding](https://github.com/aheze/QuadTree/assets/49819455/1ded10b0-00b5-4759-98d1-c05e4061e1a6) 10 | 11 | 12 | 13 | Original repo: https://github.com/jared-hughes/isosurfaces 14 | 15 | Original license: 16 | 17 | ``` 18 | MIT License 19 | 20 | Copyright (c) 2021 Jared Hughes 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a copy 23 | of this software and associated documentation files (the "Software"), to deal 24 | in the Software without restriction, including without limitation the rights 25 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 26 | copies of the Software, and to permit persons to whom the Software is 27 | furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in all 30 | copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 35 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 37 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 38 | SOFTWARE. 39 | ``` 40 | --------------------------------------------------------------------------------