Class CompoundShape
- Namespace
- CADability.Shapes
- Assembly
- CADability.dll
A 2d shape composed by multiple SimpleShape objects. All simple shapes are disjoint.
public class CompoundShape : ISerializable, IJsonSerialize, IQuadTreeInsertable
- Inheritance
-
CompoundShape
- Implements
- Inherited Members
Constructors
CompoundShape()
Constructs an empty shape
public CompoundShape()
CompoundShape(params SimpleShape[])
Constructs a compund shape from one or many simple shapes. The simple shapes must be non overlapping
note
If you are not sure, whether
public CompoundShape(params SimpleShape[] simpleShapes)
Parameters
simpleShapesSimpleShape[]the simple shapes
CompoundShape(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected CompoundShape(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Properties
Area
The total area of this shape: the sum of the areas of the simple shapes (each outline minus its holes).
public double Area { get; }
Property Value
DebugList
All borders of this shape as 3d curves in the xy plane, for inspection in a debugger or for displaying the shape in a model. Intended for debugging.
public GeoObjectList DebugList { get; }
Property Value
Empty
true if this shape contains no simple shapes or their total Area is 0. The boolean operations return an empty shape when nothing remains.
public bool Empty { get; }
Property Value
SimpleShapes
Returns the array of SimpleShape, which define this CompoundShape. In many cases, there is only one SimpleShape.
public SimpleShape[] SimpleShapes { get; }
Property Value
UserData
Arbitrary data attached to this shape by the application, see UserData. The container is created on first access; it is not serialized with the shape.
public UserData UserData { get; }
Property Value
Methods
Approximate(bool, double)
Replaces the segments of all borders in place by approximations with lines and arcs (or lines only) that deviate
at most precision from the original curves. Splines and ellipses are gone afterwards, which
makes subsequent operations faster and simpler; use Clone() first if the exact shape is still needed.
public void Approximate(bool linesOnly, double precision)
Parameters
linesOnlybooltrue: approximate with lines only, false: with lines and arcs
precisiondoubleMaximum deviation of the approximation
Clip(ICurve2D, bool)
Clips a curve with this shape: returns the parts of the curve inside (or outside) the shape as parameter intervals on the curve, see Clip(ICurve2D, bool). The result holds pairs of curve parameters (0 to 1), start and end of each piece, sorted along the curve.
public double[] Clip(ICurve2D toClip, bool returnInsideParts)
Parameters
toClipICurve2DThe curve to clip
returnInsidePartsbooltrue: return the parts inside the shape, false: the parts outside
Returns
- double[]
Start and end parameters of the pieces, an even number of values; empty if there is no such piece
Clone()
Returns a deep copy of this compound shape: all simple shapes and their borders are cloned, so the copy can be modified (e.g. with Approximate(bool, double)) without affecting this shape.
public CompoundShape Clone()
Returns
- CompoundShape
The cloned shape
Contains(GeoPoint2D, bool)
Tests whether a point is contained in one of the simple shapes of this shape, see Contains(GeoPoint2D, bool).
public bool Contains(GeoPoint2D p, bool acceptOnCurve)
Parameters
pGeoPoint2DThe point to test
acceptOnCurvebooltrue: a point on a border counts as contained, false: only points strictly inside
Returns
- bool
true if the point is contained
CreateFromConnectedList(GeoObjectList, Plane, GeoPoint2D, double, HatchMode)
Creates a CompundShape from the objects in the list. The objects must reside in a common plane.
The objects must reside in the provided plane. The innerPoint defines
a point which must be inside the shape. The mode gives more control about the desired result.
public static CompoundShape CreateFromConnectedList(GeoObjectList TheObjects, Plane plane, GeoPoint2D innerPoint, double maxGap, ConstrHatchInside.HatchMode mode)
Parameters
TheObjectsGeoObjectListThe objects (curves) that build the shape
planePlaneThe plane, in which the objects reside
innerPointGeoPoint2Dthe inner point which acts as a seed to define the shape
maxGapdoubleThe maiximum allowable gap between curves to still consider them as connected.
modeConstrHatchInside.HatchModeThe mode, ConstrHatchInside.HatchMode
Returns
- CompoundShape
The shape or null, if no appropriate shape found
CreateFromList(ICurve2D[], double)
Creates a CompundShape from the curves in this list. Assumes the curves are connected. The outer hull is returned.
public static CompoundShape CreateFromList(ICurve2D[] curves2d, double maxGap)
Parameters
Returns
- CompoundShape
The shape
CreateFromList(ICurve2D[], double, bool, out GeoObjectList)
Creates a CompundShape from the curves in this list. Assumes the curves are connected. The outer hull is returned.
public static CompoundShape CreateFromList(ICurve2D[] curves2d, double maxGap, bool partInPart, out GeoObjectList deadObjectList)
Parameters
curves2dICurve2D[]The curves
maxGapdoubleMaximum gap between curves
partInPartboolReturn Part in Part (true) or remove them (false)
deadObjectListGeoObjectListList of objects that could not be used to build a CompoundShape
Returns
- CompoundShape
The shape
CreateFromList(GeoObjectList, GeoPoint, bool, bool, double, out Plane)
Creates a CompundShape from the objects in the list. The objects must reside in a common plane.
Only the shape that encloses the inner point is created. If excludeHoles is true,
The resulting shape may contain holes.
public static CompoundShape CreateFromList(GeoObjectList TheObjects, GeoPoint innerPoint, bool connected, bool excludeHoles, double maxGap, out Plane plane)
Parameters
TheObjectsGeoObjectListThe curves to make the shape from
innerPointGeoPointThe inner point to define which shape is to be created
connectedboolTrue: the curves are already connected (faster performance), false: the curves may overlap or intersect
excludeHolesboolTrue: exclude all holes that are inside the outer shape, false: return only the outer shape
maxGapdoubleMaximum gap between curves
planePlaneThe common plane and the location of the shape in 3d space
Returns
- CompoundShape
The shape or null, if no appropriate shape found
CreateFromList(GeoObjectList, double, out Plane, bool)
Creates a CompundShape from the objects in the list. The objects must reside in a common plane.
public static CompoundShape CreateFromList(GeoObjectList TheObjects, double maxGap, out Plane plane, bool partInPart = false)
Parameters
TheObjectsGeoObjectListThe objects to be connected to a shape
maxGapdoubleMaximum gap between curves
planePlaneThe common plane and the location of the shape in 3d space
partInPartboolIf true, parts that lie inside other parts are also returned, otherwise they are removed
Returns
- CompoundShape
The shape, may be null if no shape could be created
CreateGraphicsPath()
Converts this shape to a GDI+ GraphicsPath for drawing or clipping with System.Drawing: the outlines are added counterclockwise and the holes clockwise, so filling the path leaves the holes empty.
public GraphicsPath CreateGraphicsPath()
Returns
- GraphicsPath
The graphics path
Difference(CompoundShape, CompoundShape)
Returns the difference s1 minus s2, the same as s1 - s2, using
eps as the precision.
public static CompoundShape Difference(CompoundShape s1, CompoundShape s2)
Parameters
s1CompoundShapeThe shape to subtract from
s2CompoundShapeThe shape to subtract
Returns
- CompoundShape
The difference, empty if nothing remains
Difference(CompoundShape, CompoundShape, double)
Returns the difference s1 minus s2, i.e. the area of s1
not covered by s2, with an explicit precision: points of the outlines closer than
precision are considered identical. The operands stay unchanged.
public static CompoundShape Difference(CompoundShape s1, CompoundShape s2, double precision)
Parameters
s1CompoundShapeThe shape to subtract from
s2CompoundShapeThe shape to subtract
precisiondoublePrecision for the intersection of the outlines
Returns
- CompoundShape
The difference, empty if nothing remains
Expand(double)
Expands the shape by moving all borders outward by d (see Expand(double)).
Simple shapes that come to overlap are united and holes may close; a negative amount calls Shrink(double).
This shape stays unchanged.
public CompoundShape Expand(double d)
Parameters
ddoubleAmount to expand
Returns
- CompoundShape
The expanded shape
FromSingleOutline(ICurve2D[], double)
Reverse of GetSingleOutline(): builds a compound shape from a sequence of curves describing several
closed loops one after another. A loop ends with the curve whose end point comes back (within
maxGap) to the start point of the first curve of the loop; a bridge line that is traversed
forth and back is left out. The first loop becomes an outline, each following loop becomes a hole of the current
outline when it lies inside it, otherwise it starts a new simple shape. Curves after a loop that cannot be
closed are ignored.
public static CompoundShape FromSingleOutline(ICurve2D[] curves, double maxGap)
Parameters
curvesICurve2D[]The curves of the loops, each loop ordered and connected
maxGapdoubleMaximum distance between the end of a loop and its start
Returns
- CompoundShape
The compound shape
GetDisplayExtent(double)
Returns the extent of this shape for display purposes; since a shape has no parts of fixed pixel size it is the same as GetExtent().
public BoundingRect GetDisplayExtent(double WorldToPixel)
Parameters
WorldToPixeldoubleScaling factor from world units to pixels, not used
Returns
- BoundingRect
The extent of the shape
GetExtent()
Returns the axis aligned bounding rectangle of all simple shapes; an empty rectangle for an empty shape.
public BoundingRect GetExtent()
Returns
- BoundingRect
The extent of the shape
GetModified(ModOp2D)
Returns a copy of this shape transformed by m; this shape stays unchanged. A reflection keeps
the borders correctly oriented, see GetModified(ModOp2D).
public CompoundShape GetModified(ModOp2D m)
Parameters
mModOp2DThe transformation to apply
Returns
- CompoundShape
The transformed shape
GetObjectData(IJsonWriteData)
Writes the simple shapes for the JSON serialization (IJsonSerialize). UserData is not written.
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDataReceives the properties of this shape
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 void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetSingleOutline()
Returns the whole shape as one closed path: the single outlines of the simple shapes (see GetSingleOutline()) are joined by bridge lines at their closest points (ConnectPaths(Path2D, Path2D)). Whether a bridge crosses another simple shape is not checked. Requires at least one simple shape.
public Path2D GetSingleOutline()
Returns
- Path2D
A single closed path covering all simple shapes
HitTest(ref BoundingRect)
Tests whether the given rectangle overlaps this shape: true if the rectangle is (partly) inside one of the simple shapes or touches one of their borders, false if it lies completely outside or inside a hole.
public bool HitTest(ref BoundingRect Rect)
Parameters
RectBoundingRectThe rectangle to test
Returns
- bool
true if the rectangle and the shape overlap
HitTest(ref BoundingRect, bool)
Implementation of HitTest(ref BoundingRect, bool): the same as HitTest(ref BoundingRect), a shape has no control points.
public bool HitTest(ref BoundingRect Rect, bool IncludeControlPoints)
Parameters
RectBoundingRectThe rectangle to test
IncludeControlPointsboolNot used
Returns
- bool
true if the rectangle and the shape overlap
Interferes(CompoundShape, CompoundShape)
Tests whether two compound shapes have area in common or touch each other, i.e. whether some simple shape of
cs1 and some simple shape of cs2 are not disjoint (see
GetPosition(SimpleShape, SimpleShape)).
public static bool Interferes(CompoundShape cs1, CompoundShape cs2)
Parameters
cs1CompoundShapeFirst shape
cs2CompoundShapeSecond shape
Returns
- bool
true if the shapes overlap, touch or one contains the other
Intersection(CompoundShape, CompoundShape)
Returns the intersection of two compound shapes, the same as s1 * s2, using eps as
the precision.
public static CompoundShape Intersection(CompoundShape s1, CompoundShape s2)
Parameters
s1CompoundShapeFirst operand
s2CompoundShapeSecond operand
Returns
- CompoundShape
The intersection, empty if the shapes do not overlap
Intersection(CompoundShape, CompoundShape, double)
Returns the intersection (common area) of two compound shapes with an explicit precision: points of the outlines
closer than precision are considered identical. The operands stay unchanged.
public static CompoundShape Intersection(CompoundShape s1, CompoundShape s2, double precision)
Parameters
s1CompoundShapeFirst operand
s2CompoundShapeSecond operand
precisiondoublePrecision for the intersection of the outlines
Returns
- CompoundShape
The intersection, empty if the shapes do not overlap
MakeFaces(Plane)
Returns planar faces, one for each contained SimpleShape.
public Face[] MakeFaces(Plane plane)
Parameters
planePlanePlane where to construct the faces
Returns
- Face[]
Array of faces
MakePaths(Plane)
Converts the shape to one or more Path objects according to the provided plane.
public Path[] MakePaths(Plane plane)
Parameters
planePlanePlane in 3D space where the shape should be located
Returns
- Path[]
The resulting path(s)
Project(Plane, Plane)
The 2d-compund shape is assumed to reside in plane "fromPlane". It will be projected perpendicular onto the plane "toPlane". If the planes are perpendicular, the result will be am empty shape
public CompoundShape Project(Plane fromPlane, Plane toPlane)
Parameters
Returns
- CompoundShape
the projected shape
SetObjectData(IJsonReadData)
Reads the simple shapes written by GetObjectData(IJsonWriteData) for the JSON deserialization.
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDataThe properties of the shape being read
Shrink(double)
Shrinks the shape by moving all borders inward by d (see Shrink(double)).
Simple shapes may fall apart into several pieces or vanish; a negative amount calls Expand(double). This
shape stays unchanged.
public CompoundShape Shrink(double d)
Parameters
ddoubleAmount to shrink
Returns
- CompoundShape
The shrunk shape, empty if nothing remains
Split(Border)
Splits this compound shape with the given open curve. The result is a compound shape whose simple shapes are the parts of the original simple shapes that the curve cuts them into. If the splitting fails, the unchanged shape is returned.
public CompoundShape Split(Border ToSplitWith)
Parameters
ToSplitWithBorderAn open border that cuts through this shape
Returns
- CompoundShape
The split shape
Union(CompoundShape, CompoundShape)
Returns the union of two compound shapes, the same as s1 + s2, using eps as the
precision.
public static CompoundShape Union(CompoundShape s1, CompoundShape s2)
Parameters
s1CompoundShapeFirst operand
s2CompoundShapeSecond operand
Returns
- CompoundShape
The union
Union(CompoundShape, CompoundShape, double)
Returns the union of two compound shapes with an explicit precision: points of the outlines closer than
precision are considered identical, which makes the operation robust for shapes that touch or
share edges. The operands stay unchanged.
public static CompoundShape Union(CompoundShape s1, CompoundShape s2, double precision)
Parameters
s1CompoundShapeFirst operand
s2CompoundShapeSecond operand
precisiondoublePrecision for the intersection of the outlines
Returns
- CompoundShape
The union
Operators
operator +(CompoundShape, CompoundShape)
Returns the union of two compound shapes (the same as Union(CompoundShape, CompoundShape)): overlapping simple shapes are merged, simple shapes contained in others are dropped and the remaining disjoint simple shapes are collected. The operands stay unchanged.
public static CompoundShape operator +(CompoundShape s1, CompoundShape s2)
Parameters
s1CompoundShapeFirst operand
s2CompoundShapeSecond operand
Returns
- CompoundShape
The union
operator *(CompoundShape, CompoundShape)
Returns the intersection of two compound shapes (the same as Intersection(CompoundShape, CompoundShape)): the area common to both, assembled from the pairwise intersections of their simple shapes. The operands stay unchanged.
public static CompoundShape operator *(CompoundShape s1, CompoundShape s2)
Parameters
s1CompoundShapeFirst operand
s2CompoundShapeSecond operand
Returns
- CompoundShape
The intersection, empty if the shapes do not overlap
operator -(CompoundShape, CompoundShape)
Returns the difference of the two CompoundShapes s1 and s2 (s1-s2). The result may be empty.
public static CompoundShape operator -(CompoundShape s1, CompoundShape s2)
Parameters
s1CompoundShapefirst operand
s2CompoundShapesecond operand
Returns
- CompoundShape
difference