Find the union of a set of axis-aligned rectangles

Overview

RectangleContour

My main product is a library named RectangleContour which contains one Swift module also named RectangleContour. The library implements an algorithm for finding the union of a set of axis-aligned rectangles.

Using the library, you can create shapes like these:

demo images

Adding RectangleContour as a Dependency

To use the RectangleContour library as a dependency in a SwiftPM project, add the following to your Package dependencies in your Package.swift manifest:

.package(url: "https://github.com/mayoff/RectangleContour", from: "0.0.2"),

and include "RectangleContour" as a dependency of your Target:

.target(name: "YourExistingTarget", dependencies: [
    .product(name: "RectangleContour", package: "RectangleContour"),
]),

Demo Apps

To run the demo apps, clone the RectangleContour repo and open its RectangleContour.xcworkspace in Xcode. Select the MacDemoApp scheme and the “My Mac” destination, or select the PhoneDemoApp scheme and an iPhone simulator (or real iPhone) destination. Then click Product > Run.

Using the RectangleContour API

For examples of how to use the module, look for the calls to contour and cgPath in RectDemoView.swift, TextDemoView.swift (macOS), and TextDemoView.swift (iOS).

To use the module, you must first prepare a Collection of CGRects. Typically you'll create an array, but you can use any Collection type.

let rects: [CGRect] = [
    CGRect(x: 100, y: 200, width: 300, height: 400),
    CGRect(x: 200, y: 300, width: 500, height: 600),
]

Next, ask the collection for its contour:

let contour: IsoOrientedContour = rects.contour()

Then you'll probably want to convert the contour to a CGPath. The IsoOrientedContour type provides two convenience methods for converting a contour to a CGPath. One creates sharp corners:

let sharpPath: CGPath = contour.cgPath()

The other creates rounded corners:

let roundedPath: CGPath = contour.cgPath(cornerRadius: 10)

If you need a SwiftUI.Path or an UIBezierPath, you can wrap the CGPath:

let swiftuiPath = Path(roundedPath)
let uiPath = UIBezierPath(cgPath: roundedPath)

Implementation Notes

This package implements the algorithm described in the 1979 paper “Finding the Contour of a Union of Iso-Oriented Rectangles” by Witold Lipski Jr. and Franco P. Preparata.

You might also like...
Highlighter will magically find UI objects such as UILabel, UITextView, UITexTfield, UIButton
Highlighter will magically find UI objects such as UILabel, UITextView, UITexTfield, UIButton

Highlighter Updates See CHANGELOG for details Intoduction 🖍 Highlight whatever you want! Highlighter will magically find UI objects such as UILabel,

This is a Review posting app that let user find interesting places near them
This is a Review posting app that let user find interesting places near them

ColorMatchTabs Inspired by this project on Dribbble Also, read how it was done in our blog Installation CocoaPods pod 'ColorMatchTabs' Carthage github

Are you bored? This app helps find you something to do via Bored api
Are you bored? This app helps find you something to do via Bored api

Bored Swift Are you bored? This app helps find you something to do via Bored api Features Beautiful widgets 📅 Simple and easy ✅ Open source 📱 Previe

The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.
The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.

Color Game The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun. Getting Started Insta

SwiftUI Animation Library. Useful SwiftUI animations including Loading/progress, Looping, On-off, Enter, Exit, Fade, Spin and Background animations that you can directly implement in your next iOS application or project. The library also contains huge examples of spring animations such as Inertial Bounce, Shake, Twirl, Jelly, Jiggle, Rubber Band, Kitchen Sink and Wobble effects. Browse, find and download the animation that fits your needs.
Validate iOS, Android, and Mac localizations. Find errors in .strings, .stringsdict, and strings.xml files.

Locheck An Xcode and Android localization file validator. Make sure your .strings, .stringsdict, and strings.xml files do not have any errors! What do

The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.
The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun.

Color Game The purpose of the color game is to find the right color without getting distracted. It is as difficult as it is fun. Getting Started Insta

A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.
A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

TimeZonePicker A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your

iOS and  Watch app to find city bicycles to rent in your city
iOS and  Watch app to find city bicycles to rent in your city

Bike-Compass Bike Compass is a full-featured city bicycle finder app for iOS. Using a bike is enjoyable, that is why our app is fast, beautiful, and d

Contains the swift rewrite of Find My Bus NJ iOS App
Contains the swift rewrite of Find My Bus NJ iOS App

