import java.awt.Point; import java.util.*; public class e { Scanner in=new Scanner(System.in); public static void main(String[] args) { new e().go(); } private void go() { while(true){ int[] d=new int[8]; for(int i=0;i<8;i++)d[i]=in.nextInt(); if(d[0]==d[2])break; boolean aon=d[4]>=d[0]&&d[4]<=d[2]&&d[5]>=d[1]&&d[5]<=d[3]; boolean bon=d[6]>=d[0]&&d[6]<=d[2]&&d[7]>=d[1]&&d[7]<=d[3]; if(aon&&bon){//both on the grid System.out.printf("%.3f\n",(double)Math.abs(d[7]-d[5])+Math.abs(d[6]-d[4])); continue; } if(aon){//if aon the grid, flip the points for simplicity int temp=d[5]; d[5]=d[7]; d[7]=temp; temp=d[4]; d[4]=d[6]; d[6]=temp; } if(aon||bon){//if one left on grid, iterate through all points visible to other double min=Double.MAX_VALUE; if(d[4]d[2])for(int i=d[1];i<=d[3];i++)min=Math.min(min, Math.sqrt(Math.pow(d[4]-d[2], 2)+Math.pow(d[5]-i, 2))+Math.abs(d[7]-i)+Math.abs(d[6]-d[2])); if(d[5]d[3])for(int i=d[0];i<=d[2];i++)min=Math.min(min, Math.sqrt(Math.pow(d[4]-i, 2)+Math.pow(d[5]-d[3], 2))+Math.abs(d[6]-i)+Math.abs(d[7]-d[3])); System.out.printf("%.3f\n",min); continue; } int count=0; count+=cross(d[4],d[5],d[6],d[7],d[0],d[1]); count+=cross(d[4],d[5],d[6],d[7],d[0],d[3]); count+=cross(d[4],d[5],d[6],d[7],d[2],d[1]); count+=cross(d[4],d[5],d[6],d[7],d[2],d[3]); if((d[4]>=d[2]&&d[6]>=d[2])||(d[4]<=d[0]&&d[6]<=d[0])||(d[5]>=d[3]&&d[7]>=d[3])||(d[5]<=d[1]&&d[7]<=d[1])||Math.abs(count)==4){//straight line (either both left or right up or down of whole thing, or crossproduct to each corner is the same System.out.printf("%.3f\n",Math.sqrt(Math.pow(d[7]-d[5],2)+Math.pow(d[6]-d[4],2))); continue; } double min=Double.MAX_VALUE;//both off, no straight line, iterate over all points visible to each one ArrayList a=new ArrayList(),b=new ArrayList(); if(d[4]d[2])for(int i=d[1];i<=d[3];i++)a.add(new Point(d[2],i)); if(d[5]d[3])for(int i=d[0];i<=d[2];i++)a.add(new Point(i,d[3])); if(d[6]d[2])for(int i=d[1];i<=d[3];i++)b.add(new Point(d[2],i)); if(d[7]d[3])for(int i=d[0];i<=d[2];i++)b.add(new Point(i,d[3])); for(Point aa:a)for(Point bb:b)min=Math.min(min, Math.sqrt(Math.pow(d[5]-aa.y,2)+Math.pow(d[4]-aa.x,2))+Math.sqrt(Math.pow(d[7]-bb.y,2)+Math.pow(d[6]-bb.x,2))+Math.abs(aa.x-bb.x)+Math.abs(aa.y-bb.y)); System.out.printf("%.3f\n",min); } } private int cross(int i, int j, int k, int l, int m, int n) { int tmp=(k-i)*(n-j)-(m-i)*(l-j); if(tmp==0)return 18; return tmp/Math.abs(tmp); } } //Extended Manhattan Distance //cross products //case work