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

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

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.

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.

Owner
Romain Guy
Engineering director at Google on Android
Romain Guy
Similar Resources

🌞 A physically based monte carlo path tracer written in C++

🌞 A physically based monte carlo path tracer written in C++

Physically Based Path Tracer The below 3D model for the Head of Michelangelo's David bust was taken from this link. Other .obj files taken from The St

Jul 16, 2022

A Hydra-enabled GPU path tracer that supports MaterialX.

A Hydra-enabled GPU path tracer that supports MaterialX.

A Hydra-enabled GPU path tracer that supports MaterialX.

Jul 27, 2022

Brute force volumetric path tracer written in C++

Brute force volumetric path tracer written in C++

volpt Brute force volumetric path tracer written in C++. WIP. Features Homogeneous medium Hero wavelength sampling for chromatic absorption/scattering

Aug 3, 2022

A realtime Vulkan voxel path tracer.

A realtime Vulkan voxel path tracer.

brickmap-vulkan A realtime Vulkan voxel path tracer. This is a work in progress! This system is a Vulkan/SPIRV implementation of the BrickMap by stijn

Jul 29, 2022

ReferencePT - Supplemental code accompanying Ray Tracing Gems II, Chapter 14: The Reference Path Tracer

ReferencePT - Supplemental code accompanying Ray Tracing Gems II, Chapter 14: The Reference Path Tracer

The Reference Path Tracer Code sample This is a supplemental code accompanying Ray Tracing Gems II, Chapter 14: The Reference Path Tracer. Code is bas

Jul 28, 2022

A modern cross-platform low-level graphics library and rendering framework

A modern cross-platform low-level graphics library and rendering framework

Diligent Engine A Modern Cross-Platform Low-Level 3D Graphics Library Diligent Engine is a lightweight cross-platform graphics API abstraction library

Aug 12, 2022

A library for high-performance, modern 2D graphics with SDL written in C.

SDL_gpu, a library for making hardware-accelerated 2D graphics easy. by Jonathan Dearborn SDL_gpu is licensed under the terms of the MIT License. See

Aug 17, 2022

3D engine from scratch (without OpenGL or any other 3D graphics library)

3D engine from scratch (without OpenGL or any other 3D graphics library)

Simple 3d engine based on SFML library. I tried to make this engine powerful and easy to understand.

Aug 7, 2022
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)

  • 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.

  • 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.

Related tags
Legion Low Level Rendering Interface provides a graphics API agnostic rendering interface with minimal CPU overhead and low level access to verbose GPU operations.
Legion Low Level Rendering Interface provides a graphics API agnostic rendering interface with minimal CPU overhead and low level access to verbose GPU operations.

Legion-LLRI Legion-LLRI, or “Legion Low Level Rendering Interface” is a rendering API that aims to provide a graphics API agnostic approach to graphic

Aug 13, 2022
Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal

Low Level Graphics Library (LLGL) Documentation NOTE: This repository receives bug fixes only, but no major updates. Pull requests may still be accept

Aug 13, 2022
A terminal-based graphics library for both 2D and 3D graphics.
A terminal-based graphics library for both 2D and 3D graphics.

TermGL A terminal-based graphics library for both 2D and 3D graphics. Written in C, created for terminals supporting ANSI escape codes. Table of Conte

Aug 10, 2022
kaun is a replacement for löve's built-in love.graphics module intended for 3D graphics

kaun kaun is a replacement for löve's built-in love.graphics module intended for 3D graphics. It is a Lua module you can require from a shared library

Apr 5, 2021
This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.
This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.

DirectX-Graphics-Samples This repo contains the DirectX 12 Graphics samples that demonstrate how to build graphics intensive applications for Windows

Aug 10, 2022
Android studio native project template using cross platform raylib graphics library.

rayturbo Android studio native project template using cross platform raylib graphics library. https://www.raylib.com/ This project use Android Studio

Mar 5, 2022
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
Cross-platform, graphics API agnostic,

bgfx - Cross-platform rendering library GitHub Discussions Discord Chat What is it? Cross-platform, graphics API agnostic, "Bring Your Own Engine/Fram

Aug 14, 2022
SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.

SPIRV-Reflect SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications. SPIRV-Ref

Aug 7, 2022
Dear PyGui 3D Engine (early development) and Graphics API demos.
Dear PyGui 3D Engine (early development) and Graphics API demos.

Marvel This repo is the working location of the eventual Dear PyGui 3D Engine. It also contains several single file examples of creating a triangle wi

Aug 5, 2022
A path tracer based on hardware ray tracing

GoldenSun GoldenSun is a GPU path tracer. It uses hardware ray tracing APIs to do the tracing. As an experimental project, there is no release plan, n

Feb 27, 2022