Class Geometry

GoDiagram®
v10.0.8
by Northwoods Software®

The Geometry class is used to define the "shape" of a Shape.

Inheritance
Geometry
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.WinForms.dll
Syntax
[JsonConverter(typeof(GeometryJsonConverter))]
public class Geometry
Remarks

A Geometry can be simple straight lines, rectangles, or ellipses. A Geometry can also be an arbitrarily complex path, consisting of a list of PathFigures.

A Geometry must not be modified once it has been used by a Shape. However, a Geometry may be shared by multiple Shapes.

It is commonplace to create Geometries using geometry path string syntax: Geometry Path Strings. However it is much more efficient to create Geometries programmatically. One way to do that is illustrated by several of the samples that evaluate JavaScript such as:

new Geometry()
    .Add(new PathFigure(p.X, p.Y)
         .Add(new PathSegment(SegmentType.Arc, -sweep/2, sweep, 0, 0, radius+layerThickness, radius+layerThickness))
         .Add(new PathSegment(SegmentType.Line, q.X, q.Y))
         .Add(new PathSegment(SegmentType.Arc, sweep/2, -sweep, 0, 0, radius, radius).close()));

See samples that make use of Geometries in the samples index.

Constructors

Geometry(GeometryType)

Construct an empty Geometry of the given GeometryType.

Declaration
public Geometry(GeometryType type = GeometryType.Path)
Parameters
Type Name Description
GeometryType type
Remarks

The default type is Path.

Properties

Bounds

This read-only property returns a rectangle that contains all points within the Geometry. The result will always contain the origin (0, 0).

Declaration
public Rect Bounds { get; }
Property Value
Type Description
Rect

DefaultStretch

Gets or sets the GeometryStretch value the Shape should use by default when the GeometryStretch value is None. The default value is Fill. Some figure generators return a Geometry with this property set to Uniform, in order to preserve its aspect ratio when used by a Shape that may have different sizes.

Declaration
public GeometryStretch DefaultStretch { get; set; }
Property Value
Type Description
GeometryStretch

EndX

Gets or sets the ending X coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse. The initial value is zero.

Declaration
public double EndX { get; set; }
Property Value
Type Description
double

EndY

Gets or sets the ending Y coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse. The initial value is zero.

Declaration
public double EndY { get; set; }
Property Value
Type Description
double

Figures

Gets or sets the List of PathFigures that describes the content of the path for Geometries of type Path.

Declaration
public IList<PathFigure> Figures { get; set; }
Property Value
Type Description
IList<PathFigure>

Spot1

Gets or sets the spot an "Auto" Panel will use for the top-left corner of any panel content when the Spot1 value is Default. The default value is TopLeft, at the top-left point of the bounds of the Shape.

Declaration
public Spot Spot1 { get; set; }
Property Value
Type Description
Spot

Spot2

Gets or sets the spot an "Auto" Panel will use for the bottom-right corner of any panel content when the Spot2 value is Default. The default value is BottomRight, at the bottom-right point of the bounds of the Shape.

Declaration
public Spot Spot2 { get; set; }
Property Value
Type Description
Spot

StartX

Gets or sets the starting X coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse. The initial value is zero.

Declaration
public double StartX { get; set; }
Property Value
Type Description
double

StartY

Gets or sets the starting Y coordinate of the Geometry if it is of type Line, Rectangle, or Ellipse. The initial value is zero.

Declaration
public double StartY { get; set; }
Property Value
Type Description
double

Type

Gets or sets the type of the Geometry. The default type is Path. Other permissible values are Line, Ellipse, or Rectangle.

Declaration
public GeometryType Type { get; set; }
Property Value
Type Description
GeometryType

Methods

Add(PathFigure)

Add a PathFigure to the Figures list.

Declaration
public Geometry Add(PathFigure figure)
Parameters
Type Name Description
PathFigure figure

a newly allocated unshared PathFigure that will become owned by this Geometry

Returns
Type Description
Geometry

this

ComputeBoundsWithoutOrigin()

Computes the Geometry's bounds without adding an origin point, and returns those bounds as a rect. This method does not modify the Geometry or its bounds.

Declaration
public Rect ComputeBoundsWithoutOrigin()
Returns
Type Description
Rect

ContainsPoint(Point, double)

Returns true if the Geometry contains the point.

Declaration
public bool ContainsPoint(Point p, double sw = 0)
Parameters
Type Name Description
Point p

in local geometry coordinates

double sw

half the stroke width that a Shape has or that you want to pretend it has

Returns
Type Description
bool

Copy()

Create a copy of this Geometry, with the same values and figures.

Declaration
public Geometry Copy()
Returns
Type Description
Geometry

FillPath(string)

Given a SVG or GoDiagram path string, returns a congruent path string with each pathfigure filled. For instance, "M0 0 L22 22 L33 0" would become "F M0 0 L22 22 L33 0".

Declaration
public static string FillPath(string str)
Parameters
Type Name Description
string str
Returns
Type Description
string

