Example #1
0
        public void SetEndCondition(CurveEnd end, Vector3d tangent, double param)
        {
            switch (end)
            {
            case CurveEnd.None:
                break;

            case CurveEnd.Start:
                _startTangent = tangent;
                _startParam   = param;
                if (_startModified)
                {
                }
                _startModified = true;
                break;

            case CurveEnd.End:
                _endTangent = tangent;
                _endParam   = param;
                if (_endModified)
                {
                    throw new Exception("SetEndCondition ERROR: Tried to set end condition twice");
                }
                _endModified = true;
                break;

            case CurveEnd.Both:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(end), end, null);
            }
        }
Example #2
0
        public static double GetLengthFromEnd(this Curve curve, double param, CurveEnd end)
        {
            double length = Double.NegativeInfinity;

            switch (end)
            {
            case CurveEnd.None:
                break;

            case CurveEnd.Start:
                length = curve.GetLength(new Interval(curve.Domain.Min, param));
                break;

            case CurveEnd.End:
                length = curve.GetLength(new Interval(param, curve.Domain.Max));
                break;

            case CurveEnd.Both:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(end), end, null);
            }

            return(length);
        }
Example #3
0
        public bool Extend(CurveEnd end, double length)
        {
            Curve c = Centreline.Extend(end, length, CurveExtensionStyle.Smooth);

            Centreline = c;

            return(true);
        }
Example #4
0
        public bool Extend(CurveEnd end, double length, CurveExtensionStyle style = CurveExtensionStyle.Smooth)
        {
            Curve c = Centreline.Extend(end, length, style);

            if (c == null)
            {
                return(false);
            }

            Centreline = c;
            return(true);
        }
Example #5
0
        public void ShortenEnd(CurveEnd end, double length, bool absolute)
        {
            Plane    plane   = Plane.Unset;
            Point3d  origin  = Point3d.Unset;
            Vector3d tangent = Vector3d.Unset;

            switch (end)
            {
            case CurveEnd.None:
                break;

            case CurveEnd.Start:
                tangent = _startTangent;
                origin  = absolute ? Axis.PointAtLength(length) : Axis.PointAt(length);
                break;

            case CurveEnd.End:
                tangent = _endTangent;
                origin  = absolute ? Axis.PointAtLength(Axis.GetLength() - length) : Axis.PointAt(length);
                break;

            case CurveEnd.Both:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(end), end, null);
            }

            plane = new Plane(origin, Vector3d.CrossProduct(tangent, Up), Up);
            plane = new Plane(origin, -tangent);
            if (plane == Plane.Unset)
            {
                return;
            }

            var trimmed = _geometry.Trim(plane, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

            if (trimmed.Length != 1)
            {
                //RhinoDoc.ActiveDoc.Objects.AddBrep(_geometry);
                //RhinoDoc.ActiveDoc.Objects.AddBrep(Brep.CreateTrimmedPlane(plane,
                //    new Rectangle3d(plane, 1, 1).ToNurbsCurve()));
                //_geometry = _volumeGeometry.DuplicateBrep();
            }
            else
            {
                _geometry = trimmed[0];
            }
        }
        /// <summary>
        /// Clamp end knots. Does not modify control point locations.
        /// </summary>
        /// <param name="end">Curve end to clamp.</param>
        /// <returns>true on success, false on failure.</returns>
        public bool ClampEnd(CurveEnd end)
        {
            IntPtr ptr = m_curve.NonConstPointer();
            bool   rc  = true;

            if (CurveEnd.Start == end || CurveEnd.Both == end)
            {
                rc = UnsafeNativeMethods.ON_NurbsCurve_GetBool(ptr, NurbsCurve.idxClampStart);
            }
            if (CurveEnd.End == end || CurveEnd.Both == end)
            {
                rc = rc && UnsafeNativeMethods.ON_NurbsCurve_GetBool(ptr, NurbsCurve.idxClampEnd);
            }
            return(rc);
        }
