lixiaojun
6 天以前 fba4613d6b8dcbcaea6c7dc83bda14ed49d2f6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using OpenTK.Mathematics;
 
namespace Yw.WinFrmUI.Hydro
{
    /// <summary>
    /// 包围盒
    /// </summary>
    internal class BoundingBox3
    {
        /// <summary>
        /// 
        /// </summary>
        public BoundingBox3() { }
 
        /// <summary>
        /// 
        /// </summary>
        public BoundingBox3(Vector3 min, Vector3 max)
        {
            this.Min = min;
            this.Max = max;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public BoundingBox3(List<Vector3> pts)
        {
            Vector3 min = new(float.MaxValue);
            Vector3 max = new(float.MinValue);
 
            foreach (var pt in pts)
            {
                min = Vector3.ComponentMin(min, pt);
                max = Vector3.ComponentMax(max, pt);
            }
            this.Min = min;
            this.Max = max;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public Vector3 Min { get; set; }
 
        /// <summary>
        /// 
        /// </summary>
        public Vector3 Max { get; set; }
 
        /// <summary>
        /// 中心点
        /// </summary>
        public Vector3 Center => (Min + Max) / 2f;
 
        /// <summary>
        /// 尺寸
        /// </summary>
        public Vector3 Size => Max - Min;
 
        /// <summary>
        /// 是否包含
        /// </summary>
        public bool Contains(Vector3 pt)
        {
            if (pt.X > this.Max.X || pt.X < this.Min.X)
            {
                return false;
            }
            if (pt.Y > this.Max.Y || pt.Y < this.Min.Y)
            {
                return false;
            }
            if (pt.Z > this.Max.Z || pt.Z < this.Min.Z)
            {
                return false;
            }
 
            return true;
        }
 
 
        /// <summary>
        /// 计算
        /// </summary>
        public static BoundingBox3 Calculate(List<Vector3> pts)
        {
            if (pts == null || pts.Count < 1)
            {
                return default;
            }
            return new BoundingBox3(pts);
        }
 
        /// <summary>
        /// 合并
        /// </summary>
        public static BoundingBox3 Merge(BoundingBox3 a, BoundingBox3 b)
        {
            return new BoundingBox3(
                Vector3.ComponentMin(a.Min, b.Min),
                Vector3.ComponentMin(a.Max, b.Max)
            );
        }
 
 
 
 
 
 
 
 
 
    }
}