public bool equals(TDNode other) { bool test = false; if (other == null && p == null && s == null && t == null) { return(true); } else if (other == null) { return(false); } else { if (p != null && other.p != null && p.equals(other.p)) { test = true; } if (s != null && other.s != null && s.equals(other.s)) { test = true; } if (t != null && other.t != null && t.equals(other.t)) { test = true; } if (type != other.getType()) { test = false; } return(test); } }
public bool equals(TrapezoidFace other) { return(other == null?isEmpty() : ((top == null ? other.top == null : top.equals(other.top)) && (bottom == null ? other.bottom == null : bottom.equals(other.bottom)) && (leftp == null ? other.leftp == null : leftp.equals(other.leftp)) && (rightp == null ? other.rightp == null : rightp.equals(other.rightp)) && upperLeft == other.upperLeft && lowerLeft == other.lowerLeft && upperRight == other.upperRight && lowerRight == other.lowerRight)); }
/* * Creates trapezoidal maps the "naive" way. More specifically, this * function iterates through each shape, and each point of each shape, * creating a TrapezoidLine for each point with an initially long length. * Then, this length is minimized over all the x intersections for above the * point. This is repeated for all the lines below the point. This is * primarily used for drawing the visual lines on the screen (as any time * savings are already negated when having to draw all objects anyway). */ public List <TrapezoidLine> naiveMap(float width, float height) { //return all the vertical lines of trapezoid. //TODO:fix the boundary parameter; List <TrapezoidLine> trapezoidMap = new List <TrapezoidLine>(); // Add the borders of the window as temporary shapes TDShape border = new TDShape(); TDShape border2 = new TDShape(); border.getPoints().Add(new TDPoint(-1f * height, 0)); border.getPoints().Add(new TDPoint(height, 0)); border2.getPoints().Add(new TDPoint(0, -1f * width)); border2.getPoints().Add(new TDPoint(0, width)); shapes.Add(border); shapes.Add(border2); // Step through each shape for (int i = 0; i < shapes.Count; i++) { //TDShape s = shapes[i]; //TDShape sh = shapes[i + 1]; TDShape sh = shapes[i]; // Ignore the border shapes so their points do not appear as part of // the trapezoidal map if (sh.equals(border) || sh.equals(border2)) { continue; } // Step through the points in the current shape for (int pi = 0; pi < sh.getPoints().Count; pi++) { //TDPoint p = sh.getPoints()[pi]; TDPoint pt = sh.getPoints()[pi]; // Generate two trapezoidal lines for each point (up and down) TrapezoidLine t = new TrapezoidLine(pt, height + 1, true); TrapezoidLine t2 = new TrapezoidLine(pt, height + 1, false); bool tu = false; bool t2u = false; // Iterate over all shapes, intersecting the trapezoidal lines // with each of the shapes for (int s2i = 0; s2i < shapes.Count; s2i++) { //TDShape s2 = shapes[s2i]; TDShape sh2 = shapes[s2i]; // if(!sh.equals(sh2)) { // If the intersection yields a positive difference that is // smaller than the previous length, update t // down if (t.getStart().y - sh2.intersect(t, height + 1) > 0) { t.setLength(Mathf.Min((t.getStart().y - sh2 .intersect(t, height + 1)), t.getLength())); tu = true; } // if the intersection yields a negative difference that is // absolutely smaller than the previous length, update t2 else if (t2.getStart().y - sh2.intersect(t2, height + 1) < 0) { t2.setLength(Mathf.Min(Mathf.Abs(t2.getStart().y - sh2.intersect(t2, height + 1)), t2 .getLength())); t2u = true; } // } } // If the lengths have been updated to a reasonable value, Add // them if (t.getLength() < height) { trapezoidMap.Add(t); } if (t2.getLength() < height) { trapezoidMap.Add(t2); } } } // Remove the borders so they are not displayed shapes.Remove(border); shapes.Remove(border2); return(trapezoidMap); }