private bool IsPolylineRectangle() { if (this.PaddedPolyline.PolylinePoints.Count() != 4) { return(false); } var ppt = this.PaddedPolyline.StartPoint; var nextPpt = ppt.NextOnPolyline; var dir = CompassVector.DirectionsFromPointToPoint(ppt.Point, nextPpt.Point); if (!CompassVector.IsPureDirection(dir)) { return(false); } do { ppt = nextPpt; nextPpt = ppt.NextOnPolyline; var nextDir = CompassVector.DirectionsFromPointToPoint(ppt.Point, nextPpt.Point); // We know the polyline is clockwise. if (nextDir != CompassVector.RotateRight(dir)) { return(false); } dir = nextDir; } while (ppt != this.PaddedPolyline.StartPoint); return(true); }
private void AddGroupIntersectionsToRestrictedRay(Obstacle obstacle, IList <IntersectionInfo> intersections) { // We'll let the lines punch through any intersections with groups, but track the location so we can enable/disable crossing. foreach (var intersectionInfo in intersections) { var intersect = SpliceUtility.RawIntersection(intersectionInfo, currentRestrictedRay.Start); // Skip intersections that are past the end of the restricted segment (though there may still be some // there if we shorten it later, but we'll skip them later). var distSquared = (intersect - currentRestrictedRay.Start).LengthSquared; if (distSquared > restrictedRayLengthSquared) { continue; } var dirTowardIntersect = PointComparer.GetPureDirection(currentRestrictedRay.Start, currentRestrictedRay.End); var polyline = (Polyline)intersectionInfo.Segment1; // this is the second arg to GetAllIntersections var dirsOfSide = CompassVector.VectorDirection(polyline.Derivative(intersectionInfo.Par1)); // The derivative is always clockwise, so if the side contains the rightward rotation of the // direction from the ray origin, then we're hitting it from the inside; otherwise from the outside. var dirToInsideOfGroup = dirTowardIntersect; if (0 != (dirsOfSide & CompassVector.RotateRight(dirTowardIntersect))) { dirToInsideOfGroup = CompassVector.OppositeDir(dirToInsideOfGroup); } CurrentGroupBoundaryCrossingMap.AddIntersection(intersect, obstacle, dirToInsideOfGroup); } }
void DevTrace_VerifyVertex(VisibilityVertex vertex) { if (transGraphVerify.IsLevel(1)) { Directions dir = Directions.North; for (int idir = 0; idir < 4; ++idir, dir = CompassVector.RotateRight(dir)) { int count = 0; int cEdges = vertex.InEdges.Count; // indexing is faster than foreach for Lists for (int ii = 0; ii < cEdges; ++ii) { var edge = vertex.InEdges[ii]; if (PointComparer.GetPureDirection(vertex.Point, edge.SourcePoint) == dir) { ++count; } } // Avoid GetEnumerator overhead. var outEdgeNode = vertex.OutEdges.IsEmpty() ? null : vertex.OutEdges.TreeMinimum(); for (; outEdgeNode != null; outEdgeNode = vertex.OutEdges.Next(outEdgeNode)) { var edge = outEdgeNode.Item; if (PointComparer.GetPureDirection(vertex.Point, edge.TargetPoint) == dir) { ++count; } } Debug.Assert(count < 2, "vertex has multiple edges in one direction"); } } }
private bool SeeIfSpliceIsStillOverlapped(Directions extendDir, VisibilityVertex nextExtendVertex) { // If we've spliced out of overlapped space into free space, we may be able to turn off the // overlapped state if we have a perpendicular non-overlapped edge. var edge = this.FindNextEdge(nextExtendVertex, CompassVector.RotateLeft(extendDir)); var maybeFreeSpace = (null == edge) ? false : (ScanSegment.NormalWeight == edge.Weight); if (!maybeFreeSpace) { edge = this.FindNextEdge(nextExtendVertex, CompassVector.RotateRight(extendDir)); maybeFreeSpace = (null == edge) ? false : (ScanSegment.NormalWeight == edge.Weight); } return(!maybeFreeSpace || this.ObstacleTree.PointIsInsideAnObstacle(nextExtendVertex.Point, extendDir)); }