diff --git a/README.md b/README.md index b824c8b..5ace065 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ repositories { } dependencies { - implementation 'dev.romainguy:pathway:0.7.0' + implementation 'dev.romainguy:pathway:0.8.0' } ``` diff --git a/gradle.properties b/gradle.properties index bc7ce06..fd53fc0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP=dev.romainguy -VERSION_NAME=0.7.0 +VERSION_NAME=0.8.0 SONATYPE_HOST=S01 RELEASE_SIGNING_ENABLED=true diff --git a/pathway/src/main/cpp/pathway.cpp b/pathway/src/main/cpp/pathway.cpp index 65add0f..39d68f9 100644 --- a/pathway/src/main/cpp/pathway.cpp +++ b/pathway/src/main/cpp/pathway.cpp @@ -22,7 +22,7 @@ #include -#define JNI_CLASS_NAME "dev/romainguy/graphics/path/PathIterator" +#define JNI_CLASS_NAME "dev/romainguy/graphics/path/Paths" #if !defined(NDEBUG) #include @@ -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_); } -static jboolean pathIteratorHasNext(JNIEnv*, jobject, jlong pathIterator_) { +static jboolean pathIteratorHasNext(JNIEnv*, jclass, jlong pathIterator_) { return reinterpret_cast(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_); Point pointsData[4]; Verb verb = pathIterator->next(pointsData); @@ -118,15 +118,15 @@ static jint pathIteratorNext( return static_cast(verb); } -static jint pathIteratorPeek(JNIEnv*, jobject, jlong pathIterator_) { +static jint pathIteratorPeek(JNIEnv*, jclass, jlong pathIterator_) { return static_cast(reinterpret_cast(pathIterator_)->peek()); } -static jint pathIteratorRawSize(JNIEnv*, jobject, jlong pathIterator_) { +static jint pathIteratorRawSize(JNIEnv*, jclass, jlong pathIterator_) { return static_cast(reinterpret_cast(pathIterator_)->rawCount()); } -static jint pathIteratorSize(JNIEnv*, jobject, jlong pathIterator_) { +static jint pathIteratorSize(JNIEnv*, jclass, jlong pathIterator_) { return static_cast(reinterpret_cast(pathIterator_)->count()); } diff --git a/pathway/src/main/java/dev/romainguy/graphics/path/Paths.kt b/pathway/src/main/java/dev/romainguy/graphics/path/Paths.kt index fbb6a37..b0a3bea 100644 --- a/pathway/src/main/java/dev/romainguy/graphics/path/Paths.kt +++ b/pathway/src/main/java/dev/romainguy/graphics/path/Paths.kt @@ -14,6 +14,8 @@ * limitations under the License. */ +@file:JvmName("Paths") + package dev.romainguy.graphics.path import android.graphics.Path @@ -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]. @@ -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 @@ -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 } /** @@ -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