|
| 1 | +// Copyright 2024 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <jni.h> |
| 16 | + |
| 17 | +#include <utility> |
| 18 | + |
| 19 | +#include "ink/geometry/angle.h" |
| 20 | +#include "ink/geometry/envelope.h" |
| 21 | +#include "ink/geometry/internal/jni/rect_jni_helper.h" |
| 22 | +#include "ink/geometry/internal/jni/vec_jni_helper.h" |
| 23 | +#include "ink/geometry/quad.h" |
| 24 | +#include "ink/geometry/vec.h" |
| 25 | +#include "ink/jni/internal/jni_defines.h" |
| 26 | + |
| 27 | +namespace { |
| 28 | + |
| 29 | +using ::ink::Angle; |
| 30 | +using ::ink::Envelope; |
| 31 | +using ::ink::Quad; |
| 32 | +using ::ink::Vec; |
| 33 | + |
| 34 | +} // namespace |
| 35 | + |
| 36 | +extern "C" { |
| 37 | + |
| 38 | +JNI_METHOD(geometry, ParallelogramNative, jobject, nativeCreateBoundingBox) |
| 39 | +(JNIEnv* env, jclass clazz, jfloat center_x, jfloat center_y, jfloat width, |
| 40 | + jfloat height, jfloat rotation, jfloat shear_factor, |
| 41 | + jclass immutable_box_class, jclass immutable_vec_class) { |
| 42 | + Quad quad = Quad::FromCenterDimensionsRotationAndShear( |
| 43 | + {center_x, center_y}, width, height, Angle::Radians(rotation), |
| 44 | + shear_factor); |
| 45 | + |
| 46 | + return ink::CreateJImmutableBoxFromRect(env, Envelope(quad).AsRect().value(), |
| 47 | + immutable_box_class, |
| 48 | + immutable_vec_class); |
| 49 | +} |
| 50 | + |
| 51 | +JNI_METHOD(geometry, ParallelogramNative, void, nativePopulateBoundingBox) |
| 52 | +(JNIEnv* env, jclass clazz, jfloat center_x, jfloat center_y, jfloat width, |
| 53 | + jfloat height, jfloat rotation, jfloat shear_factor, jobject mutable_box) { |
| 54 | + Quad quad = Quad::FromCenterDimensionsRotationAndShear( |
| 55 | + {center_x, center_y}, width, height, Angle::Radians(rotation), |
| 56 | + shear_factor); |
| 57 | + |
| 58 | + ink::FillJMutableBoxFromRect(env, mutable_box, |
| 59 | + Envelope(quad).AsRect().value()); |
| 60 | +} |
| 61 | + |
| 62 | +JNI_METHOD(geometry, ParallelogramNative, jobjectArray, nativeCreateSemiAxes) |
| 63 | +(JNIEnv* env, jclass clazz, jfloat center_x, jfloat center_y, jfloat width, |
| 64 | + jfloat height, jfloat rotation, jfloat shear_factor, |
| 65 | + jclass immutable_vec_class) { |
| 66 | + Quad quad = Quad::FromCenterDimensionsRotationAndShear( |
| 67 | + {center_x, center_y}, width, height, Angle::Radians(rotation), |
| 68 | + shear_factor); |
| 69 | + std::pair<Vec, Vec> axes = quad.SemiAxes(); |
| 70 | + jobjectArray vector_array = |
| 71 | + env->NewObjectArray(2, immutable_vec_class, nullptr); |
| 72 | + env->SetObjectArrayElement( |
| 73 | + vector_array, 0, |
| 74 | + ink::CreateJImmutableVecFromVec(env, axes.first, immutable_vec_class)); |
| 75 | + env->SetObjectArrayElement( |
| 76 | + vector_array, 1, |
| 77 | + ink::CreateJImmutableVecFromVec(env, axes.second, immutable_vec_class)); |
| 78 | + return vector_array; |
| 79 | +} |
| 80 | + |
| 81 | +JNI_METHOD(geometry, ParallelogramNative, void, nativePopulateSemiAxes) |
| 82 | +(JNIEnv* env, jclass clazz, jfloat center_x, jfloat center_y, jfloat width, |
| 83 | + jfloat height, jfloat rotation, jfloat shear_factor, jobject out_axis1, |
| 84 | + jobject out_axis2) { |
| 85 | + Quad quad = Quad::FromCenterDimensionsRotationAndShear( |
| 86 | + {center_x, center_y}, width, height, Angle::Radians(rotation), |
| 87 | + shear_factor); |
| 88 | + std::pair<Vec, Vec> axes = quad.SemiAxes(); |
| 89 | + ink::FillJMutableVecFromVec(env, out_axis1, axes.first); |
| 90 | + ink::FillJMutableVecFromVec(env, out_axis2, axes.second); |
| 91 | +} |
| 92 | + |
| 93 | +} // extern "C" |
0 commit comments