/// <summary> 检查X序列的值的单调性 </summary> /// <param name="xValues"></param> private static CurveShape CheckXTrend(double[] xValues) { CurveShape cs = CurveShape.XAscend; bool ascend = (xValues[1].CompareTo(xValues[0]) > 0); if (ascend) { cs = CurveShape.XAscend; for (int i = 2; i < xValues.Length; i++) { // 当相邻的两个个值相等时,认为不妨碍其原来的单调性 if (xValues[i] - xValues[i - 1] < 0) { return(CurveShape.XNonMonotonic); } } } else { cs = CurveShape.XDescend; for (int i = 2; i < xValues.Length; i++) { if (xValues[i] - xValues[i - 1] > 0) { return(CurveShape.XNonMonotonic); } } } return(cs); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Point3d> cp = new List <Point3d>(); DA.GetDataList(0, cp); bool closed = false; DA.GetData(1, ref closed); double tension = 0; DA.GetData(2, ref tension); Pen outline = null; DA.GetData(3, ref outline); Pen fill = null; DA.GetData(4, ref fill); Shape2D shape = new CurveShape(cp, closed, (float)tension); if (outline != null) { shape.outline(outline); } if (fill != null) { shape.fill(fill); } DA.SetData(0, shape); }
public static float Sample(this CurveShape shape, float alpha, float a = 0.0f, float b = 0.0f) { switch (shape) { default: case CurveShape.Linear: return(alpha); case CurveShape.Cosine: {
/// <summary> 考虑X坐标的分布,根据所占X轴的区间的分段数来进行缩减,缩减后的数组中的元素个数不大于 <paramref name="segments" />+1。 </summary> /// <param name="segments"> 将整条曲线所占的X轴区间分割为 segments 段,所以其值至少为1,且无上限。 </param> /// <remarks> /// 此收缩方法适用于数据对象随X轴增加的变化不大的情况。 /// 比如基坑监测中每一天的位移。 /// </remarks> public ShrinkResult ShrinkByXAxis(int segments) { if (segments > 0) { CurveShape trend = CheckXTrend(_xValues); if (trend == CurveShape.XAscend) { return(ShrinkByAscendXAxis(segments)); } else if (trend == CurveShape.XDescend) { // 先将源曲线的X、Y序列反过来 var originalX = _xValues; try { // 先将源曲线的X、Y序列反过来 _xValues = originalX.Reverse().ToArray(); // Result = ShrinkByAscendXAxis(segments); } finally { // 最后务必将源XY序列复原 _xValues = originalX; // 也要将结果再反过来 FilteredIds = FilteredIds.Select(r => Length - 1 - r).ToArray(); } } else { ErrorMessage = @"X序列非单调。"; Result = ShrinkResult.XNonMonotonic; } } else { ErrorMessage = @"指定的分段数至少为1,且小于 总点数-1。"; Result = ShrinkResult.NotStarted; } return(Result); }
public static float Sample(this CurveShape shape, float alpha, float a = 0.0f, float b = 0.0f) { switch (shape) { default: case CurveShape.Linear: return(alpha); case CurveShape.Cosine: { // TODO(local): "strengthen" the curve based on `a` and `b` float angle = alpha * MathL.Pi; return((1 - (float)Math.Cos(angle)) * 0.5f); } case CurveShape.ThreePoint: { float t = (a - MathL.Sqrt(a * a + alpha - 2 * a * alpha)) / (-1 + 2 * a); return(2 * (1 - t) * t * b + t * t); } } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { graphicsProcessor.MouseUpEvent(); switch (ToggleSelection) { case 0: { if (this.RectPoint1 != this.RectPoint2) { ITransformable item; if (IsRectOrEll) { item = new RectangleShape(new Size(Math.Max(RectPoint1.X, RectPoint2.X) - Math.Min(RectPoint1.X, RectPoint2.X), Math.Max(RectPoint1.Y, RectPoint2.Y) - Math.Min(RectPoint1.Y, RectPoint2.Y)), new Point(Math.Min(RectPoint1.X, RectPoint2.X), Math.Min(RectPoint1.Y, RectPoint2.Y)), Color.Transparent, colorDialog1.Color, 200, "Rectangle Shape"); Items.Add(item); ToggleSelection = 1; } else { item = new EllipseShape(new Size(Math.Max(RectPoint1.X, RectPoint2.X) - Math.Min(RectPoint1.X, RectPoint2.X), Math.Max(RectPoint1.Y, RectPoint2.Y) - Math.Min(RectPoint1.Y, RectPoint2.Y)), new Point(Math.Min(RectPoint1.X, RectPoint2.X), Math.Min(RectPoint1.Y, RectPoint2.Y)), Color.Transparent, colorDialog1.Color, 200, "Ellipse Shape"); Items.Add(item); ToggleSelection = 1; } this.GetRectPoints(e.X, e.Y); SelectedItem = (IDrawable)item; graphicsProcessor.SelectedItem = (ITransformable)SelectedItem; this.CustomRefresh(); } break; } case 5: { LineShape item = new LineShape(Points[0], new Point(e.X + 1, e.Y + 1), colorDialog1.Color, 255, "Line Shape"); Items.Add(item); Points.Clear(); ToggleSelection = 1; SelectedItem = item; graphicsProcessor.SelectedItem = (ITransformable)SelectedItem; this.CustomRefresh(); break; } case 6: { SelectedItem = null; break; } case 7: { ITransformable item; if (Points.Count > 1) { item = new CurveShape(new List <Point>(Points), colorDialog1.Color, 255, "Curve Shape"); Items.Add(item); ToggleSelection = 1; SelectedItem = (IDrawable)item; graphicsProcessor.SelectedItem = (ITransformable)SelectedItem; } Points.Clear(); this.CustomRefresh(); break; } } HelpSelectedItem = null; this.CustomRefresh(); }
public Point(time_t pos, float alpha, CurveShape shape) { Position = pos; Alpha = alpha; Shape = shape; }