func newSurfaceBoundingBoxTree(surface *verb.NurbsSurface, splitV bool, knotTolU, knotTolV *float64) *surfaceBoundingBoxTree { this := new(surfaceBoundingBoxTree) this.surface = surface knotsU, knotsV := KnotVec(surface.KnotsU()), KnotVec(surface.KnotsV()) var _knotTolU float64 if knotTolU == nil { _knotTolU = knotsU.Domain() / 16.0 } else { _knotTolU = *knotTolU } var _knotTolV float64 if knotTolV == nil { _knotTolV = knotsV.Domain() / 16.0 } else { _knotTolV = *knotTolV } var divisible bool if splitV { divisible = knotsV.Domain() > _knotTolV } else { divisible = knotsU.Domain() > _knotTolU } if !divisible { return this } var min, max float64 if splitV { min = knotsV[0] max = knotsV[len(knotsV)-1] } else { min = knotsU[0] max = knotsU[len(knotsU)-1] } dom := max - min pivot := (min+max)/2.0 + dom*0.1*rand.Float64() srf0, srf1 := this.surface.Split(pivot, splitV) this.children = [2]BoundingBoxTree{ newSurfaceBoundingBoxTree(srf0, !splitV, &_knotTolU, &_knotTolV), newSurfaceBoundingBoxTree(srf1, !splitV, &_knotTolU, &_knotTolV), } return this }
func newLazySurfaceBoundingBoxTree(surface *verb.NurbsSurface, splitV bool, knotTolU, knotTolV *float64) *lazySurfaceBoundingBoxTree { this := lazySurfaceBoundingBoxTree{ surface: surface, knotsU: surface.KnotsU(), knotsV: surface.KnotsV(), splitV: splitV, // default: false } if knotTolU == nil { this.knotTolU = this.knotsU.Domain() / 16 } else { this.knotTolU = *knotTolU } if knotTolV == nil { this.knotTolV = this.knotsV.Domain() / 16 } else { this.knotTolV = *knotTolV } return &this }