Пример #1
0
func (m *Mesh) SubsetBoundingBox(subset interface{}) *cb.Cuboid {
	var subset_indices []int

	if verts, ok := subset.([]VertexI); ok {
		subset_indices = make([]int, len(verts), len(verts))
		for i, vert := range verts {
			subset_indices[i] = vert.GetLocationInMesh(*m)
		}
	} else {
		subset_indices = subset.([]int)
	}

	var minX, maxX, minY, maxY, minZ, maxZ float64
	minX = math.Inf(1)
	minY = math.Inf(1)
	minZ = math.Inf(1)
	maxX = math.Inf(-1)
	maxY = math.Inf(-1)
	maxZ = math.Inf(-1)
	for _, i := range subset_indices {
		v := m.Vertices.Get(i)[0]
		minX = math.Min(minX, v.GetX())
		minY = math.Min(minY, v.GetY())
		minZ = math.Min(minZ, v.GetZ())
		maxX = math.Max(maxX, v.GetX())
		maxY = math.Max(maxY, v.GetY())
		maxZ = math.Max(maxZ, v.GetZ())
	}
	return cb.New(minX, minY, minZ, maxX, maxY, maxZ)
}
Пример #2
0
func (m *Mesh) BoundingBox() *cb.Cuboid {
	var minX, maxX, minY, maxY, minZ, maxZ float64
	minX = math.Inf(1)
	minY = math.Inf(1)
	minZ = math.Inf(1)
	maxX = math.Inf(-1)
	maxY = math.Inf(-1)
	maxZ = math.Inf(-1)
	for i := 0; i < m.Vertices.Len(); i++ {
		v := m.Vertices.Get(i)[0]
		minX = math.Min(minX, v.GetX())
		minY = math.Min(minY, v.GetY())
		minZ = math.Min(minZ, v.GetZ())
		maxX = math.Max(maxX, v.GetX())
		maxY = math.Max(maxY, v.GetY())
		maxZ = math.Max(maxZ, v.GetZ())
	}
	return cb.New(minX, minY, minZ, maxX, maxY, maxZ)
}