  % Title "Intersections Demo"
 '% Animated
 '% ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  uses consoleG
  uses GLO2\GeoPlanar

  sub boundaries()
  ================
  indexbase 0

  string tab="    "
  point  p
  int    a,i,j,k

  seed=0x123567

  line  d[8]
  float f[16]
  f={-1,-1, 1,-1,  1,1, -1,1}
  for i=0 to 7
    f[i]+=rnd()*0.4 'turbulate
  next
  '
  d[0]={ f[0],f[1],f[2],f[3]}
  d[1]={ f[2],f[3],f[4],f[5]}
  d[2]={ f[4],f[5],f[6],f[7]}
  d[3]={ f[6],f[7],f[0],f[1]}
  '
  for i=0 to 7
    f[i]=f[i]*0.5 'smaller inner form
  next
  '
  d[4]={ f[0],f[1],f[2],f[3]}
  d[5]={ f[2],f[3],f[4],f[5]}
  d[6]={ f[4],f[5],f[6],f[7]}
  d[7]={ f[6],f[7],f[0],f[1]}



  'shading
  flat 'default
  '
  color 0,1,1
  'printl "Inside " tab p.x tab p.y

  scale 10,10

  move 1.5,-1
  '
  color 0,1,1
  thickness 3
  '
  for i=0 to 7
    drawline @d[i]
  next
  '
  int inside
  point pio
  line dd
  '
  float x,y
  for j=1 to 1000
    x=2*rnd
    y=2*rnd
    pio={x,y}
    gosub checkInside
  next
  exit sub
  '
  CheckInside:
  ============
  color 1,1,0
  pointsize 4
  dd={-1000,pio.y,1000,pio.y}
  inside=0
  for i=0 to 7
   a=intersected d[i],dd,p
   if a
     'drawline @dd
     'drawpoint @p
     if p.x<pio.x
       inside=1-inside 'toggle
     endif
   endif
  next
  '
  if inside
    color 1,1,0
  else
    color 0.8,0,0
  endif
  pointsize 4
  drawpoint @pio
  ret  
  



  end sub


  sub main()
  ==========
  string s
  cls 0,0,0
  pushstate
  scale 2,2
  'typeface=1
  printl "Inside / Outside Points"
  popstate
  '
  move 0,-2
  '
  PushState
  move 1,-1
  boundaries()
  PopState
  '
  
  end sub

  EndScript
