/***************************************************/ public static bool IsEqual(this BHG.Line bhLine, RHG.Line rhLine, double tolerance = BHG.Tolerance.Distance) { if (bhLine == null & rhLine == default(RHG.Line)) { return(true); } return(bhLine.Start.IsEqual(rhLine.PointAt(0), tolerance) && bhLine.End.IsEqual(rhLine.PointAt(1), tolerance)); }
public double ClosestParameter(Point3d testPoint) { int count = Count; if (count < 2) { return(0.0); } int s_min = 0; double t_min = 0.0; double d_min = double.MaxValue; for (int i = 0; i < count - 1; i++) { Line seg = new Line(this[i], this[i + 1]); double d; double t; if (seg.Direction.IsTiny(1e-32)) { t = 0.0; d = this[i].DistanceTo(testPoint); } else { t = seg.ClosestParameter(testPoint); if (t <= 0.0) { t = 0.0; } else if (t > 1.0) { t = 1.0; } d = seg.PointAt(t).DistanceTo(testPoint); } if (d < d_min) { d_min = d; t_min = t; s_min = i; } } return(s_min + t_min); }
private UI.FrixelReferenceData Regenerate() { MassingStructure massing = GenerateMassingStructure(); if (massing == null) { return(null); } var Nodes = massing.Nodes; // Crawl across the point array and crete pixels var nodeList = Nodes.Values.ToList(); List <Pixel> pixelList = new List <Pixel>(); for (int x = 0; x < massing.xBayCount; x++) { for (int y = 0; y < massing.yBayCount; y++) { if (!Nodes.ContainsKey(new Tuple <int, int>(x, y))) { continue; } var currentPoint = Nodes[new Tuple <int, int>(x, y)]; var topLeft = new Tuple <int, int>(x, y + 1); var topRight = new Tuple <int, int>(x + 1, y + 1); var botLeft = new Tuple <int, int>(x, y); var botRight = new Tuple <int, int>(x + 1, y); Core.Geometry.Point2d topLeftPt; Core.Geometry.Point2d topRightPt; Core.Geometry.Point2d botLeftPt; Core.Geometry.Point2d botRightPt; if ( Nodes.TryGetValue(botLeft, out botLeftPt) && Nodes.TryGetValue(topLeft, out topLeftPt) && Nodes.TryGetValue(topRight, out topRightPt) && Nodes.TryGetValue(botRight, out botRightPt) && Utilities.AtLeastXInside(topLeftPt.IsInside, topRightPt.IsInside, botLeftPt.IsInside, botRightPt.IsInside, 2) ) { pixelList.Add(new Pixel( nodeList.IndexOf(topLeftPt), nodeList.IndexOf(topRightPt), nodeList.IndexOf(botLeftPt), nodeList.IndexOf(botRightPt), PixelState.None )); topLeftPt.IsPixeled = true; topRightPt.IsPixeled = true; botLeftPt.IsPixeled = true; botRightPt.IsPixeled = true; } } } // Remove unpixeled nodes and update nodeList var nodeListCopy = nodeList.Where(n => n.IsPixeled).ToList(); foreach (var p in pixelList) { p.UpdateTopology( nodeListCopy.IndexOf(nodeList[p.TopLeft]), nodeListCopy.IndexOf(nodeList[p.TopRight]), nodeListCopy.IndexOf(nodeList[p.BottomLeft]), nodeListCopy.IndexOf(nodeList[p.BottomRight]) ); } nodeList = nodeListCopy; // Find the closest node to the spine line Tuple <double, int> closestPoint = null; var crv = new Rhino.Geometry.Line(_spine.Item1, _spine.Item2).ToNurbsCurve(); int spi = 0; foreach (var p in nodeList.Select(n => new Point3d(n.X, n.Y, 0))) { double dist = double.PositiveInfinity; double t = 0; crv.ClosestPoint(p, out t, 100); var crvPt = crv.PointAt(t); dist = crvPt.DistanceTo(p); // First cycle if (closestPoint == null) { closestPoint = new Tuple <double, int>(dist, spi); spi++; continue; } // If its closer if (!double.IsInfinity(dist) && dist < closestPoint.Item1) { closestPoint = new Tuple <double, int>(dist, spi); } spi++; } var closestNode = nodeList[closestPoint.Item2]; var coord = Nodes.Where(x => x.Value == closestNode).First().Key; // Find orientation of spine curve, vert or horz, to create spine bool xDir = Math.Abs(_spine.Item1.X - _spine.Item2.X) > Math.Abs(_spine.Item1.Y - _spine.Item2.Y); if (xDir) { var horzPts = Nodes.Where(x => x.Key.Item2 == coord.Item2).ToList().Select(x => x.Value).ToList(); List <Core.Geometry.Point2d> newPts = new List <Core.Geometry.Point2d>(); foreach (var pt in horzPts) { var myCoord = nodeList.IndexOf(pt); foreach (var p in pixelList.Where(p => p.ContainsNode(myCoord, true)).ToList()) { p.ChangeStateTo(PixelState.Moment); p.LockedBrace = true; newPts.Add(nodeList[p.BottomLeft]); newPts.Add(nodeList[p.TopLeft]); } } horzPts.AddRange(newPts); // Lock support points (LEFT) var horzPtsMin = horzPts.Select(p => p.X).Min(); nodeList.Where(p => p.X.IsCloseTo(horzPtsMin)).ToList().ForEach(p => p.IsLocked = true); } else { var vertPts = Nodes.Where(x => x.Key.Item1 == coord.Item1).ToList().Select(x => x.Value).ToList(); List <Core.Geometry.Point2d> newPts = new List <Core.Geometry.Point2d>(); foreach (var pt in vertPts) { var myCoord = nodeList.IndexOf(pt); foreach (var p in pixelList.Where(p => p.ContainsNode(myCoord, true)).ToList()) { p.ChangeStateTo(PixelState.Moment); newPts.Add(nodeList[p.BottomLeft]); newPts.Add(nodeList[p.BottomRight]); } } vertPts.AddRange(newPts); // Lock support points (BOTTOM) var vertPtsMin = vertPts.Select(p => p.Y).Min(); vertPts.Where(p => p.Y.IsCloseTo(vertPtsMin)).ToList().ForEach(p => p.IsLocked = true); pixelList.ForEach(p => { if (nodeList[p.BottomLeft].Y.IsCloseTo(vertPtsMin)) { nodeList[p.BottomLeft].IsLocked = true; } if (nodeList[p.BottomRight].Y.IsCloseTo(vertPtsMin)) { nodeList[p.BottomRight].IsLocked = true; } }); } foreach (var p in pixelList.Where(p => p.ContainsNode(spi)).ToList()) { p.ChangeStateTo(PixelState.Moment); } // Create the pixel structure var pixelStruct = new Core.PixelStructure(nodeList, pixelList); // Return the data return(new UI.FrixelReferenceData(pixelStruct, massing)); }