Table of Contents

Class SimpleShape

Namespace
CADability.Shapes
Assembly
CADability.dll

A simply connected 2d shape. It consists of a Border outline and 0 or more holes. The holes don't overlap (disjunct) and reside totally inside the outline.

public class SimpleShape : ISerializable, IQuadTreeInsertable, IComparable<SimpleShape>, IJsonSerialize
Inheritance
SimpleShape
Implements
Inherited Members

Constructors

SimpleShape()

Creates an uninitialized shape for the JSON deserialization; SetObjectData(IJsonReadData) fills it in.

protected SimpleShape()

SimpleShape(Border)

Constructs a simple shape by specifying the outline

public SimpleShape(Border outline)

Parameters

outline Border

The outline

SimpleShape(Border, params Border[])

Constructs a simple shape by specifying the outline and any number of holes.

public SimpleShape(Border outline, params Border[] holes)

Parameters

outline Border

The outline

holes Border[]

The holes

SimpleShape(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected SimpleShape(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Properties

Area

Returns the area of this simple shape.

public double Area { get; }

Property Value

double

DebugList

The segments of the outline and of the holes 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

Returns true, if the Area of this shape is 0.0

public bool Empty { get; }

Property Value

bool

Holes

Returns all holes of this simple shape in an array. You may modify the array since it is a clone of the holes array in this object. But you may not modify the individual holes.

public Border[] Holes { get; }

Property Value

Border[]

NumHoles

Gets the number of holes in this simple shape.

public int NumHoles { get; }

Property Value

int

Outline

Gets the outline of this simple shape. Do not modify the border because this shape might become invalid. To obtain a good performance the outline of this simple shape is returned, not a clone.

public Border Outline { get; }

Property Value

Border

Segments

All segments of this shape: those of the outline followed by those of the holes, each border counterclockwise as every closed Border is. The original curves are returned, do not modify them.

public IEnumerable<ICurve2D> Segments { get; }

Property Value

IEnumerable<ICurve2D>

Methods

CalculateSignature()

Computes a signature of this shape that is invariant under rotation and translation and can be compared quickly (see isEqual(Signature, out bool, double)): the shape is rotated so that its longest outline segment is horizontal and cut with two horizontal and four vertical lines at fixed relative positions; the parameter intervals inside the shape on these lines and the total length of all borders make up the signature. Used by isCongruent(SimpleShape, Signature, out ModOp2D, double) to compare many shapes cheaply before verifying congruence.

public CompoundShape.Signature CalculateSignature()

Returns

CompoundShape.Signature

The signature of this shape

CheckTopology()

Checks whether this shape is correct. I.e. no (self-) intersections of the outline or holes, all holes inside the outline

public bool CheckTopology()

Returns

bool

Clip(ICurve2D, bool)

Clips the provided curve by this shape. Either the inner parts or the parts outside of this shape are returned.

public double[] Clip(ICurve2D toClip, bool returnInsideParts)

Parameters

toClip ICurve2D

Curve to be clipped

returnInsideParts bool

true: return inside parts, false: return outside parts

Returns

double[]

the clipped curves

Clone()

Returns a clone (deep copy) of this simple shape

public SimpleShape Clone()

Returns

SimpleShape

The clone

ConnectPaths(Path2D, Path2D)

Joins two closed paths into a single closed path by inserting a bridge: the closest points p1 on outline and p2 on hole are determined, and the result runs from p2 to p1, around the outline back to p1, back to p2 and around the hole back to p2. Both paths are cloned and flattened first, the originals stay unchanged. The direction of each path is kept, so a hole should be passed reversed (clockwise) for a correctly wound result.

public static Path2D ConnectPaths(Path2D outline, Path2D hole)

Parameters

outline Path2D

The outer closed path

hole Path2D

The closed path to join to it

Returns

Path2D

The combined closed path

Contains(GeoPoint2D, bool)

Tests whether the provided point is contained in this simple shape.

public bool Contains(GeoPoint2D p, bool acceptOnCurve)

Parameters

p GeoPoint2D

The point to be examined

acceptOnCurve bool

true: accept points on the border as inside points, false: return true only for points totally inside this shape

Returns

bool

true if the point is contained, false otherwise

Expand(double)

Expands this simple shape by the given amount. note that the result is a CompoundShape which is composed of multiple simple shapes.

public CompoundShape Expand(double d)

Parameters

d double

Amount to expand, if negative Shrink(double) will be called

Returns

CompoundShape

The resulting shape

GetExtent()

Returns the extent of this shape, i.e. the size of the horizontally adjusted rectangle that encloses it.

public BoundingRect GetExtent()

Returns

BoundingRect

GetModified(ModOp2D)

Returns a modified shape of this shape. This shape remains unchanged.

public SimpleShape GetModified(ModOp2D m)

Parameters

m ModOp2D

Modification by which this shape is modified

Returns

SimpleShape

GetObjectData(IJsonWriteData)

Writes the outline and the holes for the JSON serialization (IJsonSerialize).

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

GetPosition(GeoPoint2D, double)

Determines where a point lies relative to this shape: Inside for a point inside the outline but not inside a hole, Outside for a point outside the outline or inside a hole, OnCurve for a point on the outline or on the border of a hole (within prec). Unlike Contains(GeoPoint2D, bool) the three cases are distinguished.

public Border.Position GetPosition(GeoPoint2D p, double prec = 0)

Parameters

p GeoPoint2D

The point to test

prec double

Distance within which the point counts as being on a border; 0 uses eps

Returns

Border.Position

The position of the point

GetPosition(CompoundShape, CompoundShape)

Checks the relative position of two shapes to each other. The order of the parameters is important for the result.

public static SimpleShape.Position GetPosition(CompoundShape cs1, CompoundShape cs2)

Parameters

cs1 CompoundShape

First shape

cs2 CompoundShape

Second shape

Returns

SimpleShape.Position

The position

GetPosition(SimpleShape, SimpleShape)

Checks the relative position of two shapes to each other. The order of the parameters is important for the result.

public static SimpleShape.Position GetPosition(SimpleShape s1, SimpleShape s2)

Parameters

s1 SimpleShape

First shape

s2 SimpleShape

Second shape

Returns

SimpleShape.Position

The position

GetSingleOutline()

Returns the outline and the holes as one closed path: each hole (reversed, i.e. clockwise) is joined to the outline by a pair of coincident bridge lines at the closest points, see ConnectPaths(Path2D, Path2D). Such a path describes the shape with a single contour, e.g. for exporting to formats or algorithms that do not know holes.

public Path2D GetSingleOutline()

Returns

Path2D

A single closed path covering the outline and the holes

GetSomeInnerPoint()

Finds a point inside this shape (inside the outline, not in a hole) that is well away from the borders: the shape is clipped with a growing set of horizontal and vertical lines and the middle of the widest piece inside is taken, as long as its distance to the borders exceeds a limit that is relaxed with every round. Used e.g. as a test point to evaluate a surface on a face. Returns the origin if no such point can be found.

public GeoPoint2D GetSomeInnerPoint()

Returns

GeoPoint2D

A point inside the shape

HitTest(ref BoundingRect)

Checks whether this shape and the provided rectangle overlap

public bool HitTest(ref BoundingRect Rect)

Parameters

Rect BoundingRect

Returns

bool

Hole(int)

Gets the hole with the specified index. The original border is returned. Do not modify this or the simple shape might become invalid. If you need to modify it, make a clone first.

public Border Hole(int Index)

Parameters

Index int

Returns

Border

Intersect(SimpleShape, SimpleShape)

Returns the intersection (common parts, overlapping area) of two simple shapes.

public static CompoundShape Intersect(SimpleShape Part1, SimpleShape Part2)

Parameters

Part1 SimpleShape

First shape

Part2 SimpleShape

Second shape

Returns

CompoundShape

The resulting shape (may be empty)

Intersect(SimpleShape, SimpleShape, double)

Returns the intersection (common area) of two simple shapes like Intersect(SimpleShape, SimpleShape), with an explicit precision for intersecting the outlines: points closer than precision are considered identical, which makes the operation robust for shapes that touch or share edges.

public static CompoundShape Intersect(SimpleShape Part1, SimpleShape Part2, double precision)

Parameters

Part1 SimpleShape

First shape

Part2 SimpleShape

Second shape

precision double

Precision for the intersection of the outlines

Returns

CompoundShape

The resulting shape (may be empty)

MakeCircle(GeoPoint2D, double)

Creates a circular disk without holes, see MakeCircle(GeoPoint2D, double).

public static SimpleShape MakeCircle(GeoPoint2D center, double radius)

Parameters

center GeoPoint2D

Center of the circle

radius double

Radius of the circle

Returns

SimpleShape

The circular shape

MakeLongHole(ICurve2D, double, double)

Creates the shape of a slot around an arbitrary curve: all points closer than halfWidth to centerLine. The curve is approximated by lines and arcs with the given precision, a slot is built around each piece (see MakeLongHole(ICurve2D, double); arcs with a radius not greater than the half width and arcs sweeping more than 180 degrees are handled specially) and the slots are united. As the pieces are connected, the union is a single simple shape, which may have a hole when the curve winds around.

public static SimpleShape MakeLongHole(ICurve2D centerLine, double halfWidth, double precision)

Parameters

centerLine ICurve2D

The open center curve of the slot, a single curve or a Path2D

halfWidth double

Half the width of the slot, i.e. the radius of the round ends

precision double

Maximum deviation when approximating the curve by lines and arcs

Returns

SimpleShape

The slot, or null if no piece of the curve yielded a shape

MakePaths(Plane)

Converts the outline and the holes of this shape into Path objects.

public Path[] MakePaths(Plane plane)

Parameters

plane Plane

Plane in 3D space where the shape is located

Returns

Path[]

The resulting path(s)

MakePolygon(GeoPoint2D, double, int)

Creates a regular polygon without holes, see MakePolygon(GeoPoint2D, double, int).

public static SimpleShape MakePolygon(GeoPoint2D center, double radius, int numberOfSides)

Parameters

center GeoPoint2D

Center of the polygon

radius double

Distance of the vertices from the center

numberOfSides int

Number of sides (and vertices), at least 3

Returns

SimpleShape

The polygonal shape

Project(Plane, Plane)

The 2d-simple 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 SimpleShape Project(Plane fromPlane, Plane toPlane)

Parameters

fromPlane Plane

the containing plane

toPlane Plane

the projection plane

Returns

SimpleShape

the projected shape

Reduce(double)

Simplifies the outline and the holes in place: segments that are not lines or arcs are approximated by lines and arcs with the given precision, adjacent segments that can be merged into one are fused, and segments shorter than precision as well as dead ends (spikes going out and back) are removed. Holes whose area drops below precision are dropped. Useful after boolean operations, which tend to leave tiny segments.

public void Reduce(double precision)

Parameters

precision double

Maximum deviation of the approximation and minimum length of a segment to keep

SetObjectData(IJsonReadData)

Reads the outline and the holes 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 this simple shape by the given amount. note that the result is a CompoundShape which is composed of multiple simple shapes.

public CompoundShape Shrink(double d)

Parameters

d double

Amount to shrink, if negative Expand(double) will be called

Returns

CompoundShape

The resulting shape (may be empty)

Split(Border)

Returns a CompoundShape consisting of several SimpleShapes that touch each other. This SimpleShape is cut along the open Border ToSplitWith into several subshapes.

public CompoundShape Split(Border ToSplitWith)

Parameters

ToSplitWith Border

The curve to cut with (open Border)

Returns

CompoundShape

Splitted shape

Subtract(SimpleShape, SimpleShape)

Returns the subtraction of Part1 minus Part2, i.e. all parts that belont to Part1 but not to Part2.

public static CompoundShape Subtract(SimpleShape Part1, SimpleShape Part2)

Parameters

Part1 SimpleShape

Shape to be subtracted from

Part2 SimpleShape

Shape that is subtracted

Returns

CompoundShape

The resulting shape (may be empty)

ThickPolyLine(Polyline2D, double)

Creates the shape covered by a round pen of the given radius moving along the polyline: the union of a rectangle of width 2*radius around each edge and a disk of that radius around each vertex, so the ends and the corners are rounded. The pieces are connected, so the union is a single simple shape; should it fall apart (e.g. for a degenerate polyline), only the first simple shape is returned.

public static SimpleShape ThickPolyLine(Polyline2D p2d, double radius)

Parameters

p2d Polyline2D

The polyline to thicken

radius double

Half the width of the resulting band

Returns

SimpleShape

The thickened polyline as a simple shape

Unite(SimpleShape, SimpleShape)

Returns the union of two simple shapes.

public static CompoundShape Unite(SimpleShape Part1, SimpleShape Part2)

Parameters

Part1 SimpleShape

First shape

Part2 SimpleShape

Second shape

Returns

CompoundShape

The resulting shape (may be empty)

isCongruent(SimpleShape, Signature, out ModOp2D, double)

Tests whether this shape and other are congruent, i.e. whether a rotation and a translation (possibly combined with a reflection) map this shape onto the other within precision. The comparison starts with the signatures (see CalculateSignature()), computed here for every longest segment of the outline and compared with otherSig; a candidate is then verified by actually transforming this shape and checking that it coincides with other. Used to find identical faces, e.g. for recognizing repeated features in a shell.

public bool isCongruent(SimpleShape other, CompoundShape.Signature otherSig, out ModOp2D thisToOther, double precision)

Parameters

other SimpleShape

The shape to compare with

otherSig CompoundShape.Signature

The signature of other, as returned by its CalculateSignature()

thisToOther ModOp2D

The transformation mapping this shape onto other, Null if not congruent

precision double

Maximum distance for points to be considered identical

Returns

bool

true if the shapes are congruent