That fuck shit the fascists are using
at master 55 lines 1.8 kB view raw
1package org.tm.archive.util; 2 3import android.graphics.PointF; 4 5import androidx.annotation.NonNull; 6 7public class MathUtils { 8 9 /** 10 * For more info: 11 * <a href="http://math.stackexchange.com/questions/190111/how-to-check-if-a-point-is-inside-a-rectangle">StackOverflow: How to check point is in rectangle</a> 12 * 13 * @param pt point to check 14 * @param v1 vertex 1 of the triangle 15 * @param v2 vertex 2 of the triangle 16 * @param v3 vertex 3 of the triangle 17 * @return true if point (x, y) is inside the triangle 18 */ 19 public static boolean pointInTriangle(@NonNull PointF pt, @NonNull PointF v1, 20 @NonNull PointF v2, @NonNull PointF v3) { 21 22 boolean b1 = crossProduct(pt, v1, v2) < 0.0f; 23 boolean b2 = crossProduct(pt, v2, v3) < 0.0f; 24 boolean b3 = crossProduct(pt, v3, v1) < 0.0f; 25 26 return (b1 == b2) && (b2 == b3); 27 } 28 29 /** 30 * calculates cross product of vectors AB and AC 31 * 32 * @param a beginning of 2 vectors 33 * @param b end of vector 1 34 * @param c end of vector 2 35 * @return cross product AB * AC 36 */ 37 private static float crossProduct(@NonNull PointF a, @NonNull PointF b, @NonNull PointF c) { 38 return crossProduct(a.x, a.y, b.x, b.y, c.x, c.y); 39 } 40 41 /** 42 * calculates cross product of vectors AB and AC 43 * 44 * @param ax X coordinate of point A 45 * @param ay Y coordinate of point A 46 * @param bx X coordinate of point B 47 * @param by Y coordinate of point B 48 * @param cx X coordinate of point C 49 * @param cy Y coordinate of point C 50 * @return cross product AB * AC 51 */ 52 private static float crossProduct(float ax, float ay, float bx, float by, float cx, float cy) { 53 return (ax - cx) * (by - cy) - (bx - cx) * (ay - cy); 54 } 55}