Example #7
0
        public void SetEndTangent(CurveEnd end, Vector3d tangent)
        {
            switch (end)
            {
            case CurveEnd.None:
                break;

            case CurveEnd.Start:
                _startTangent = tangent;
                break;

            case CurveEnd.End:
                _endTangent = tangent;
                break;

            case CurveEnd.Both:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(end), end, null);
            }
        }
    /// <summary>
    /// Extends a curve to a point.
    /// </summary>
    /// <param name="side">The end of the curve to extend.</param>
    /// <param name="style">The style or type of extension to use.</param>
    /// <param name="endPoint">A new end point.</param>
    /// <returns>New extended curve result on success, null on failure.</returns>
    public Curve Extend(CurveEnd side, CurveExtensionStyle style, Point3d endPoint)
    {
      if (CurveEnd.None == side)
        return null;
      int _side = 0;
      if (CurveEnd.End == side)
        _side = 1;
      else if (CurveEnd.Both == side)
        _side = 2;

      IntPtr pConstPtr = ConstPointer();

      int extendStyle = idxExtendTypeLine;
      if (style == CurveExtensionStyle.Arc)
        extendStyle = idxExtendTypeArc;
      else if (style == CurveExtensionStyle.Smooth)
        extendStyle = idxExtendTypeSmooth;

      IntPtr rc = UnsafeNativeMethods.RHC_RhinoExtendCurve2(pConstPtr, extendStyle, _side, endPoint);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
    /// <summary>
    /// Extends a curve until it intersects a collection of objects.
    /// </summary>
    /// <param name="side">The end of the curve to extend.</param>
    /// <param name="style">The style or type of extension to use.</param>
    /// <param name="geometry">A collection of objects. Allowable object types are Curve, Surface, Brep.</param>
    /// <returns>New extended curve result on success, null on failure.</returns>
    public Curve Extend(CurveEnd side, CurveExtensionStyle style, System.Collections.Generic.IEnumerable<GeometryBase> geometry)
    {
      if (CurveEnd.None == side)
        return null;
      int _side = 0;
      if (CurveEnd.End == side)
        _side = 1;
      else if (CurveEnd.Both == side)
        _side = 2;

      IntPtr pConstPtr = ConstPointer();

      using (SimpleArrayGeometryPointer geometryArray = new SimpleArrayGeometryPointer(geometry))
      {
        IntPtr geometryArrayPtr = geometryArray.ConstPointer();

        int extendStyle = idxExtendTypeLine;
        if (style == CurveExtensionStyle.Arc)
          extendStyle = idxExtendTypeArc;
        else if (style == CurveExtensionStyle.Smooth)
          extendStyle = idxExtendTypeSmooth;

        IntPtr rc = UnsafeNativeMethods.RHC_RhinoExtendCurve1(pConstPtr, extendStyle, _side, geometryArrayPtr);
        return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
      }
    }
Example #10
0
    /// <summary>
    /// Extends a curve by a specific length.
    /// </summary>
    /// <param name="side">Curve end to extend.</param>
    /// <param name="length">Length to add to the curve end.</param>
    /// <param name="style">Extension style.</param>
    /// <returns>A curve with extended ends or null on failure.</returns>
    public Curve Extend(CurveEnd side, double length, CurveExtensionStyle style)
    {
      if (side == CurveEnd.None)
        return DuplicateCurve();

      length = Math.Max(length, 0.0);

      double l0 = length;
      double l1 = length;

      if (side == CurveEnd.End)
        l0 = 0.0;
      if (side == CurveEnd.Start)
        l1 = 0.0;

      IntPtr ptr = ConstPointer();
      IntPtr rc = UnsafeNativeMethods.RHC_RhinoExtendCurve(ptr, l0, l1, (int)style);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
Example #11
0
 /// <summary>
 /// Shortens a curve by a given length
 /// </summary>
 /// <param name="side"></param>
 /// <param name="length"></param>
 /// <returns>Trimmed curve if successful, null on failure.</returns>
 public Curve Trim(CurveEnd side, double length)
 {
   if( length<=0 )
     throw new ArgumentException("length must be > 0", "length");
   double cLength = GetLength();
   if( IsClosed || length >= cLength )
     return null;
   if( side==CurveEnd.Both && length>=2.0*cLength)
     return null;
   
   double t0 = Domain[0];
   double t1 = Domain[1];
   if( side == CurveEnd.Start || side == CurveEnd.Both )
   {
     double s = length / cLength;
     NormalizedLengthParameter(s, out t0);
   }
   if( side == CurveEnd.End || side == CurveEnd.Both )
   {
     double s = (cLength - length) / cLength;
     NormalizedLengthParameter(s, out t1);
   }
   return Trim(t0,t1);
 }
Example #12
0
 public double T(CurveEnd end)
 {
     return((end == CurveEnd.Start) ? Domain.T0 : Domain.T1);
 }
Example #13
0
 /// <summary>
 /// Extends a curve by an Arc until it intersects a collection of objects.
 /// </summary>
 /// <param name="side">The end of the curve to extend.</param>
 /// <param name="geometry">A collection of objects. Allowable object types are Curve, Surface, Brep.</param>
 /// <returns>New extended curve result on success, null on failure.</returns>
 public Curve ExtendByArc(CurveEnd side, System.Collections.Generic.IEnumerable<GeometryBase> geometry)
 {
   return Extend(side, CurveExtensionStyle.Arc, geometry);
 }
Example #14
0
 public Point3d PointAt(CurveEnd end)
 {
     return(Crv.PointAt(T(end)));
 }
Example #15
0
    /// <summary>
    /// Extends a curve on a surface.
    /// </summary>
    /// <param name="side">The end of the curve to extend.</param>
    /// <param name="surface">Surface that contains the curve.</param>
    /// <returns>New extended curve result on success, null on failure.</returns>
    public Curve ExtendOnSurface(CurveEnd side, Surface surface)
    {
      if (surface == null) { throw new ArgumentNullException("surface"); }
      Brep brep = surface.ToBrep();
      if (brep == null) { return null; }

      return ExtendOnSurface(side, brep.Faces[0]);
    }
Example #16
0
    /// <summary>
    /// Extends a curve on a surface.
    /// </summary>
    /// <param name="side">The end of the curve to extend.</param>
    /// <param name="face">BrepFace that contains the curve.</param>
    /// <returns>New extended curve result on success, null on failure.</returns>
    public Curve ExtendOnSurface(CurveEnd side, BrepFace face)
    {
      if (face == null) { throw new ArgumentNullException("face"); }

      if (CurveEnd.None == side)
        return null;
      int _side = 0;
      if (CurveEnd.End == side)
        _side = 1;
      else if (CurveEnd.Both == side)
        _side = 2;

      IntPtr pConstCurve = ConstPointer();
      IntPtr pConstFace = face.ConstPointer();

      IntPtr rc = UnsafeNativeMethods.RHC_RhinoExtendCrvOnSrf(pConstCurve, pConstFace, _side);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
Example #17
0
    /// <summary>
    /// Extends a curve to a point.
    /// </summary>
    /// <param name="side">The end of the curve to extend.</param>
    /// <param name="style">The style or type of extension to use.</param>
    /// <param name="endPoint">A new end point.</param>
    /// <returns>New extended curve result on success, null on failure.</returns>
    public Curve Extend(CurveEnd side, CurveExtensionStyle style, Point3d endPoint)
    {
      if (CurveEnd.None == side)
        return null;
      int _side = 0;
      if (CurveEnd.End == side)
        _side = 1;
      else if (CurveEnd.Both == side)
        _side = 2;

      IntPtr pConstPtr = ConstPointer();

      IntPtr rc = UnsafeNativeMethods.RHC_RhinoExtendCurve2(pConstPtr, ConvertExtensionStyle(style), _side, endPoint);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
Example #18
0
    /// <summary>
    /// Same as SimplifyCurve, but simplifies only the last two segments at "side" end.
    /// </summary>
    /// <param name="end">If CurveEnd.Start the function simplifies the last two start 
    /// side segments, otherwise if CurveEnd.End the last two end side segments are simplified.
    /// </param>
    /// <param name="options">Simplification options.</param>
    /// <param name="distanceTolerance">A distance tolerance for the simplification.</param>
    /// <param name="angleToleranceRadians">An angle tolerance for the simplification.</param>
    /// <returns>New simplified curve on success, null on failure.</returns>
    public Curve SimplifyEnd(CurveEnd end, CurveSimplifyOptions options, double distanceTolerance, double angleToleranceRadians)
    {
      // CurveEnd must be Start or End
      if (end != CurveEnd.Start && end != CurveEnd.End)
        return null;

      int side = 0;//Start
      if (CurveEnd.End == end)
        side = 1; //end
      int _options = SimplifyOptionsToInt(options);
      IntPtr pConstPtr = ConstPointer();
      IntPtr rc = UnsafeNativeMethods.RHC_RhinoSimplifyCurveEnd(pConstPtr, side, _options, distanceTolerance, angleToleranceRadians);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
Example #19
0
 public static CurveEnd _Reverse(this CurveEnd end)
 {
     return(end == CurveEnd.Start ? CurveEnd.End : CurveEnd.Start);
 }