Problem:
Problem F: Heavenly Jewels

There is a flat island whose shape is a perfect square. On this island, there are three habitants whose names are IC, PC, and ACM Every day, one jewel is dropped from the heaven. Just as the jewel touches the ground, IC, PC, and ACM leave their houses simultaneously, run with the same speed, and then a person who first touched the jewel can get the jewel. Hence, the person whose house is nearest to the location of the jewel is the winner of that day.

They always have a quarrel with each other, and therefore their houses are located at distinct places. The locations of their houses are fixed. This jewel falls at a random point on the island, that is, all points on the island have even chance.

When three are two or more persons whose houses are simultaneously nearest, the last person in the order of

IC, PC, ACM

obtains the jewel.

Our interest is to know the probability for IC to get the jewel under this situation.

Input

The input describes one problem instance per line. Each line contains the x- and y-coordinates of IC's home, those of PC's, and those of ACM's in this order. Note that the houses of IC, PC and ACM are located at distinct places. The end of the input is indicated by a line with six zeros.

The coordinates of the whole island are given by (0, 10000) × (0, 10000) and coordinates of houses are given in integer numbers between 1 and 9999, inclusive. It should be noted that the locations of the jewels are arbitrary places on the island and their coordinate values are not necessarily integers.

Output

For each input line, your program should output its sequence number starting from 1, and the probability for the instance. The computed probability values should have errors less than 10-5.

The sequence number and the probability should be printed on the same line. The two numbers should be separated by a space.

Sample Input

2000 2000 8000 8000 9000 9500
2500 2500 7500 2500 2500 7500
0 0 0 0 0 0

Output for the Sample Input

1 0.50000
2 0.25000

Solution in Ruby (judge verdict: Runtime Error)

### constant

MAX_X = MAX_Y = 10000.0
DELTA = 1e-5

CNRS = [[0.0, 0.0], [MAX_X, 0.0], [MAX_X, MAX_Y], [0.0, MAX_Y]]

### subroutines

def get_line(x0, y0, x1, y1)
  cx = (x0 + x1) / 2
  cy = (y0 + y1) / 2
  vx = -(y1 - y0)
  vy =  (x1 - x0)
  [cx, cy, vx, vy]
end

def i_prod(vx0, vy0, vx1, vy1)
  vx0 * vx1 + vy0 * vy1
end

def o_prod(vx0, vy0, vx1, vy1)
  vx0 * vy1 - vx1 * vy0
end

# x = vx0*s+cx0 = vx1*t+cx1
# y = vy0*s+cy0 = vy1*t+cy1
# |vx0 -vx1| |s| = |cx1-cx0|
# |vy0 -vy1| |t|   |cy1-cy0|
# |s| = 1/(vx0*vy1-vx1*vy0)|vy1 -vx1||cx1-cx0|
# |t|                      |vy0 -vx0||cy1-cy0|

def cross(cx0, cy0, vx0, vy0, cx1, cy1, vx1, vy1)
  d = o_prod(vx0, vy0, vx1, vy1)
  return nil if d == 0.0
  s = (vy1 * (cx1 - cx0) - vx1 * (cy1 - cy0)) / d
  [vx0 * s + cx0, vy0 * s + cy0]
end

def triangle(x0, y0, x1, y1, x2, y2)
  o_prod(x1 - x0, y1 - y0, x2 - x0, y2 - y0).abs / 2
end

def dist2(x0, y0, x1, y1)
  (x1 - x0) ** 2 + (y1 - y0) ** 2
end

def div_border(ix, iy, px, py, ax, ay, lip, lia)
  ptsi = 4.times.map{|i| [CNRS[i]]}
  $bls.each_with_index do |bl, i|
    for l in [lip, lia]
      pt = cross(*l, *bl)
      if pt &&
         pt[0] >= 0.0 && pt[0] <= MAX_X && pt[1] >= 0.0 && pt[1] <= MAX_Y
        ptsi[i] << pt
      end
    end
  end

  ptsi.each{|pts| pts.sort!}
  ptsi[2].reverse!
  ptsi[3].reverse!
  pts = ptsi.flatten(1).uniq
  #p [[cx, cy], pts]

  nrsts = pts.map do |pt|
    d2i = dist2(ix, iy, *pt)
    d2p = dist2(px, py, *pt)
    d2a = dist2(ax, ay, *pt)
    (d2i <= d2p && d2i <= d2a)
  end

  [pts, nrsts]
end

### main

$bls = 4.times.map do |i|
  j = (i + 1) % 4
  vx = CNRS[j][0] - CNRS[i][0]
  vy = CNRS[j][1] - CNRS[i][1]
  [*CNRS[i], vx, vy]
end
#p $bls

seq = 0

loop do
  line = gets.strip
  break if line == '0 0 0 0 0 0'

  ix, iy, px, py, ax, ay = line.split.map(&:to_f)
  #p [ix, iy, px, py, ax, ay]

  lip = get_line(ix, iy, px, py)
  lia = get_line(ix, iy, ax, ay)
  lpa = get_line(px, py, ax, ay)

  ar = 0.0
  
  ci = cross(*lip, *lia)

  pts, nrsts = div_border(ix, iy, px, py, ax, ay, lip, lia)
  npts = pts.length
  
  if ci && ci[0] > 0.0 && ci[0] < MAX_X && ci[1] > 0.0 && ci[1] < MAX_Y
    for i in (0...npts)
      j = (i + 1) % npts
      if nrsts[i] && nrsts[j]
        ar += triangle(*ci, *pts[i], *pts[j])
      end
    end
  else
    while ! nrsts.first || nrsts.last
      pts.rotate!
      nrsts.rotate!
    end
    #p pts
    #p nrsts

    ply = []
    for i in (0...npts)
      if nrsts[i]
        ply << pts[i]
      else
        if ! ply.empty?
          pt0 = ply.shift
          ply.each_cons(2) do |pt1, pt2|
            ar += triangle(*pt0, *pt1, *pt2)
          end
          pt0 = []
        end
      end
    end
  end

  seq += 1
  puts [seq, "%.5f" % (ar / (MAX_X * MAX_Y))].join(' ')
end