All Projects → romainguy → pathway

romainguy / pathway

Licence: Apache-2.0 license
A set of APIs to manipulate graphics paths on Android.

Programming Languages

kotlin
9241 projects
C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to pathway

Typescript Transform Paths
Transforms absolute imports to relative
Stars: ✭ 166 (+2.47%)
Mutual labels:  path
Set Value
Set nested values on an object using dot-notation, like 'a.b.c'.
Stars: ✭ 203 (+25.31%)
Mutual labels:  path
datoteka
A filesystem toolset and storage implementation for Clojure.
Stars: ✭ 59 (-63.58%)
Mutual labels:  path
Diffre
Neon Progress indicator useful for event progress like views. Proof of concept.
Stars: ✭ 176 (+8.64%)
Mutual labels:  path
Richpath
💪 Rich Android Path. 🤡 Draw as you want. 🎉 Animate much as you can.
Stars: ✭ 2,259 (+1294.44%)
Mutual labels:  path
Pkg Ok
👌 Checks paths and scripts defined in package.json before you publish
Stars: ✭ 219 (+35.19%)
Mutual labels:  path
Wechart
Create all the [ch]arts by cax or three.js - Cax 和 three.js 创造一切图[表]
Stars: ✭ 152 (-6.17%)
Mutual labels:  path
MARCspec
📄 MARCspec - A common MARC record path language
Stars: ✭ 21 (-87.04%)
Mutual labels:  path
Exilence
DEPRECATED Tool for Path of Exile that calculates net worth and tracks gear, maps and other statistics for you and your group
Stars: ✭ 200 (+23.46%)
Mutual labels:  path
path-data
A gRPC API that exposes various information about the PATH transit system.
Stars: ✭ 29 (-82.1%)
Mutual labels:  path
Zson
专为测试人员打造的JSON解析器
Stars: ✭ 181 (+11.73%)
Mutual labels:  path
Virgilio
Virgilio is developed and maintained by these awesome people. You can email us virgilio.datascience (at) gmail.com or join the Discord chat.
Stars: ✭ 13,200 (+8048.15%)
Mutual labels:  path
Swiftuirouter
Routing in SwiftUI
Stars: ✭ 242 (+49.38%)
Mutual labels:  path
Bandersnatch
💻 Interactive Black Mirror: Bandersnatch Paths Website 🎥
Stars: ✭ 169 (+4.32%)
Mutual labels:  path
jurl
Fast and simple URL parsing for Java, with UTF-8 and path resolving support
Stars: ✭ 84 (-48.15%)
Mutual labels:  path
Mav active 3d planning
Modular framework for online informative path planning.
Stars: ✭ 164 (+1.23%)
Mutual labels:  path
Picasso
Picasso is a high quality 2D vector graphic rendering library. It support path , matrix , gradient , pattern , image and truetype font.
Stars: ✭ 205 (+26.54%)
Mutual labels:  path
path-dsl-rs
A Rust utility DSL and macro to help construct and modify Paths.
Stars: ✭ 19 (-88.27%)
Mutual labels:  path
PathOfBuildingAPI
API for Path of Building's build sharing format for builds in Path of Exile.
Stars: ✭ 25 (-84.57%)
Mutual labels:  path
Lambda
Physically based renderer written in C++
Stars: ✭ 26 (-83.95%)
Mutual labels:  path

Pathway

pathway Android build status

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.11.0'
}

Features

Paths from images

Bitmap.toPath() and Bitmap.toPaths() can be used to extract vector contours from images, as Path object. toPath() extracts all the contours in a single Path while toPaths() returns a list of contours as separate Path instances. Calling toPaths() is equivalent to calling toPath().divide() (see Path division) but more efficient.

When extracting a path from an image, two parameters can be set:

  • alphaTreshold: defines the maximum alpha channel value a pixel might have before being considered opaque. Transitions from opaque to transparent are used to define the contours in the image. The default value is 0.0f (meaning any pixel with an alpha > 0.0 is considered to be inside the contour).
  • minAngle: defines the minimum angle in degrees between two segments in the contour before they are collapsed to simplify the final geometry. The default value is 15 degrees. Setting this value to 0 will yield an exact vector representation of the contours but will generate complex and expensive paths.

Path division

Path division can be used to generate a list of paths from a source path. Each contour, defined by a "move" operation, in the source path is extracted as a separate Path. In the following example the paths variable contains a list of 2 Path instance, each containing one of the rectangles originally added to the source path:

val path = Path().apply {
    addRect(0.0f, 0.0f, 24.0f, 24.0f)
    addRect(32.0f, 32.0f, 64.0f, 64.0f)
}
val paths = path.divide()

Convert to SVG

To convert a Path to an SVG document, call Path.toSvg(). If you only want the path data instead of a full SVG document, use Path.toSvg(document = false) instead. Exporting a full document will properly honor the path's fill type.

Iterating over a Path

Note As of Android 14 (tentatively API 34), iterating over a Path can be achieved using the new platform API getPathIterator(). Pathway is however compatible with Android 14, including Developer Preview builds.

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 = segment.type // The type of segment (move, cubic, quadratic, line, close, etc.)
    val points = segment.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.

Conic curves are automatically converted to quadratic curves by default, see Handling conic segments below for more information.

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.

Handling conic segments

In some API levels, paths may contain conic curves (weighted quadratics) but the Path API does not offer a way to add conics to a Path object. To work around this, Pathway automatically converts conics into several quadratics by default.

The conic to quadratic conversion is an approximation controlled by a tolerance threshold, set by default to 0.25f (sub-pixel). If you want to preserve conics or control the tolerance, you can use the following APIs:

// Preserve conics
val iterator = path.iterator(PathIterator.ConicEvaluation.AsConic)

// Control the tolerance of the conic to quadratic conversion
val iterator = path.iterator(PathIterator.ConicEvaluation.AsQuadratics, 2.0f)

License

Please see LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].