static void CalculateIdealPositionsForLongestSegs(Path path, PointProjection projectionToPerp) { LongestNudgedSegment currentLongSeg = null; LongestNudgedSegment ret = null; double prevOffset = projectionToPerp(path.Start); foreach (var edge in path.PathEdges) { if (edge.LongestNudgedSegment != null) { currentLongSeg = edge.LongestNudgedSegment; if (ret != null) { double t; SetIdealPositionForSeg(ret, t = projectionToPerp(ret.Start), prevOffset, projectionToPerp(currentLongSeg.Start)); prevOffset = t; ret = null; } } else if (currentLongSeg != null) { ret = currentLongSeg; currentLongSeg = null; } } if (ret != null) { SetIdealPositionForSeg(ret, projectionToPerp(ret.Start), prevOffset, projectionToPerp(path.End)); } else if (currentLongSeg != null) { currentLongSeg.IdealPosition = projectionToPerp(currentLongSeg.Start); } }
public static bool PointIsWithinSegmentExtentsHeightInclusive_On_Ends(double yPtN) { IPathSegment segment = new LineSegment( new CartesianCoordinate(1, 2), new CartesianCoordinate(15, 5)); return(PointProjection.PointIsWithinSegmentExtentsHeightInclusive(yPtN, segment)); }
[TestCase(2.1, ExpectedResult = 2)] // Top of segment public static double IntersectionPointY_Horizontal(double xPtN) { IPathSegment segment = new LineSegment( new CartesianCoordinate(2, 2), new CartesianCoordinate(3, 2)); return(PointProjection.IntersectionPointY(xPtN, segment)); }
public static void IntersectionPointY_Vertical_Returns_Infinity() { IPathSegment segment = new LineSegment( new CartesianCoordinate(2, 2), new CartesianCoordinate(2, 4)); Assert.IsTrue(double.IsInfinity(PointProjection.IntersectionPointY(2, segment))); }
public static bool PointIsLeftOfSegmentIntersection_Outside_Segment(double xPtN, double xIntersection) { IPathSegment segment = new LineSegment( new CartesianCoordinate(-1, 1), new CartesianCoordinate(1, 2)); return(PointProjection.PointIsLeftOfSegmentIntersection(xPtN, xIntersection, segment)); }
[TestCase(2.1, ExpectedResult = 2)] // Right of segment public static double IntersectionPointX_Vertical(double yPtN) { IPathSegment segment = new LineSegment( new CartesianCoordinate(2, 2), new CartesianCoordinate(2, 3)); return(PointProjection.IntersectionPointX(yPtN, segment)); }
public static bool PointIsBelowSegmentExtentsBottomExclusive_On_Ends(double yPtN) { IPathSegment segment = new LineSegment( new CartesianCoordinate(1, 2), new CartesianCoordinate(15, 5)); return(PointProjection.PointIsBelowSegmentExtentsExclusive(yPtN, segment)); }
public static bool PointIsBelowSegmentExtentsBottom_SlopedLine(double yPtN, double yBottomEnd, double yTopEnd) { IPathSegment segment = new LineSegment( new CartesianCoordinate(10, yBottomEnd), new CartesianCoordinate(20, yTopEnd)); return(PointProjection.PointIsBelowSegmentExtentsInclusive(yPtN, segment)); }
public static bool PointIsLeftOfSegmentExtentsEndExclusive_On_Ends(double xPtN) { IPathSegment segment = new LineSegment( new CartesianCoordinate(1, 2), new CartesianCoordinate(15, 5)); return(PointProjection.PointIsLeftOfSegmentExtentsEndExclusive(xPtN, segment)); }
public static bool PointIsLeftOfSegmentExtentsEnd_SlopedLine(double xPtN, double xLeftEnd, double xRightEnd) { IPathSegment segment = new LineSegment( new CartesianCoordinate(xLeftEnd, 10), new CartesianCoordinate(xRightEnd, 20)); return(PointProjection.PointIsLeftOfSegmentExtentsEndInclusive(xPtN, segment)); }
public static bool PointIsWithinSegmentExtentsWidth_Sloped(double xPtN, double xLeftEnd, double xRightEnd) { IPathSegment segment = new LineSegment( new CartesianCoordinate(xLeftEnd, 1), new CartesianCoordinate(xRightEnd, 15)); return(PointProjection.PointIsWithinSegmentExtentsWidthInclusive(xPtN, segment)); }
public static bool PointIsBelowSegmentIntersection_Outside_Segment(double yPtN, double yIntersection) { IPathSegment segment = new LineSegment( new CartesianCoordinate(1, -1), new CartesianCoordinate(2, 1)); return(PointProjection.PointIsBelowSegmentIntersection(yPtN, yIntersection, segment)); }
public static bool PointIsWithinSegmentExtentsHeight_SlopedLine(double yPtN, double yLeftEnd, double yRightEnd) { IPathSegment segment = new LineSegment( new CartesianCoordinate(1, yLeftEnd), new CartesianCoordinate(15, yRightEnd)); return(PointProjection.PointIsWithinSegmentExtentsHeightInclusive(yPtN, segment)); }
static void UpdateMinMaxWithPoint(ref double min, ref double max, PointProjection projectionToDir, Point point) { double p = projectionToDir(point); if (min > p) { min = p; } if (max < p) { max = p; } }
/// <summary> /// /// </summary> /// <param name="direction"></param> /// <param name="obstacles"></param> /// <param name="axisEdgesToObstaclesTheyOriginatedFrom"></param> /// <param name="pathOrders"></param> /// <param name="axisEdges">edges to find the empty space around</param> internal FreeSpaceFinder(Directions direction, IEnumerable <Polyline> obstacles, Dictionary <AxisEdge, Polyline> axisEdgesToObstaclesTheyOriginatedFrom, Dictionary <AxisEdge, List <PathEdge> > pathOrders, IEnumerable <AxisEdge> axisEdges) : base(obstacles, new CompassVector(direction).ToPoint()) { DirectionPerp = new CompassVector(direction).Right.ToPoint(); PathOrders = pathOrders; xProjection = direction == Directions.North ? (PointProjection)X : MinusY; #if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=301 edgeContainersTree = new RbTree <AxisEdgesContainer>(new FreeSpaceFinderComparer(this)); #else edgeContainersTree = new RbTree <AxisEdgesContainer>(this); #endif SweepPole = CompassVector.VectorDirection(SweepDirection); Debug.Assert(CompassVector.IsPureDirection(SweepPole)); AxisEdges = axisEdges; AxisEdgesToObstaclesTheyOriginatedFrom = axisEdgesToObstaclesTheyOriginatedFrom; }
public PointByDelegateComparer(PointProjection projection) { this.projection = projection; }
void CreateLongestNudgedSegmentsForPath(Path path, PointProjection projectionToPerp) { //ShowEdgesOfEdgePath(path); GoOverPathAndCreateLongSegs(path); CalculateIdealPositionsForLongestSegs(path, projectionToPerp); }
/// <summary> /// refine vertices belonging to a bucket; /// pathLinkedVertices belong to a line parallel to the direction of the refinement /// </summary> /// <param name="pathLinkedVertices"></param> /// <param name="projectionToDirection"></param> static void RefineCollinearBucket( IEnumerable<LinkedPoint> pathLinkedVertices, PointProjection projectionToDirection) { var dict = new SortedDictionary<Point, int>(new PointByDelegateComparer(projectionToDirection)); foreach (var pathLinkedPoint in pathLinkedVertices) { if (!dict.ContainsKey(pathLinkedPoint.Point)) dict[pathLinkedPoint.Point] = 0; if (!dict.ContainsKey(pathLinkedPoint.Next.Point)) dict[pathLinkedPoint.Next.Point] = 0; } var arrayOfPoints = new Point[dict.Count]; int i = 0; foreach (var point in dict.Keys) arrayOfPoints[i++] = point; for (i = 0; i < arrayOfPoints.Length; i++) dict[arrayOfPoints[i]] = i; foreach (var pathLinkedVertex in pathLinkedVertices) { i = dict[pathLinkedVertex.Point]; int j = dict[pathLinkedVertex.Next.Point]; if (Math.Abs(j - i) > 1) InsertPoints(pathLinkedVertex, arrayOfPoints, i, j); } }
static IEnumerable<LinkedPoint> GetAllLinkedVertsInDirection( PointProjection projectionToPerp, IEnumerable<LinkedPoint> initialVerts) { foreach (var vert in initialVerts) for (var v = vert; v.Next != null; v = v.Next) if ( ApproximateComparer.Close(projectionToPerp(v.Point),projectionToPerp(v.Next.Point))) yield return v; }
static void GetProjectionsDelegates(Directions direction, out PointProjection projectionToPerp, out PointProjection projectionToDirection) { if (direction == Directions.East) { projectionToDirection = delegate(Point p) { return p.X; }; projectionToPerp = delegate(Point p) { return p.Y; }; } else { projectionToPerp = delegate(Point p) { return p.X; }; projectionToDirection = delegate(Point p) { return p.Y; }; } }
static void CalculateIdealPositionsForLongestSegs(Path path, PointProjection projectionToPerp) { LongestNudgedSegment currentLongSeg = null; LongestNudgedSegment ret = null; double prevOffset = projectionToPerp(path.Start); foreach (var edge in path.PathEdges) { if (edge.LongestNudgedSegment != null) { currentLongSeg = edge.LongestNudgedSegment; if (ret != null) { double t; SetIdealPositionForSeg(ret, t = projectionToPerp(ret.Start), prevOffset, projectionToPerp(currentLongSeg.Start)); prevOffset = t; ret = null; } } else if (currentLongSeg != null) { ret = currentLongSeg; currentLongSeg = null; } } if (ret != null) SetIdealPositionForSeg(ret, projectionToPerp(ret.Start), prevOffset, projectionToPerp(path.End)); else if (currentLongSeg != null) currentLongSeg.IdealPosition = projectionToPerp(currentLongSeg.Start); }
static void UpdateMinMaxWithPoint(ref double min, ref double max, PointProjection projectionToDir, Point point) { double p = projectionToDir(point); if (min > p) min = p; if (max < p) max = p; }