package com.google.ar.sceneform.samples.hellosceneform;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import android.view.MotionEvent;
import android.view.View;
import android.view.MotionEvent.PointerCoords;
import android.view.MotionEvent.PointerProperties;
import com.google.ar.core.Pose;
import com.google.ar.sceneform.Node;
import com.google.ar.sceneform.Scene;
import com.google.ar.sceneform.collision.Plane;
import com.google.ar.sceneform.collision.Ray;
import com.google.ar.sceneform.collision.RayHit;
import com.google.ar.sceneform.math.Quaternion;
import com.google.ar.sceneform.math.Vector3;
import com.google.ar.sceneform.rendering.ViewRenderable;
import com.google.ar.sceneform.utilities.Preconditions;

class a {
    static Vector3 a(Pose var0) {
        return new Vector3(var0.tx(), var0.ty(), var0.tz());
    }

    static Quaternion b(Pose var0) {
        return new Quaternion(var0.qx(), var0.qy(), var0.qz(), var0.qw());
    }

    static boolean a(Node var0, MotionEvent var1) {
        Preconditions.checkNotNull(var0, "Parameter \"node\" was null.");
        Preconditions.checkNotNull(var1, "Parameter \"motionEvent\" was null.");
        if (!(var0.getRenderable() instanceof ViewRenderable)) {
            return false;
        } else if (!var0.isActive()) {
            return false;
        } else {
            Scene var2;
            if ((var2 = var0.getScene()) == null) {
                return false;
            } else {
                ViewRenderable var3;
                if ((var3 = (ViewRenderable)var0.getRenderable()) == null) {
                    return false;
                } else {
                    int var4;
                    PointerProperties[] var5 = new PointerProperties[var4 = var1.getPointerCount()];
                    PointerCoords[] var6 = new PointerCoords[var4];
                    Plane var7 = new Plane(var0.getWorldPosition(), var0.getForward());
                    RayHit var8 = new RayHit();
                    Plane var9 = new Plane(var0.getWorldPosition(), var0.getBack());

                    for(int var10 = 0; var10 < var4; ++var10) {
                        PointerProperties var11 = new PointerProperties();
                        PointerCoords var12 = new PointerCoords();
                        var1.getPointerProperties(var10, var11);
                        var1.getPointerCoords(var10, var12);
                        Ray var14 = var2.getCamera().screenPointToRay(var12.x, var12.y);
                        Vector3 var15;
                        if (var7.rayIntersection(var14, var8)) {
                            var15 = a(var0, var8.getPoint(), var3);
                            var12.x = var15.x;
                            var12.y = var15.y;
                        } else if (var9.rayIntersection(var14, var8)) {
                            var15 = a(var0, var8.getPoint(), var3);
                            var12.x = (float)var3.getView().getWidth() - var15.x;
                            var12.y = var15.y;
                        } else {
                            var12.clear();
                            var11.clear();
                        }

                        var5[var10] = var11;
                        var6[var10] = var12;
                    }

                    MotionEvent var16 = MotionEvent.obtain(var1.getDownTime(), var1.getEventTime(), var1.getAction(), var4, var5, var6, var1.getMetaState(), var1.getButtonState(), var1.getXPrecision(), var1.getYPrecision(), var1.getDeviceId(), var1.getEdgeFlags(), var1.getSource(), var1.getFlags());
                    return var3.getView().dispatchTouchEvent(var16);
                }
            }
        }
    }

    static Vector3 a(Node var0, Vector3 var1, ViewRenderable var2) {
        Preconditions.checkNotNull(var0, "Parameter \"node\" was null.");
        Preconditions.checkNotNull(var1, "Parameter \"worldPos\" was null.");
        Preconditions.checkNotNull(var2, "Parameter \"viewRenderable\" was null.");
        Vector3 var3 = var0.worldToLocalPoint(var1);
        View var4;
        int var5 = (var4 = var2.getView()).getWidth();
        int var6 = var4.getHeight();
        float var7 = a(var2);
        int var8 = (int)(var3.x * var7);
        int var9 = (int)(var3.y * var7);
        int var10 = var5 / 2;
        int var11 = var6 / 2;
        switch(var2.getVerticalAlignment().ordinal()) {
            case 0:
                var9 = var6 - var9;
                break;
            case 1:
                var9 = var6 - (var9 + var11);
                break;
            case 2:
                var9 = var6 - (var9 + var6);
        }

        switch(var2.getHorizontalAlignment().ordinal()) {
            case 0:
            default:
                break;
            case 1:
                var8 += var10;
                break;
            case 2:
                var8 += var5;
        }

        return new Vector3((float)var8, (float)var9, 0.0F);
    }

    private static float a(ViewRenderable var0) {
        int var2 = var0.getView().getWidth();
        Vector3 var3;
        return (var3 = var0.getSizer().getSize(var0.getView())).x == 0.0F ? 0.0F : (float)var2 / var3.x;
    }
}
