\name{and.globalSeg}
\alias{and.globalSeg}
\alias{&.globalSeg}
%- Also NEED an '\alias' for EACH other topic documented here.
\title{Intersection of global segments}
\description{
  Computes intersection of two objects of class
  globalSeg a and b,  i.e. returns segments that are both in a and b.

  When used with only one object of class globalSeg, it computes
  intersection of all its segments set (an segments sets
  is a set of segments; an object of class globalSeg
  is a set of segments sets).
  In this case, when global=TRUE, it computes the intersection of
  all the segments (see example below).
}
\usage{
and.globalSeg(a, b = NULL, global = FALSE, byrows = FALSE, relist = TRUE, 
    ...) 
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{a,b}{elements of class globalSeg}
  \item{global}{used if b=NULL}
  \item{byrows}{if TRUE,  \code{a} and \code{b} must be lists of same
    length, and intersection is computed for each elements from \code{a}
    with its homologue in  \code{b}.    
  }
  \item{relist}{is TRUE, results are re-listed (envelops are union of
    all \code{a} and \code{b}).
  }
  \item{...}{Unused}
}

\value{
  an element of class globalSeg.
}

\author{Odile Rogier}



\seealso{\link{globalSeg},\link{and.segSet}}
\examples{
a = list(
    matrix( c( 1, 15, 17,  5, 45, 38),ncol=2),
    matrix( c( 100 , 120),ncol=2),
    matrix( c( 130, 135, 140, 145),ncol=2),
    matrix( c( 142 , 160),ncol=2))


b = list(
    matrix( c(15, 28, 18, 45),ncol=2),
    matrix( c(1, 15, 25, 10, 20, 40),ncol=2),
    matrix( c(17, 35, 23, 38),ncol=2),
    matrix( c(100, 110, 105, 120),ncol=2))

a = as.globalSeg(a)
b = as.globalSeg(b)



c = and(a,b,byrows=TRUE)
par(mfrow=c(5,1))
plot(a,xlim=c(1,160),main="A")
plot(b,xlim=c(1,160),main="B")
plot(a&b,xlim=c(1,160),main="A&B")
plot(c,xlim=c(1,160),main="A&B, byrow=T")
plot(and(a),xlim=c(1,160),main="and(A)")

## Show result
a&b
c
and(a)
}

\keyword{utilities}