//---- // merge graphics path //---- /** * merge path commands */ public static List<GraphicsPath> mergePathCommands( PathInfo p0, PathInfo p1, float err=0.1f ) { if ( p0.paths.Count == 0 || p1.paths.Count == 0 ) { //throw new Error("[mergePathCommands] PathInfo has no path.") Debug.LogError("[mergePathCommands] PathInfo has no path."); } //segment 1st List<List<IPath>> paths0 = new List<List<IPath>>(); List<List<IPath>> paths1 = new List<List<IPath>>(); _segmentPathToCompare( p0, p1, err, paths0, paths1 ); //segment 2nd make graphics paths List<int> c0 = new List<int>(); List<float> d0 = new List<float>(); List<float> d1 = new List<float>(); _mergeGraphicsPathCommands( c0, d0, d1, paths0, paths1 ); //make result List<GraphicsPath> res; //res = new Vector.<GraphicsPath>(2, true); res = new List<GraphicsPath>(); res[0] = new GraphicsPath(c0, d0); res[1] = new GraphicsPath(c0, d1); return res; }
//---- // merge path //---- public static GraphicsPath mergePath( PathInfo p0, PathInfo p1 ) { //交点を求めてパスを分割 //パスを結合 return null; }
private static void _segmentPathToCompare(PathInfo p0, PathInfo p1, float err, List<List<IPath>> paths0, List<List<IPath>> paths1 ) { int n0 = p0.paths.Count; int n1 = p1.paths.Count; float len0 = p0.length; float len1 = p1.length; int b0 = 0; int b1 = 0; int i0 = 0; int i1 = 0; bool last0 = false; bool last1 = false; err = err * 2.0f / (n0 + n1); float s0 = p0._lengths[0] / len0; float s1 = p1._lengths[0] / len1; bool flg = true; while ( flg ) { bool gt = ( s0 > s1 ); float d = ( gt ) ? s0 - s1 : s1 - s0; if ( d < err ) { i0++; i1++; s0 = p0._lengths[i0] / len0; s1 = p1._lengths[i1] / len1; //paths0.Add( p0.path.slice( b0, i0 ) ); paths0.Add( p0.paths.GetRange( b0, b0 + i0 ) ); paths1.Add( p1.paths.GetRange( b1, b1 + i1 ) ); last0 = ( i0 >= n0 - 1 ); last1 = ( i1 >= n1 - 1 ); b0 = i0; b1 = i1; }else if ( gt ) { i1++; s1 = p1._lengths[i1] / len1; last1 = ( i1 >= n1 - 1 ); }else { i0++; s0 = p0._lengths[i0] / len0; last0 = ( i0 >= n0 - 1 ); } if ( last0 || last1 ) { paths0.Add( p0.paths.GetRange( b0, b0 + n0 ) ); paths1.Add( p1.paths.GetRange( b1, b1 + n1 ) ); flg = false; } } }