FIND MY BUS NJ 2 An app for tracking NJ Transit bus times. Dependancies Alamofire SwiftyJSON PKHUD Fabric Getting started Install fastlane and imagema

Find memory leaks in your iOS app at develop time.

中文介绍 | FAQ中文 MLeaksFinder MLeaksFinder helps you find memory leaks in your iOS apps at develop time. It can automatically find leaks in UIView and UIV

Find memory issues & leaks in your iOS app without instruments
Find memory issues & leaks in your iOS app without instruments

HeapInspector Find memory issues & leaks in your iOS app HeapInspector is a debug tool that monitors the memory heap with backtrace recording in your

Find common xib and storyboard-related problems without running your app or writing unit tests.
Find common xib and storyboard-related problems without running your app or writing unit tests.

IBAnalyzer Find common xib and storyboard-related problems without running your app or writing unit tests. Usage Pass a path to your project to ibanal

Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.
Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

iOS mobile app to find and display the nearest boba shop

iOSBoba - Boba App Description Basic mobile app where you can plug in a location (or let the app find your current location), and the app will tap int

ColorAssetsFinder can help you find particular color assets easily by hex color code.
ColorAssetsFinder can help you find particular color assets easily by hex color code.

ColorAssetsFinder ColorAssetsFinder can help you find particular color assets easily by hex color code. Features Find particular color assets in Asset

it's simple kids game to find different colour.
it's simple kids game to find different colour.

SWift_FindColourGame it's simple swift find different colour game. This is a sample project students or kids can use to learn how to find difference c

it's simple swift find different colour game.
it's simple swift find different colour game.

SWift_FindColourGame it's simple swift find different colour game. This is a sample project students or kids can use to learn how to find difference c

Comments
  • Explanation

    Explanation

    this is a question

    I am trying to port this algorithm to Flutter - Dart. I don't swift, so I would like to have some better documentation on what the code itself does, if possible.

    I was able to convert the whole code to Dart, except for the following line:

    //! I haven't found any `lazy` variables in GCRect. Also, `self` is not a list. Am I missing something?
    let nonEmpties = self.lazy.filter { !$0.isEmpty }
    

    https://github.com/mayoff/RectangleContour/blob/main/Sources/RectangleContour/Collection.contour.swift#L129

    opened by bdlukaa 6
Owner
Rob Mayoff
Rob Mayoff
TapLetterGuess - Find the answer by combining words

TapLetterGuess Find the answer by combining words.

Ahmet Onur Sahin 3 Apr 18, 2022
Xcode Plugin helps you find missing methods in your class header, protocols, and super class, also makes fast inserting.

FastStub-Xcode Life is short, why waste it on meaningless typing? What is it? A code generating feature borrowed from Android Studio. FastStub automat

mrpeak 509 Jun 29, 2022
Puma - A set of build utilities to automate mobile application development and deployment

Puma → https://github.com/onmyway133/Swiftlane Puma is a set of build utilities

Puma Swift 5 Oct 8, 2022
SafeDecoder - a swift package that set defaults when Codable fails to decode a field

SafeDecoder is a swift package that set defaults when Codable fails to decode a field. SafeDecoder supports configurable default values, See SafeDecoder.Configuration.

GodL 4 Mar 21, 2022
Set `Open using Rosetta` option on Xcode easily

xcode-arch A utility to switch running architecture of Xcode on M1 mac. Motivation Currently, there is no way to toggle Open using Rosetta option othe

Takuhiro Muta 7 Aug 8, 2022
A novel way to set attributes to the Font in SwiftUI.

A novel way to set attributes to the Font in SwiftUI.

Riiid 6 Oct 13, 2022
A set of libraries to help users find and replace native system emojis with EmojiOne in their app or website.

This repository is now maintained as JoyPixels/emoji-toolkit. You'll find the latest version of our resources at emoji-toolkit. Please see the UPGRADE

JoyPixels Inc. 4.5k Dec 24, 2022
A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.

Installation Drag the included Colours.h and Colours.m files into your project. They are located in the top-level directory. You can see a demo of how

Ben Gordon 3.1k Dec 28, 2022
ColorKit makes it easy to find the dominant colors of an image

ColorKit is your companion to work with colors on iOS. Features Installation Sample Project Contributing License Features Dominant Colors Col

Boris Emorine 569 Dec 29, 2022