// EdenAutoMorpher_ProfileSaver_Script, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Eden.AutoMorpher.profile.ProfileUtils_VolumeUtil
using System.Collections.Generic;
using UnityEngine;

public class ProfileUtils_VolumeUtil
{
    public VolumeData GetVolumeData(Transform originTransform, Transform axisTransform, List<Vector3> points, int sampleStep = 1)
    {
        if (originTransform == null)
        {
            Debug.LogError("[ProfileUtils_VolumeUtil] originTransform is null");
            return null;
        }
        if (axisTransform == null)
        {
            Debug.LogError("[ProfileUtils_VolumeUtil] axisTransform is null");
            return null;
        }
        if (points == null || points.Count == 0)
        {
            Debug.LogError("[ProfileUtils_VolumeUtil] There is No Points to calculate volume");
            return null;
        }
        VolumeData volumeData = new VolumeData();
        Vector3 forward = axisTransform.forward;
        Vector3 right = axisTransform.right;
        Vector3 up = axisTransform.up;
        float num = float.PositiveInfinity;
        float num2 = float.NegativeInfinity;
        float num3 = float.PositiveInfinity;
        float num4 = float.NegativeInfinity;
        float num5 = float.PositiveInfinity;
        float num6 = float.NegativeInfinity;
        for (int i = 0; i < points.Count; i += sampleStep)
        {
            Vector3 lhs = points[i] - originTransform.position;
            float num7 = Vector3.Dot(lhs, up);
            if (num7 < num)
            {
                num = num7;
            }
            if (num7 > num2)
            {
                num2 = num7;
            }
            float num8 = Vector3.Dot(lhs, forward);
            if (num8 < num3)
            {
                num3 = num8;
            }
            if (num8 > num4)
            {
                num4 = num8;
            }
            float num9 = Vector3.Dot(lhs, right);
            if (num9 < num5)
            {
                num5 = num9;
            }
            if (num9 > num6)
            {
                num6 = num9;
            }
        }
        volumeData.forwardDir = forward;
        volumeData.rightDir = right;
        volumeData.upDir = up;
        volumeData.fMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + forward * num4);
        volumeData.fMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + forward * num3);
        volumeData.rMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + right * num6);
        volumeData.rMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + right * num5);
        volumeData.uMaxLocalPos = originTransform.InverseTransformPoint(originTransform.position + up * num2);
        volumeData.uMinLocalPos = originTransform.InverseTransformPoint(originTransform.position + up * num);
        return volumeData;
    }
}