GetAngleAlongPath(double)

Returns the slope expressed as an angle at the fractional distance (0-1) along this Geometry's path, in local coordinates.

Declaration
public double GetAngleAlongPath(double fraction)
Parameters
Type Name Description
double fraction

A fractional amount between 0 and 1, inclusive.

Returns
Type Description
double

GetFractionForPoint(Point)

Returns the fractional distance (0-1) along this Geometry's path for a nearby point.

Declaration
public double GetFractionForPoint(Point pt)
Parameters
Type Name Description
Point pt

A Point, in local coordinates, near this Geometry.

Returns
Type Description
double

A fractional amount between 0 and 1, inclusive.

GetPointAlongPath(double)

Returns the point at the fractional distance (0-1) along this Geometry's path.

Declaration
public Point GetPointAlongPath(double fraction)
Parameters
Type Name Description
double fraction

A fractional amount between 0 and 1, inclusive.

Returns
Type Description
Point

the Point, in local coordinates, of the fractional distance along the path.

Normalize()

Normalizes the Geometry points in place by ensuring the top-left bounds of the geometry lines up with (0, 0), returning the Point (x, y) amount it was shifted. After this method is called there will be no negative X or Y value for the Geometry's bounds, and no empty space at the top-left of the Geometry.

Declaration
public Point Normalize()
Returns
Type Description
Point

Offset(double, double)

Offsets the Geometry in place by a given (x, y) amount.

Declaration
public Geometry Offset(double x, double y)
Parameters
Type Name Description
double x

The x-axis offset factor.

double y

The y-axis offset factor.

Returns
Type Description
Geometry

this

Parse(object)

This is a convenience method for Parse(string, bool) that can be used as a Converter.

Declaration
public static object Parse(object str)
Parameters
Type Name Description
object str
Returns
Type Description
object

Parse(string, bool)

Produce a Geometry from a string that uses an SVG-like compact path geometry syntax. The syntax accepts all SVG Path Syntax (SVG Path Syntax (w3.org)), as well as three GoDiagram-specific tokens.

Declaration
public static Geometry Parse(string str, bool filled = false)
Parameters
Type Name Description
string str
bool filled

whether figures should be filled. If true, all PathFigures in the string will be filled regardless of the presence of an "F" command or not. If false, all PathFigures will determine their own filled state by the presence of an "F" command or not. Default is false.

Returns
Type Description
Geometry
Remarks

Specifically, the following tokens are allowed:

  • M (x,y)+ - Move commands
  • L (x,y)+, H (x)+, V (y)+ Lines commands, including horizontal and vertical lines
  • C (x1 y1 x2 y2 x y)+, S (x2 y2 x y)+ Cubic bezier curves
  • Q (x1 y1 x y)+, T (x y)+ Quadratic bezier curves
  • A (rx ry x-axis-rotation large-arc-flag clockwise-flag x y)+ Arcs (following SVG arc conventions)
  • Z Denotes that the previous subpath is closed

Additionally there are some tokens specific to GoDiagram:

  • B (startAngle, sweepAngle, centerX, centerY, radius)+ Arcs following GoDiagram canvas arc conventions
  • X Used before M-commands to denote separate PathFigures instead of a subpath
  • F Denotes whether the current PathFigure is filled (true if F is present)
  • U Denotes that the PathFigure is not shadowed

See the Introduction page on Geometry Parsing for more details.

Rotate(double, double, double)

Rotates the Geometry in place by a given angle, with optional x and y values to rotate the geometry about. If no x and y value are given, (0, 0) is used as the rotation point.

Declaration
public Geometry Rotate(double angle, double x = 0, double y = 0)
Parameters
Type Name Description
double angle

The angle to rotate by.

double x

The optional X point to rotate the geometry about. If no point is given, this value is 0.

double y

The optional Y point to rotate the geometry about. If no point is given, this value is 0.

Returns
Type Description
Geometry

this

Scale(double, double)

Scales the Geometry in place by a given (x, y) scale factor.

If you want to flip a Geometry horizontally, call geo.Scale(-1, 1). If you want to flip a Geometry vertically, call geo.Scale(1, -1).

Declaration
public Geometry Scale(double x, double y)
Parameters
Type Name Description
double x

The x-axis scale factor.

double y

The y-axis scale factor.

Returns
Type Description
Geometry

this

Stringify(Geometry)

This static function can be used to write out a Geometry as a string that can be read by Parse(string, bool).

Declaration
public static string Stringify(Geometry val)
Parameters
Type Name Description
Geometry val
Returns
Type Description
string
Remarks

The string produced by this method is a superset of the SVG path string rules that contains some additional GoDiagram-specific tokens. See the Introduction page on Geometry Parsing for more details.

Stringify(object)

This is a convenience method for Stringify(Geometry) that can be used as a BackConverter.

Declaration
public static object Stringify(object geo)
Parameters
Type Name Description
object geo
Returns
Type Description
object