diff --git a/src/lib/mod.rs b/src/lib/mod.rs index a1789bd14a3fd604aa433bd1561ee6ab6b116fec..7c2464c8ad7371b19babdd14e87d7753a6da9774 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -33,7 +33,6 @@ impl IEDGE { /// Triangulation subroutine. /// Allows one to triangulate a list of points in a O(n²) time complexity -/// pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, ntri: &mut i32) -> i32 { let trimax = 4 * *nv; let mut _nedge: i32 = 0; @@ -51,11 +50,11 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt let (mut xmin, mut xmax): (f64, f64); let (mut ymin, mut ymax): (f64, f64); - let mut j: isize = 0; + let mut _j: isize = 0; /* - Find the maximum and minimum vertex bounds. - This is to allow calculation of the bounding triangle + Find the maximum and minimum vertex bounds. + This is to allow calculation of the bounding triangle */ xmin = pxyz[0].x; ymin = pxyz[0].y; @@ -75,11 +74,11 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt /* - Set up the supertriangle - This is a triangle which encompasses all the sample points. - The supertriangle coordinates are added to the end of the - vertex list. The supertriangle is the first triangle in - the triangle list. + Set up the supertriangle + This is a triangle which encompasses all the sample points. + The supertriangle coordinates are added to the end of the + vertex list. The supertriangle is the first triangle in + the triangle list. */ pxyz.push(XYZ { x: xmid - 20.0 * dmax, @@ -105,10 +104,6 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt complete[0] = false; *ntri = 1; - // print_point(&pxyz[v[0].p1 as usize]); - // print_point(&pxyz[v[0].p2 as usize]); - // print_point(&pxyz[v[0].p3 as usize]); - /* Include each point one at a time into the existing mesh */ @@ -125,36 +120,36 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt and that triangle is removed. */ - j = 0; - while j < *ntri as isize { - if complete[j as usize] { - j += 1; + _j = 0; + while _j < *ntri as isize { + if complete[_j as usize] { + _j += 1; continue; } - x1 = pxyz[v[j as usize].p1 as usize].x; - y1 = pxyz[v[j as usize].p1 as usize].y; - x2 = pxyz[v[j as usize].p2 as usize].x; - y2 = pxyz[v[j as usize].p2 as usize].y; - x3 = pxyz[v[j as usize].p3 as usize].x; - y3 = pxyz[v[j as usize].p3 as usize].y; + x1 = pxyz[v[_j as usize].p1 as usize].x; + y1 = pxyz[v[_j as usize].p1 as usize].y; + x2 = pxyz[v[_j as usize].p2 as usize].x; + y2 = pxyz[v[_j as usize].p2 as usize].y; + x3 = pxyz[v[_j as usize].p3 as usize].x; + y3 = pxyz[v[_j as usize].p3 as usize].y; inside = circum_circle(xp,yp,x1,y1,x2,y2,x3,y3,&mut xc,&mut yc,&mut r); if xc < xp && ((xp-xc)*(xp-xc)) > r { - complete[j as usize] = true; + complete[_j as usize] = true; } if inside { /* Check that we haven't exceeded the edge list size */ - edges.push(IEDGE::new(v[j as usize].p1, v[j as usize].p2)); - edges.push(IEDGE::new(v[j as usize].p2, v[j as usize].p3)); - edges.push(IEDGE::new(v[j as usize].p3, v[j as usize].p1)); + edges.push(IEDGE::new(v[_j as usize].p1, v[_j as usize].p2)); + edges.push(IEDGE::new(v[_j as usize].p2, v[_j as usize].p3)); + edges.push(IEDGE::new(v[_j as usize].p3, v[_j as usize].p1)); _nedge += 3; - v[j as usize] = v[(*ntri-1) as usize]; - complete[j as usize] = complete[(*ntri-1) as usize]; + v[_j as usize] = v[(*ntri-1) as usize]; + complete[_j as usize] = complete[(*ntri-1) as usize]; *ntri -= 1; - j -= 1; + _j -= 1; } - j+=1; + _j+=1; } /* @@ -187,29 +182,23 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt Skipping over any tagged edges. All edges are arranged in clockwise order. */ - j = 0; - while j < _nedge as isize { - if edges[j as usize].p1 < 0 || edges[j as usize].p2 < 0 { - j += 1; + _j = 0; + while _j < _nedge as isize { + if edges[_j as usize].p1 < 0 || edges[_j as usize].p2 < 0 { + _j += 1; continue; } if (*ntri) >= trimax { status = 4; return status } - v[*ntri as usize].p1 = edges[j as usize].p1; - v[*ntri as usize].p2 = edges[j as usize].p2; + v[*ntri as usize].p1 = edges[_j as usize].p1; + v[*ntri as usize].p2 = edges[_j as usize].p2; v[*ntri as usize].p3 = i as i32; complete[*ntri as usize] = false; *ntri += 1; - j += 1; + _j += 1; } - // println!("================================"); - // println!("(2) j = {}, *ntri = {}", j, *ntri); - // for it in 0_usize..*ntri as usize { - // print_tri(&v[it]); - // } - // println!("================================"); } @@ -235,8 +224,6 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt i -= 1; } - // println!("len : {} \n {:#?} ", *nv, v); - /* removing super triangle vertices */ pxyz.remove(pxyz.len()-1); pxyz.remove(pxyz.len()-1); @@ -248,7 +235,7 @@ pub fn triangulate(nv: &mut i32, pxyz: &mut Vec<XYZ>, v: &mut Vec<ITRIANGLE>, nt /// Return true if a point (xp,yp) lies inside the circumcircle made up /// of the points (x1,y1), (x2,y2), (x3,y3) /// The circumcircle centre is returned in (xc,yc) and the radius r -/// NOTE: A point on the edge is inside the circumcircle +/// NOTE: A point on the edge is considered inside the circumcircle fn circum_circle(xp: f64, yp: f64, x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64, xc: &mut f64, yc: &mut f64, rsqr: &mut f64) -> bool { let m1: f64; let m2: f64;