Table of Contents

Class Geometry

Namespace
Northwoods.Go
Assembly
Northwoods.GoDiagram.WinForms.dll

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

[JsonConverter(typeof(GeometryJsonConverter))]
public class Geometry
Inheritance
Geometry
Inherited Members

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.

public Geometry(GeometryType type = GeometryType.Path)

Parameters

type GeometryType

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).

public Rect Bounds { get; }

Property Value

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.

public GeometryStretch DefaultStretch { get; set; }

Property Value

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.

public double EndX { get; set; }

Property Value

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.

public double EndY { get; set; }

Property Value

double

Figures

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

public IList<PathFigure> Figures { get; set; }

Property Value

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.

public Spot Spot1 { get; set; }

Property Value

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.

public Spot Spot2 { get; set; }

Property Value

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.

public double StartX { get; set; }

Property Value

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.

public double StartY { get; set; }

Property Value

double

Type

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

public GeometryType Type { get; set; }

Property Value

GeometryType

Methods

Add(PathFigure)

Add a PathFigure to the Figures list.

public Geometry Add(PathFigure figure)

Parameters

figure PathFigure

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

Returns

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.

public Rect ComputeBoundsWithoutOrigin()

Returns

Rect

ContainsPoint(Point, double)

Returns true if the Geometry contains the point.

public bool ContainsPoint(Point p, double sw = 0)

Parameters

p Point

in local geometry coordinates

sw double

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

Returns

bool

Copy()

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

public Geometry Copy()

Returns

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".

public static string FillPath(string str)

Parameters

str string

Returns

string

GetAngleAlongPath(double)

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

public double GetAngleAlongPath(double fraction)

Parameters

fraction double

A fractional amount between 0 and 1, inclusive.

Returns

double

GetFractionForPoint(Point)

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

public double GetFractionForPoint(Point pt)

Parameters

pt Point

A Point, in local coordinates, near this Geometry.

Returns

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.

public Point GetPointAlongPath(double fraction)

Parameters

fraction double

A fractional amount between 0 and 1, inclusive.

Returns

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.

public Point Normalize()

Returns

Point

Offset(double, double)

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

public Geometry Offset(double x, double y)

Parameters

x double

The x-axis offset factor.

y double

The y-axis offset factor.

Returns

Geometry

this

Parse(object)

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

public static object Parse(object str)

Parameters

str object

Returns

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.

public static Geometry Parse(string str, bool filled = false)

Parameters

str string
filled bool

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

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.

public Geometry Rotate(double angle, double x = 0, double y = 0)

Parameters

angle double

The angle to rotate by.

x double

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

y double

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

Returns

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).

public Geometry Scale(double x, double y)

Parameters

x double

The x-axis scale factor.

y double

The y-axis scale factor.

Returns

Geometry

this

Stringify(Geometry)

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

public static string Stringify(Geometry val)

Parameters

val Geometry

Returns

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.

public static object Stringify(object geo)

Parameters

geo object

Returns

object

StringifyFixed(Geometry, int)

This static method can be used to write out a Geometry as a string with its numbers at a fixed number of digits after the decimal point.

public static string StringifyFixed(Geometry val, int digits)

Parameters

val Geometry

the Geometry

digits int

the number of decimals to output

Returns

string

Remarks

This is useful for limiting the size of JSON output and making it more legible. It might also be useful for regression testing.

StringifyFixed(object)

This is a convenience method for StringifyFixed(Geometry, int) that can be used as a BackConverter. This convenience method uses two decimal places.

public static object StringifyFixed(object geo)

Parameters

geo object

Returns

object