Class GeneralCurve
- Namespace
- CADability.GeoObject
- Assembly
- CADability.dll
A base implementation of ICurve
public abstract class GeneralCurve : IGeoObjectImpl, ISerializable, IFeedBack, ICloneable, IColorDef, ICurve, IGeoObject, ILayer, IStyle, IOctTreeInsertable, IComparable, ILineWidth, ILinePattern
- Inheritance
-
GeneralCurve
- Implements
- Derived
- Inherited Members
Constructors
GeneralCurve()
protected GeneralCurve()
GeneralCurve(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected GeneralCurve(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
Constructor
public static GeneralCurve.ConstructionDelegate Constructor
Field Value
Properties
ColorDef
Sets and gets the color of the object
public ColorDef ColorDef { get; set; }
Property Value
Description
Returns a textual description of the GeoObject. Mainly used for debugging purposes
public override string Description { get; }
Property Value
EndDirection
The direction of the curve at the endpoint. If the curve is closed, this is the direction where the parameter is 1.0.
public virtual GeoVector EndDirection { get; }
Property Value
EndPoint
The endpoint of the curve. If the curve is closed, this is the point where the parameter is 1.0.
public virtual GeoPoint EndPoint { get; set; }
Property Value
IsClosed
Determines, whether the curve is closed or open.
public virtual bool IsClosed { get; }
Property Value
IsComposed
public virtual bool IsComposed { get; }
Property Value
IsSingular
Determines, whether this curve is singular, i.e. it is only a point, returns the same value for each parameter
public virtual bool IsSingular { get; }
Property Value
Length
The arc length of the curve, from its points. Derived classes, which know a closed form or the derivative, should override this. The length used to be estimated from the tetrahedron hull, which is up to several tenths of a percent too short.
public virtual double Length { get; }
Property Value
LinePattern
The line pattern of the object, or null when none is set. For GeoObjects setting it raises the change events and is undoable.
public LinePattern LinePattern { get; set; }
Property Value
LineWidth
The line width of the object, or null when none is set. For GeoObjects setting it raises the change events and is undoable.
public LineWidth LineWidth { get; set; }
Property Value
StartDirection
The direction of the curve at the start-point. If the curve is closed, this is the direction where the parameter is 0.0.
public virtual GeoVector StartDirection { get; }
Property Value
StartPoint
The start-point of the curve. If the curve is closed, this is the point where the parameter is 0.0.
public virtual GeoPoint StartPoint { get; set; }
Property Value
SubCurves
public virtual ICurve[] SubCurves { get; }
Property Value
- ICurve[]
Methods
Approximate(bool, double)
public virtual ICurve Approximate(bool linesOnly, double maxError)
Parameters
Returns
- ICurve
The Approximation
CloneModified(ModOp)
Returns a modified copy of this curve
public virtual ICurve CloneModified(ModOp m)
Parameters
mModOpmodification
Returns
- ICurve
modified copy
DirectionAt(double)
Returns the direction of the curve at a specified point. The parameter position of the start-point is 0.0, the parameter position of the endpoint is 1.0. Directions of a position outside this interval may be undefined.
public abstract GeoVector DirectionAt(double Position)
Parameters
PositiondoublePosition on the curve
Returns
- GeoVector
The requested direction
DistanceTo(GeoPoint)
Returns the minimal distance of point p to the curve.
public virtual double DistanceTo(GeoPoint p)
Parameters
pGeoPoint
Returns
GetBasePoints()
protected abstract double[] GetBasePoints()
Returns
- double[]
GetBoundingCube()
Returns a bounding cube of the object. The object must fir into this cube. There may be a smaller cube that contains the object if it is to expensive to calculate the exact cube.
public override BoundingCube GetBoundingCube()
Returns
- BoundingCube
the bounding cube
GetExtent(Projection, ExtentPrecision)
Returns the 2d extent of the object as it appears in the given projection, in the coordinates of the projection's plane (not in pixels).
public override BoundingRect GetExtent(Projection projection, ExtentPrecision extentPrecision)
Parameters
projectionProjectionthe projection
extentPrecisionExtentPrecisionExact for the exact extent, Raw for a quick estimate that may be larger
Returns
- BoundingRect
the extent in the projection's 2d coordinates
GetExtent(double)
Gets the 3-dimensional extent of an object
public override BoundingCube GetExtent(double precision)
Parameters
precisiondoublePrecision of the test
Returns
- BoundingCube
The minmax cube
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetPlanarState()
Determins the state of the curve in space. A curve may be either Planar (e.g. a cicle), NonPlanar (e.g. a polyline with vertices that dont shear a common plane) or UnderDetermined (e.g. a line defines a sheaf of planes (Ebenenbüschel))
public virtual PlanarState GetPlanarState()
Returns
GetPlane()
Determins the plane in which the curve resides. Throws CurveException if the curve's PlanarState is NonPlanar or UnderDetermined.
public virtual Plane GetPlane()
Returns
- Plane
The plane
GetProjectedCurve(Plane)
Orthogonally projects this curve into the given plane. Returns the 2D curve in the coordinate system of the given plane.
public virtual ICurve2D GetProjectedCurve(Plane p)
Parameters
pPlaneThe plane this curve will be projected on
Returns
- ICurve2D
The 2D curve in the given plane
GetQuadTreeItem(Projection, ExtentPrecision)
Returns an item for a 2d quad tree of the projected objects, used for hit tests in a projection: it knows the 2d extent of the object, whether a 2d rectangle hits it, and the depth (z position) of the object at a 2d point. Composite objects (blocks, solids, paths) return a collection of the items of their parts.
public override IQuadTreeInsertableZ GetQuadTreeItem(Projection projection, ExtentPrecision extentPrecision)
Parameters
projectionProjectionthe projection
extentPrecisionExtentPrecisionprecision of the extent, see GetExtent(Projection, ExtentPrecision)
Returns
- IQuadTreeInsertableZ
the item for the quad tree
GetSelfIntersections()
Returns the self intersection position of this curve. The returned array contains pairs of parameter values. Each intersectionpoint corresponds to two parameters.
public virtual double[] GetSelfIntersections()
Returns
- double[]
Parameters of the intersection points
GetShowProperties(IFrame)
Should be overridden and return a IPropertyEntry derived object that handles the display and modification of the properties of the IGeoObject derived object. Default implementation return null.
public override IPropertyEntry GetShowProperties(IFrame Frame)
Parameters
FrameIFrame
Returns
HitTest(ref BoundingCube, double)
Tests whether an object is touched by the provided cube
public override bool HitTest(ref BoundingCube cube, double precision)
Parameters
cubeBoundingCubeTo test with
precisiondoubleRequired precision
Returns
- bool
true if the object strikes the cube
HitTest(Projection, BoundingRect, bool)
Tests whether an object is inside or touched by the rectangle when projected with the provided projection
public override bool HitTest(Projection projection, BoundingRect rect, bool onlyInside)
Parameters
projectionProjectionThe projection for the test
rectBoundingRectThe rectangle to test the position
onlyInsidebooltrue: the object must be totaly inside the rectangle, false: the object must be totaly or partially inside the rectangle
Returns
- bool
true when the test succeedes, false otherwise
HitTest(PickArea, bool)
Tests whether an object is inside or touched by the provided area
public override bool HitTest(Projection.PickArea area, bool onlyInside)
Parameters
areaProjection.PickAreaThe area to check for
onlyInsidebooltrue: the object must be totaly inside the area, false: the object must be totaly or partially inside the area
Returns
- bool
true when the test succeedes, false otherwise
InvalidateSecondaryData()
protected virtual void InvalidateSecondaryData()
IsInPlane(Plane)
Determines whether the curve resides in the given plane.
public virtual bool IsInPlane(Plane p)
Parameters
pPlaneThe plane for the test
Returns
- bool
true, when the curve resides in the plane
MakeTetraederHull()
protected void MakeTetraederHull()
PaintTo3D(IPaintTo3D)
Paints the object with the methods of paintTo3D: lines, triangles, text... The views implement
IPaintTo3D (with OpenGL or GDI) and collect what the object paints in a display list, so this is
called rarely, after PrepareDisplayList(double) has done the expensive work (triangulation, approximation).
public override void PaintTo3D(IPaintTo3D paintTo3D)
Parameters
paintTo3DIPaintTo3Dwhere to paint
ParameterToPosition(double)
convert the parameter, which is in a natural system (0..2*pi for circle, first knot to last knot for bspline) to the 0..1 normalized position
public virtual double ParameterToPosition(double parameter)
Parameters
parameterdouble
Returns
- double
the position, 0..1 when inside the bounds
PointAndDerivativesAt(ICurve, double, int)
Helper for calculating higher derivatives of any curve: the point and the first two derivatives come from TryPointDeriv2At(double, out GeoPoint, out GeoVector, out GeoVector) (or DirectionAt(double)), higher derivatives are computed numerically. Curves which know their higher derivatives should implement them on their own.
public static IReadOnlyList<GeoVector> PointAndDerivativesAt(ICurve curve, double position, int grad)
Parameters
curveICurveThe curve
positiondoubleWhere to calculate the derivatives
gradintNumber of derivatives
Returns
- IReadOnlyList<GeoVector>
element 0 is the point (as a vector), element i is the i-th derivative
PointAndDerivativesAt(double, int)
Returns all derivatives up to grad. The first vector is actually the point at this position.
public virtual IReadOnlyList<GeoVector> PointAndDerivativesAt(double position, int grad)
Parameters
positiondoubleWhere to calculate the derivatives
gradintNumber of derivatives. grad==2 returns the point, the first and the second derivative
Returns
- IReadOnlyList<GeoVector>
Sequence of derivatives: element 0 = point-vector (P), 1 = first derivative (P'), 2 = second (P''), … . Length ≥ grad+1.
PointAt(double)
Returns the point of the given position. The parameter position of the start-point is 0.0, the parameter position of the endpoint is 1.0. Points of a position outside this interval may be undefined. The correlation between the parameter Position and the resulting point may be not linear.
public abstract GeoPoint PointAt(double Position)
Parameters
PositiondoublePosition on the curve
Returns
- GeoPoint
The requested point
Position(GeoPoint, GeoVector, double)
Returns the smallest parameter value (l) where the provided line hits the object so that the point
fromHere + l * direction is on or close to the object. The result may be negative.
Return double.MaxValue if there is no such point.
public override double Position(GeoPoint fromHere, GeoVector direction, double precision)
Parameters
fromHereGeoPointStartpoint of the line
directionGeoVectorDirection of the line
precisiondoublePrecision for the test
Returns
- double
Position on the line
PositionAtLength(double)
Returns the parameter of the point at the given position. The position must be in the interval [0, Length]. The correlation between the parameter Position and the resulting position is linear. The result is usually used for PointAt(double) or DirectionAt(double).
public virtual double PositionAtLength(double position)
Parameters
positiondoublePosition on the curve
Returns
- double
The requested position
PositionOf(ICurve, GeoPoint, ref double)
Finds the parameter of the point on curve closest to p with a
Levenberg-Marquardt minimisation, starting at u. The parameter stays within [0,1].
public static bool PositionOf(ICurve curve, GeoPoint p, ref double u)
Parameters
curveICurveThe curve
pGeoPointThe point to find the foot point for
udoubleStart value, the result on success
Returns
- bool
true, if the minimisation converged
PositionOf(GeoPoint)
Returns the parametric position of the point on the curve. This function is inverse to DirectionAt(double). If the given point is not on the curve, the result is the position of a point on the curve, that is close to the given point, but not necessary of the closest point.
public virtual double PositionOf(GeoPoint p)
Parameters
pGeoPointPoint, for which the position is requested
Returns
- double
the requested position
PositionOf(GeoPoint, Plane)
Similar to the PointAt(double) method. Returns the same result, if the point is on the curve. If the point is not on the curve the problem is looked at in the given plane. i.e. the closest point on the projected 2d curve from the projected 2d point is used.
public virtual double PositionOf(GeoPoint p, Plane pl)
Parameters
pGeoPointPoint, whos position is requested
plPlanePlane for the computation of the closest point
Returns
- double
the requested position
PositionOf(GeoPoint, double)
Similar to PositionOf(GeoPoint). If the point is not on the curve and there are several solutions then the solution closest to the parameter prefer will be returned.
public virtual double PositionOf(GeoPoint p, double prefer)
Parameters
pGeoPointPoint, for which the position is requested
preferdoublepreferable solution close to this value
Returns
- double
the requested position
PositionToParameter(double)
convert the position (which is in the 0..1 interval) to the natural parameter value
public virtual double PositionToParameter(double position)
Parameters
positiondouble
Returns
PrepareDisplayList(double)
Called before PaintTo3D(IPaintTo3D) is called, should implement the time consuming work for the display (like calculationg the triangulation of Faces or Polylines of Curves). Not normally used by user code.
public override void PrepareDisplayList(double precision)
Parameters
precisiondoubleRequired precision
Reverse()
Reverses the direction of the curve.
public abstract void Reverse()
SameGeometry(ICurve, double)
Returns true, if this curve and the provided curve describe the same curve in space (maybe opposite direction)
public virtual bool SameGeometry(ICurve other, double precision)
Parameters
Returns
- bool
true, if geometrically equal
Split(double)
Splits the curve at the given position. The position must be in the interval 0..1 and the curve must not be closed. For closed curves Split(double, double).
public abstract ICurve[] Split(double Position)
Parameters
PositiondoubleWhere to split
Returns
- ICurve[]
the splitted curve(s)
Split(double, double)
Splits the closed curve into two open curves at the given positions.
public virtual ICurve[] Split(double Position1, double Position2)
Parameters
Returns
- ICurve[]
the splitted curve(s)
TangentPosition(GeoVector)
Returns a list of positions where the curve has the same or opposite direction as the given direction. Mainly used for visualisation purposes. If there are no such points (which is true in most cases) An empty array should be returned.
public virtual double[] TangentPosition(GeoVector direction)
Parameters
directionGeoVector
Returns
- double[]
Trim(double, double)
Modifies start and endpoint of this curve. StartPos must be less than EndPos. if StartPos is less than 0.0 or EndPos greater than 1.0 this only works for lines and (circular or elliptical) arcs.
public abstract void Trim(double StartPos, double EndPos)
Parameters
TryPointDeriv2At(double, out GeoPoint, out GeoVector, out GeoVector)
Tries to get the point and the first and second derivative of the curve at the specified position. (0..1) Some curves do not implement the second derivative and hence will return false.
public virtual bool TryPointDeriv2At(double position, out GeoPoint point, out GeoVector deriv, out GeoVector deriv2)
Parameters
positiondoublePosition where to calculate point and derivatives
pointGeoPointThe point at the required position
derivGeoVectorderiv2GeoVectorThe second derivative at the provided parameter