Table of Contents

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

simpleShapes SimpleShape[]

the simple shapes

CompoundShape(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected CompoundShape(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

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

double

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

GeoObjectList

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

bool

SimpleShapes

Returns the array of SimpleShape, which define this CompoundShape. In many cases, there is only one SimpleShape.

public SimpleShape[] SimpleShapes { get; }

Property Value

SimpleShape[]

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

UserData

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

linesOnly bool

true: approximate with lines only, false: with lines and arcs

precision double

Maximum 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

toClip ICurve2D

The curve to clip

returnInsideParts bool

true: 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

p GeoPoint2D

The point to test

acceptOnCurve bool

true: 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

TheObjects GeoObjectList

The objects (curves) that build the shape

plane Plane

The plane, in which the objects reside

innerPoint GeoPoint2D

the inner point which acts as a seed to define the shape

maxGap double

The maiximum allowable gap between curves to still consider them as connected.

mode ConstrHatchInside.HatchMode

The 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

curves2d ICurve2D[]

The curves

maxGap double

Maximum gap between curves

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

curves2d ICurve2D[]

The curves

maxGap double

Maximum gap between curves

partInPart bool

Return Part in Part (true) or remove them (false)

deadObjectList GeoObjectList

List 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

TheObjects GeoObjectList

The curves to make the shape from

innerPoint GeoPoint

The inner point to define which shape is to be created

connected bool

True: the curves are already connected (faster performance), false: the curves may overlap or intersect

excludeHoles bool

True: exclude all holes that are inside the outer shape, false: return only the outer shape

maxGap double

Maximum gap between curves

plane Plane

The 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

TheObjects GeoObjectList

The objects to be connected to a shape

maxGap double

Maximum gap between curves

plane Plane

The common plane and the location of the shape in 3d space

partInPart bool

If 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

s1 CompoundShape

The shape to subtract from

s2 CompoundShape

The 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

s1 CompoundShape

The shape to subtract from

s2 CompoundShape

The shape to subtract

precision double

Precision 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

d double

Amount 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

curves ICurve2D[]

The curves of the loops, each loop ordered and connected

maxGap double

Maximum 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

WorldToPixel double

Scaling 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

m ModOp2D

The 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

data IJsonWriteData

Receives 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

info SerializationInfo

receives the data

context StreamingContext

the 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

Rect BoundingRect

The 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

Rect BoundingRect

The rectangle to test

IncludeControlPoints bool

Not 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

cs1 CompoundShape

First shape

cs2 CompoundShape

Second 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

s1 CompoundShape

First operand

s2 CompoundShape

Second 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

s1 CompoundShape

First operand

s2 CompoundShape

Second operand

precision double

Precision 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

plane Plane

Plane 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

plane Plane

Plane 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

fromPlane Plane

the containing plane

toPlane Plane

the projection plane

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

data IJsonReadData

The 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

d double

Amount 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

ToSplitWith Border

An 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

s1 CompoundShape

First operand

s2 CompoundShape

Second 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

s1 CompoundShape

First operand

s2 CompoundShape

Second operand

precision double

Precision 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

s1 CompoundShape

First operand

s2 CompoundShape

Second 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

s1 CompoundShape

First operand

s2 CompoundShape

Second 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

s1 CompoundShape

first operand

s2 CompoundShape

second operand

Returns

CompoundShape

difference