R/intersect2.R

Defines functions .Spc.Intersect.SpcCompound .Spc.NoIntersect.SpcCompound

# This is the internal library of compound intersect methods

#==============================================================================

#this is the top level intersect, for a compount list of objects.
#The world, and indeed any sub-object can be a simple list of objects
#In which case we need to traverse the list and return the proerties
#of the closest object

.Spc.Intersect.SpcCompound <- function(ray.origin, ray.vector, objects) {


  if (length(objects) == 0)
    return(NA)

  int <- NA

  for (i in 1:length(objects)) {
    ii <- .Spc.Intersect(ray.origin, ray.vector, objects[[i]])

    if (!is.na(ii[1]) && (is.na(int[1]) || ii$distance < int$distance))
      int <- ii
  }

  #if (is.na(int))
  if (class(int) == "logical")
    return(NA)

  #Properties can be defined hierarchically for compound objects
  if (is.null(int$properties) || is.na(int$properties)) {
    int$properties <- attr(objects,"properties")
  }

  return(int)
}

#--------------------------

.Spc.NoIntersect.SpcCompound <- function(ray.origin, ray.vector, objects) {

  if (length(objects) == 0)
    return(TRUE)

  int <- NA

  for (i in 1:length(objects)) {
    ii <- .Spc.NoIntersect(ray.origin, ray.vector, objects[[i]])

    if (!ii) return(FALSE)
  }
  return(TRUE)
}
JerBoon/vecspace documentation built on May 26, 2019, 7:28 a.m.