Drop MathUtils

This commit is contained in:
FooIbar authored and tarsin committed 2023-06-22 10:01:41 +08:00
1 parent eb726ccbf4
commit a0b48a5cc7
8 files changed
+10 -220

No files matched your search

@@ -20,6 +20,7 @@ import android.util.Log
import android.util.SparseLongArray
import androidx.collection.LongSparseArray
import androidx.collection.keyIterator
import com.google.android.material.math.MathUtils
import com.hippo.ehviewer.AppConfig
import com.hippo.ehviewer.EhDB
import com.hippo.ehviewer.Settings
@@ -33,7 +34,6 @@ import com.hippo.ehviewer.spider.SpiderQueen.OnSpiderListener
import com.hippo.ehviewer.spider.readCompatFromUniFile
import com.hippo.ehviewer.spider.write
import com.hippo.ehviewer.yorozuya.ConcurrentPool
import com.hippo.ehviewer.yorozuya.MathUtils
import com.hippo.ehviewer.yorozuya.SimpleHandler
import com.hippo.ehviewer.yorozuya.collect.LongList
import com.hippo.unifile.UniFile
@@ -29,8 +29,8 @@ import android.graphics.drawable.Drawable;
import androidx.annotation.Keep;
import com.google.android.material.math.MathUtils;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.yorozuya.MathUtils;
public class AddDeleteDrawable extends Drawable {
@@ -27,10 +27,10 @@ import android.view.View
import android.view.ViewConfiguration
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
import com.google.android.material.math.MathUtils.dist
import com.hippo.ehviewer.R
import com.hippo.ehviewer.yorozuya.AnimationUtils
import com.hippo.ehviewer.yorozuya.LayoutUtils.dp2pix
import com.hippo.ehviewer.yorozuya.MathUtils.dist
import com.hippo.ehviewer.yorozuya.SimpleAnimatorListener
import com.hippo.ehviewer.yorozuya.SimpleHandler
import kotlin.math.abs
@@ -20,7 +20,7 @@ import android.graphics.PointF
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.hippo.ehviewer.yorozuya.MathUtils
import com.google.android.material.math.MathUtils
import com.hippo.ehviewer.yorozuya.SimpleHandler
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method
@@ -112,7 +112,7 @@ object LayoutManagerUtils {
if (offset < max && max > 0) {
smoothScrollToPosition(
layoutManager, context, position,
MathUtils.lerp(100, 25, (offset / max).toFloat())
MathUtils.lerp(100F, 25F, (offset / max).toFloat()).toInt()
)
} else {
scrollToPositionWithOffset(layoutManager, position, 0)
@@ -126,7 +126,7 @@ object LayoutManagerUtils {
is LinearLayoutManager -> layoutManager.findFirstVisibleItemPosition()
is StaggeredGridLayoutManager -> {
val positions = layoutManager.findFirstVisibleItemPositions(null)
MathUtils.min(*positions)
positions.min()
}
else -> throw IllegalStateException("Can't do getFirstVisibleItemPosition for " + layoutManager.javaClass.name)
@@ -138,7 +138,7 @@ object LayoutManagerUtils {
is LinearLayoutManager -> layoutManager.findLastVisibleItemPosition()
is StaggeredGridLayoutManager -> {
val positions = layoutManager.findLastVisibleItemPositions(null)
MathUtils.max(*positions)
positions.max()
}
else -> throw IllegalStateException("Can't do getLastVisibleItemPosition for " + layoutManager.javaClass.name)
@@ -19,7 +19,6 @@ import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import com.hippo.ehviewer.R
import com.hippo.ehviewer.yorozuya.MathUtils.ceilDivide
import com.hippo.ehviewer.yorozuya.ViewUtils
/**
@@ -72,7 +71,7 @@ open class SimpleGridLayout : ViewGroup {
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val maxRowCount = ceilDivide(childCount, mColumnCount)
val maxRowCount = (childCount + mColumnCount - 1) / mColumnCount
if (mRowHeights == null || mRowHeights!!.size != maxRowCount) {
mRowHeights = IntArray(maxRowCount)
}
@@ -24,7 +24,7 @@ import androidx.annotation.NonNull;
import androidx.core.view.WindowInsetsAnimationCompat;
import androidx.core.view.WindowInsetsCompat;
import com.hippo.ehviewer.yorozuya.MathUtils;
import com.google.android.material.math.MathUtils;
import java.util.HashMap;
import java.util.List;
@@ -1,208 +0,0 @@
/*
* Copyright 2015 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.yorozuya;
import java.util.Random;
// Get most code from android.util.MathUtils
public final class MathUtils {
private static final Random sRandom = new Random();
private MathUtils() {
}
public static float abs(float v) {
return v > 0 ? v : -v;
}
public static float log(float a) {
return (float) Math.log(a);
}
public static float max(float a, float b) {
return a > b ? a : b;
}
public static float max(int a, int b) {
return a > b ? a : b;
}
public static float max(float a, float b, float c) {
return a > b ? (a > c ? a : c) : (b > c ? b : c);
}
public static float max(int a, int b, int c) {
return a > b ? (a > c ? a : c) : (b > c ? b : c);
}
public static float max(float... arg) {
int length = arg.length;
if (length <= 0) {
throw new IllegalArgumentException("Empty argument");
} else {
float n = arg[0];
float m;
for (int i = 1; i < length; i++) {
m = arg[i];
if (m > n)
n = m;
}
return n;
}
}
public static int max(int... arg) {
int length = arg.length;
if (length <= 0) {
throw new IllegalArgumentException("Empty argument");
} else {
int n = arg[0];
int m;
for (int i = 1; i < length; i++) {
m = arg[i];
if (m > n)
n = m;
}
return n;
}
}
public static float min(float a, float b) {
return a < b ? a : b;
}
public static float min(int a, int b) {
return a < b ? a : b;
}
public static float min(float a, float b, float c) {
return a < b ? (a < c ? a : c) : (b < c ? b : c);
}
public static float min(int a, int b, int c) {
return a < b ? (a < c ? a : c) : (b < c ? b : c);
}
public static float min(float... args) {
int length = args.length;
if (length <= 0) {
throw new IllegalArgumentException("Empty argument");
} else {
float n = args[0];
float m;
for (int i = 1; i < length; i++) {
m = args[i];
if (m < n)
n = m;
}
return n;
}
}
public static int min(int... args) {
int length = args.length;
if (length <= 0) {
throw new IllegalArgumentException("Empty argument");
} else {
int n = args[0];
int m;
for (int i = 1; i < length; i++) {
m = args[i];
if (m < n)
n = m;
}
return n;
}
}
public static float dist(float x1, float y1, float x2, float y2) {
final float x = (x2 - x1);
final float y = (y2 - y1);
return (float) Math.hypot(x, y);
}
public static float dist(float x1, float y1, float z1, float x2, float y2, float z2) {
final float x = (x2 - x1);
final float y = (y2 - y1);
final float z = (z2 - z1);
return (float) Math.sqrt(x * x + y * y + z * z);
}
public static float cross(float v1x, float v1y, float v2x, float v2y) {
return v1x * v2y - v1y * v2x;
}
public static int lerp(int start, int stop, float amount) {
return start + (int) ((stop - start) * amount);
}
public static float lerp(float start, float stop, float amount) {
return start + (stop - start) * amount;
}
public static float map(float minStart, float minStop, float maxStart, float maxStop, float value) {
return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
}
/**
* Returns the input value x clamped to the range [min, max].
*/
public static int clamp(int x, int min, int max) {
if (x > max) return max;
if (x < min) return min;
return x;
}
/**
* divide and ceil
*/
public static int ceilDivide(int a, int b) {
return (a + b - 1) / b;
}
/**
* [0, howbig)
*/
public static int random(int howbig) {
return (int) (sRandom.nextFloat() * howbig);
}
/**
* [howsmall, howbig)
*/
public static int random(int howsmall, int howbig) {
if (howsmall >= howbig)
return howsmall;
return lerp(howsmall, howbig, sRandom.nextFloat());
}
/**
* [0, howbig)
*/
public static float random(float howbig) {
return sRandom.nextFloat() * howbig;
}
/**
* [howsmall, howbig)
*/
public static float random(float howsmall, float howbig) {
if (howsmall >= howbig)
return howsmall;
return lerp(howsmall, howbig, sRandom.nextFloat());
}
}
@@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.reader.loader
import androidx.annotation.CallSuper
import androidx.collection.lruCache
import com.hippo.ehviewer.image.Image
import com.hippo.ehviewer.yorozuya.MathUtils
import com.hippo.ehviewer.yorozuya.OSUtils
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
@@ -23,7 +22,7 @@ abstract class PageLoader {
(0 until size).map { ReaderPage(it) }
}
private val mPreloads = MathUtils.clamp(com.hippo.ehviewer.Settings.preloadImage, 0, 100)
private val mPreloads = com.hippo.ehviewer.Settings.preloadImage.coerceIn(0, 100)
abstract suspend fun awaitReady(): Boolean
abstract val isReady: Boolean