private void DetalizeChunkInternal(ref List <IMSPoint> points, Point point1, Point point2, Normal n1, Normal n2) { //Workaround to prevent StackOverflowed exception if (DCIStackCounter > stackSize) { return; } DCIStackCounter++; var n = n1.Combine(n2); var middlePoint = n1.Segment().GetCurvePoint(n.T()); var mspoint = finder.FindMSPoint(middlePoint, n); if (mspoint == null) { DCIStackCounter--; return; } if (DetailRequired(point1, mspoint.GetPoint(), n1, n)) { DetalizeChunkInternal(ref points, point1, mspoint.GetPoint(), n1, n); } points.Add(mspoint); if (DetailRequired(mspoint.GetPoint(), point2, n, n2)) { DetalizeChunkInternal(ref points, mspoint.GetPoint(), point2, n, n2); } DCIStackCounter--; }
private void ShowNormal_Click(object sender, RoutedEventArgs e) { if (model == null) { MessageBox.Show("No model is imported"); return; } string[] debugParams = textBox_Debug.Text.Split(';'); int segmentNum = 0; double t = 0; double multiplier = 0; try { segmentNum = int.Parse(debugParams[0]); t = double.Parse(debugParams[1], CultureInfo.InvariantCulture); multiplier = double.Parse(debugParams[2], CultureInfo.InvariantCulture); } catch { MessageBox.Show("Wrong format in debug parameters.\nFormat is:\n <segment number>;<t value>;<multiplier value>"); return; } ISegment chosenSegment = model.GetCanvasData().ElementAt(segmentNum); Point pointOnSegment = chosenSegment.GetCurvePoint(t); Normal normalForSegment = chosenSegment.GetNormal(t); if (t == 0) { int prevSegmentNum = segmentNum == 0 ? model.GetCanvasData().Count() - 1 : segmentNum - 1; normalForSegment = normalForSegment.Combine(model.GetCanvasData().ElementAt(prevSegmentNum).GetNormal(1)); } else if (t == 1) { int nextSegmentNum = segmentNum == model.GetCanvasData().Count() - 1 ? 0 : segmentNum + 1; normalForSegment = model.GetCanvasData().ElementAt(nextSegmentNum).GetNormal(0).Combine(normalForSegment); } ISegment normalSegment = new Segment(new BezierCurve(), new List <Point>() { pointOnSegment, new Point(pointOnSegment.X + multiplier * normalForSegment.Dx(), pointOnSegment.Y + multiplier * normalForSegment.Dy()) }); View.VisibleDataSettings settings = new View.VisibleDataSettings(); settings.Brush = Brushes.Blue; settings.Thikness = 1; IMidSurface debugSurface = new MidSurface(); debugSurface.Add(normalSegment); View.VisibleData visible_data = new View.VisibleData(debugSurface, settings); view.Paint(visible_data); }
private void DetalizeChunk(ref List <IMSPoint> points, Point point1, Point point2, Normal n1, Normal n2, double angle1, double angle2) { bool n2IsBisector = n2.T() == 0; bool n1ISBisrctor = n1.T() == 0; if (n2IsBisector) { n2 = new Normal(n1.Segment(), 1, n2.Dx(), n2.Dy()); } if (n1ISBisrctor && angle1 < 0 && n2IsBisector && angle2 < 0) { var newN1 = n1.Segment().GetNormal(0); var newN2 = n1.Segment().GetNormal(1); var middlePoint1 = n1.Segment().GetCurvePoint(newN1.T()); var mspoint1 = finder.FindMSPoint(middlePoint1, newN1); var middlePoint2 = n1.Segment().GetCurvePoint(newN2.T()); var mspoint2 = finder.FindMSPoint(middlePoint2, newN2); if (mspoint1 == null || mspoint2 == null) { return; } if (DetailRequired(point1, mspoint1.GetPoint(), n1, newN1)) { DetalizeChunkInternal(ref points, point1, mspoint1.GetPoint(), n1, newN1); } points.Add(mspoint1); if (DetailRequired(mspoint1.GetPoint(), mspoint2.GetPoint(), newN1, newN2)) { DetalizeChunkInternal(ref points, mspoint1.GetPoint(), mspoint2.GetPoint(), newN1, newN2); } points.Add(mspoint2); if (DetailRequired(mspoint2.GetPoint(), point2, newN2, n2)) { DetalizeChunkInternal(ref points, mspoint2.GetPoint(), point2, newN2, n2); } } else { Normal n = null; if (n2IsBisector && angle2 < 0) { n = n1.Segment().GetNormal(1); } else if (n1ISBisrctor && angle1 < 0) { n = n1.Segment().GetNormal(0); } else { n = n1.Combine(n2); } var middlePoint = n1.Segment().GetCurvePoint(n.T()); var mspoint = finder.FindMSPoint(middlePoint, n); if (mspoint == null) { return; } if (DetailRequired(point1, mspoint.GetPoint(), n1, n)) { DetalizeChunkInternal(ref points, point1, mspoint.GetPoint(), n1, n); } points.Add(mspoint); if (DetailRequired(mspoint.GetPoint(), point2, n, n2)) { DetalizeChunkInternal(ref points, mspoint.GetPoint(), point2, n, n2); } } }