Skip to content

Commit

Permalink
More Java-friendly declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
romainguy committed Sep 8, 2022
1 parent e345265 commit efb9692
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}
dependencies {
implementation 'dev.romainguy:pathway:0.7.0'
implementation 'dev.romainguy:pathway:0.8.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=dev.romainguy
VERSION_NAME=0.7.0
VERSION_NAME=0.8.0

SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true
Expand Down
14 changes: 7 additions & 7 deletions pathway/src/main/cpp/pathway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <mutex>

#define JNI_CLASS_NAME "dev/romainguy/graphics/path/PathIterator"
#define JNI_CLASS_NAME "dev/romainguy/graphics/path/Paths"

#if !defined(NDEBUG)
#include <android/log.h>
Expand Down Expand Up @@ -96,16 +96,16 @@ static jlong createPathIterator(JNIEnv* env, jobject,
));
}

static void destroyPathIterator(JNIEnv*, jobject, jlong pathIterator_) {
static void destroyPathIterator(JNIEnv*, jclass, jlong pathIterator_) {
delete reinterpret_cast<PathIterator*>(pathIterator_);
}

static jboolean pathIteratorHasNext(JNIEnv*, jobject, jlong pathIterator_) {
static jboolean pathIteratorHasNext(JNIEnv*, jclass, jlong pathIterator_) {
return reinterpret_cast<PathIterator*>(pathIterator_)->hasNext();
}

static jint pathIteratorNext(
JNIEnv* env, jobject, jlong pathIterator_, jfloatArray points_, jint offset_) {
JNIEnv* env, jclass, jlong pathIterator_, jfloatArray points_, jint offset_) {
auto pathIterator = reinterpret_cast<PathIterator*>(pathIterator_);
Point pointsData[4];
Verb verb = pathIterator->next(pointsData);
Expand All @@ -118,15 +118,15 @@ static jint pathIteratorNext(
return static_cast<jint>(verb);
}

static jint pathIteratorPeek(JNIEnv*, jobject, jlong pathIterator_) {
static jint pathIteratorPeek(JNIEnv*, jclass, jlong pathIterator_) {
return static_cast<jint>(reinterpret_cast<PathIterator *>(pathIterator_)->peek());
}

static jint pathIteratorRawSize(JNIEnv*, jobject, jlong pathIterator_) {
static jint pathIteratorRawSize(JNIEnv*, jclass, jlong pathIterator_) {
return static_cast<jint>(reinterpret_cast<PathIterator *>(pathIterator_)->rawCount());
}

static jint pathIteratorSize(JNIEnv*, jobject, jlong pathIterator_) {
static jint pathIteratorSize(JNIEnv*, jclass, jlong pathIterator_) {
return static_cast<jint>(reinterpret_cast<PathIterator *>(pathIterator_)->count());
}

Expand Down
73 changes: 34 additions & 39 deletions pathway/src/main/java/dev/romainguy/graphics/path/Paths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:JvmName("Paths")

package dev.romainguy.graphics.path

import android.graphics.Path
Expand Down Expand Up @@ -128,6 +130,11 @@ val DoneSegment = PathSegment(PathSegment.Type.Done, emptyArray(), 0.0f)
*/
val CloseSegment = PathSegment(PathSegment.Type.Close, emptyArray(), 0.0f)

/**
* Cache of [PathSegment.Type] values to avoid internal allocation on each use.
*/
private val pathSegmentTypes = PathSegment.Type.values()

/**
* Creates a new [PathIterator] for this [path][android.graphics.Path] that evaluates
* conics as quadratics. To preserve conics, use [Path.iterator].
Expand All @@ -140,11 +147,6 @@ operator fun Path.iterator() = PathIterator(this)
fun Path.iterator(conicEvaluation: PathIterator.ConicEvaluation, tolerance: Float = 0.25f) =
PathIterator(this, conicEvaluation, tolerance)

/**
* Cache of [PathSegment.Type] values to avoid internal allocation on each use.
*/
internal val pathSegmentTypes = PathSegment.Type.values()

/**
* A path iterator can be used to iterate over all the [segments][PathSegment] that make up
* a path. Those segments may in turn define multiple contours inside the path. Conic segments
Expand All @@ -161,40 +163,6 @@ class PathIterator(
init {
System.loadLibrary("pathway")
}

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun createInternalPathIterator(
path: Path, conicEvaluation: Int, tolerance: Float
): Long

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun destroyInternalPathIterator(internalPathIterator: Long)

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun internalPathIteratorHasNext(internalPathIterator: Long): Boolean

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun internalPathIteratorNext(
internalPathIterator: Long,
points: FloatArray,
offset: Int
): Int

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun internalPathIteratorPeek(internalPathIterator: Long): Int

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun internalPathIteratorRawSize(internalPathIterator: Long): Int

@JvmStatic
@Suppress("KotlinJniMissingFunction")
external fun internalPathIteratorSize(internalPathIterator: Long): Int
}

/**
Expand Down Expand Up @@ -322,3 +290,30 @@ class PathIterator(
destroyInternalPathIterator(internalPathIterator)
}
}

@Suppress("KotlinJniMissingFunction")
private external fun createInternalPathIterator(
path: Path, conicEvaluation: Int, tolerance: Float
): Long

@Suppress("KotlinJniMissingFunction")
private external fun destroyInternalPathIterator(internalPathIterator: Long)

@Suppress("KotlinJniMissingFunction")
private external fun internalPathIteratorHasNext(internalPathIterator: Long): Boolean

@Suppress("KotlinJniMissingFunction")
private external fun internalPathIteratorNext(
internalPathIterator: Long,
points: FloatArray,
offset: Int
): Int

@Suppress("KotlinJniMissingFunction")
private external fun internalPathIteratorPeek(internalPathIterator: Long): Int

@Suppress("KotlinJniMissingFunction")
private external fun internalPathIteratorRawSize(internalPathIterator: Long): Int

@Suppress("KotlinJniMissingFunction")
private external fun internalPathIteratorSize(internalPathIterator: Long): Int

0 comments on commit efb9692

Please sign in to comment.