A set of APIs to manipulate graphics paths on Android

Overview

Pathway

pathway

Pathway is an Android library that provides new functionalities around the graphics Path API.

Pathway is compatible with API 21+.

Maven

repositories {
    // ...
    mavenCentral()
}

dependencies {
    implementation 'dev.romainguy:pathway:0.1.0'
}

Roadmap

  • Automatically convert conic segments to quadratics

Iterating over a Path

With Pathway you can easily iterate over a Path object to inspect its segments (curves or commands):

val path = Path().apply {
    // Build path content
}

for (segment in path) {
    val type = path.type // The type of segment (move, cubic, quadratic, line, close, etc.)
    val points = path.points // The points describing the segment geometry
}

This type of iteration is easy to use but may create an allocation per segment iterated over. If you must avoid allocations, Pathway provides a lower-level API to do so:

val path = Path().apply {
    // Build path content
}

val iterator = path.iterator
val points = FloatArray(8)

while (iterator.hasNext()) {
    val type = iterator.next(points) // The type of segment
    // Read the segment geometry from the points array depending on the type
}

Path segments

Each segment in a Path can be of one of the following types:

Move

Move command. The path segment contains 1 point indicating the move destination. The weight is set 0.0f and not meaningful.

Line

Line curve. The path segment contains 2 points indicating the two extremities of the line. The weight is set 0.0f and not meaningful.

Quadratic

Quadratic curve. The path segment contains 3 points in the following order:

  • Start point
  • Control point
  • End point The weight is set 0.0f and not meaningful.

Conic

Conic curve. The path segment contains 3 points in the following order:

  • Start point
  • Control point
  • End point The curve is weighted by the PathSegment.weight property.

Cubic

Cubic curve. The path segment contains 4 points in the following order:

  • Start point
  • First control point
  • Second control point
  • End point The weight is set 0.0f and not meaningful.

Close

Close command. Close the current contour by joining the last point added to the path with the first point of the current contour. The segment does not contain any point. The weight is set 0.0f and not meaningful.

Done

Done command. This optional command indicates that no further segment will be found in the path. It typically indicates the end of an iteration over a path and can be ignored.

You might also like...
Example Android library project that works with jitpack.io

android-example Example Android library project that works with jitpack.io. See this Tutorial on how to publish an Android Library with JitPack. For m

eCommerce app developed with Android Jetpack and Kotlin

garden-shed eCommerce app developed with Android Jetpack and Kotlin This is my first mobile application. Garden Shed is a simple application for buyin

This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity.
This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity.

Behind the Scenes - DevByte Viewer App This is the toy app for Lesson 9 of the Android App Development in Kotlin course on Udacity. DevByte DevByte Vi

LoadApp This is my submission for the "Building an Advanced Android App"

LoadApp This is my submission for the "Building an Advanced Android App" project of the Udacity Android Kotlin Developer nanodegree. (C) Jaldhar H. Vy

A Project suggested by the Android Basics Course

Dogglers - Starter Code Starter code for the second independent project for Android Basics in Kotlin. Introduction This is the starter code for the Do

An example Android Application to test out Kotlin development in Adndroid

AndroidDiceGenerator This is an example Android Application to test out Kotlin development in Adndroid. On pressing a button, the application generate

 Android MediaProjection Best Demo
Android MediaProjection Best Demo

Android MediaProjection Best Demo

An Android project template with MVVM, Hilt, Navigation and Compose
An Android project template with MVVM, Hilt, Navigation and Compose

compose-android-template An Android project template with MVVM, Hilt, Navigation and Compose πŸ”΄ Status UNDER ACTIVE DEVELOPMENT πŸ“„ Terminologies Termi

 Booking - Android Architecture Sample
Booking - Android Architecture Sample

Booking - Android Architecture Sample A simple app that loads information from REST API to show one approach to using some of the best practices in An

Comments
  • native crash getting a segment iterator

    native crash getting a segment iterator

    I have a simple path created with a single cubic: path.reset() path.moveTo(pathPoints[0], pathPoints[1]) path.cubicTo(points[index * 2], points[index * 2 + 1], points[index * 2], points[index * 2 + 1], points[index * 2], points[index * 2 + 1])

    I try to log the result with pathway like so: for (segment: PathSegment in path.asAndroidPath()) { println("*** segment = $segment") } The app crashes in on hasNext() during iteration. I tried it with a close() command, and with one more cubic, but it always crashed in native code with this log: 2022-07-08 16:07:33.732 22397-22397/com.example.pathplayground A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x2 in tid 22397 (.pathplayground)

    opened by chethaase 6
  • Can we have PathIterator.size?

    Can we have PathIterator.size?

    In using the iterator API, I'm finding myself wanting to know how many commands there are in a path, so I can pre-allocate structures based on that info. Not sure if that API belongs on PathIterator or some other queryable object, but seems like an API that might be useful in general.

    opened by chethaase 2
  • Cache PathSegment.Type values to avoid allocation

    Cache PathSegment.Type values to avoid allocation

    Kotlin's Enum.values() function delegates directly to Java's Enum.values() which clones an internal array on every access. Cache the array so that this allocation only occurs once rather than on each call to peek or next.

    opened by JakeWharton 0
Releases(v0.10.0)
  • v0.10.0(Dec 15, 2022)

    • Added Path.toSvg() to convert a Path instance to an SVG document. The optional document parameter can be set to false to export the SVG path data only.
    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Dec 2, 2022)

    • Added Path.divide to extract multiple contours (List<Path>) from a single Path
    • Added Bitmap.toPath and Bitmap.toPaths to extract vector contours from images
    Source code(tar.gz)
    Source code(zip)
  • v0.8.0(Sep 8, 2022)

  • v0.7.0(Sep 7, 2022)

    • next(points: FloatArray, offset: Int = 0) now uses SetFlotArrayRegion for faster copies with no internal allocations
    • Fixed unit tests on older API releases
    • Upgraded NDK (r25) and CMake (3.22)
    • Upgraded build and target SDK to 33
    Source code(tar.gz)
    Source code(zip)
  • v0.6.0(Aug 2, 2022)

    • Added PathIterator.rawSize to return the original number of verbs inside the path to iterate, ignoring conic conversions which can increase the real number of verbs
    • Added PathIterator.size to return the number of verbs inside the path to iterate, taking into account possible conversions from conics to quadratics
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Aug 2, 2022)

  • v0.4.0(Jul 22, 2022)

  • v0.3.0(Mar 1, 2022)

  • v0.2.0(Nov 18, 2021)

    • Pathway now automatically converts conic curves into a series of quadratic curves. This allows you to create a new Path object from an iteration on all versions of Android (no version provides the ability to add conics at this time). The tolerance of the conversion can be set when creating the iterator.
    • You can now create an iterator that preserves conic curves as conics instead of converting them to quadratics.
    Source code(tar.gz)
    Source code(zip)
Owner
Romain Guy
Engineering director at Google on Android
Romain Guy
NotesApp is a project which demonstrates the power of Kotlin's Ktor in developing powerful REST APIs with all basic as well as advanced features.

NotesApp NotesApp is a project which demonstrates the power of Kotlin's Ktor in developing powerful REST APIs with all basic as well as advanced featu

Rooparsh Kalia 1 Oct 18, 2021
An example to show how a proper plugin for Lambda Client is set up

Lambda Plugin SDK This project in an example to show how a proper plugin for Lambda Client is set up. The advantage of plugins for a utility mod is th

KMatias 0 Oct 25, 2021
A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.

Android Architecture Blueprints v2 Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android a

Android 42k Jan 3, 2023
Android Viper template with Kotlin, Dagger 2, Retrofit & RxJava

Android VIPER Architecture Example This repository contains a detailed sample client-server app that implements VIPER(View-Interactor-Presenter-Entity

OmiSoft 33 Nov 4, 2022
Learn How to use Google Map API for Android from Basic to Advance with complete examples.

Complete-Google-Map-API-Tutorial Learn How to use Google Map API for Android from Basic to Advance. Satellite View 3D Building Map and StreetView Lear

Next 117 Dec 8, 2022
πŸ“š Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.

Android Components Architecture in a Modular Word Android Components Architecture in a Modular Word is a sample project that presents modern, 2020 app

Madalin Valceleanu 2.3k Dec 30, 2022
Saga of Star wars - An Android sample repo showcasing Clean Arch with MVVM and Epoxy models

Star Wars Universe This is a showcase android application written in Kotlin and follows Clean Code architecture to showcase Characters from the StarWa

Adit Lal 5 Dec 13, 2022
This is an example implementation of android accessibility services with 5 Sample Actions

Android Accessibility Services Example This is an example implementation of android accessibility services with 5 Sample Actions such as: Simulate Pow

Muhammad Fahriansyah 7 Jul 1, 2022
πŸ“ŒThis repo contains the kotlin implementation of TensorflowLite Example Android AppsπŸš€

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Sunit Roy 29 Jan 1, 2023
Android Modern Architecture Sample

AndroidModernArchitectureSample TODO: write readme Download (playstore release - under review) https://play.google.com/store/apps/details?id=io.github

Ji Sungbin 22 Sep 10, 2022