Table of Contents

Class GeometryExtensions

Namespace
UglyToad.PdfPig.Geometry
Assembly
UglyToad.PdfPig.dll

Extension class to Geometry.

public static class GeometryExtensions
Inheritance
GeometryExtensions
Inherited Members

Methods

Add(PdfPoint, PdfPoint)

Get a point with the summed coordinates of both points.

public static PdfPoint Add(this PdfPoint point1, PdfPoint point2)

Parameters

point1 PdfPoint

The first point.

point2 PdfPoint

The second point.

Returns

PdfPoint

Contains(PdfLine, PdfPoint)

Whether the point is located on the line segment.

public static bool Contains(this PdfLine line, PdfPoint point)

Parameters

line PdfLine
point PdfPoint

Returns

bool

Contains(PdfRectangle, PdfPoint, bool)

Whether the point is located inside the rectangle.

public static bool Contains(this PdfRectangle rectangle, PdfPoint point, bool includeBorder = false)

Parameters

rectangle PdfRectangle

The rectangle that should contain the point.

point PdfPoint

The point that should be contained within the rectangle.

includeBorder bool

If set to false, will return false if the point belongs to the border.

Returns

bool

Contains(PdfRectangle, PdfRectangle, bool)

Whether the other rectangle is located inside the rectangle.

public static bool Contains(this PdfRectangle rectangle, PdfRectangle other, bool includeBorder = false)

Parameters

rectangle PdfRectangle

The rectangle that should contain the other rectangle.

other PdfRectangle

The other rectangle that should be contained within the rectangle.

includeBorder bool

If set to false, will return false if the rectangles share side(s).

Returns

bool

Contains(PdfSubpath, PdfPoint, bool)

Whether the point is located inside the subpath.

Ignores winding rule.

public static bool Contains(this PdfSubpath subpath, PdfPoint point, bool includeBorder = false)

Parameters

subpath PdfSubpath

The subpath that should contain the point.

point PdfPoint

The point that should be contained within the subpath.

includeBorder bool

If set to false, will return false if the point belongs to the subpath's border.

Returns

bool

Contains(PdfSubpath, PdfRectangle, bool)

Whether the rectangle is located inside the subpath.

Ignores winding rule.

public static bool Contains(this PdfSubpath subpath, PdfRectangle rectangle, bool includeBorder = false)

Parameters

subpath PdfSubpath

The subpath that should contain the rectangle.

rectangle PdfRectangle

The rectangle that should be contained within the subpath.

includeBorder bool

If set to false, will return false if the rectangle is on the subpath's border.

Returns

bool

Contains(PdfSubpath, PdfSubpath, bool)

Whether the other subpath is located inside the subpath.

Ignores winding rule.

public static bool Contains(this PdfSubpath subpath, PdfSubpath other, bool includeBorder = false)

Parameters

subpath PdfSubpath

The subpath that should contain the rectangle.

other PdfSubpath

The other subpath that should be contained within the subpath.

includeBorder bool

If set to false, will return false if the other subpath is on the subpath's border.

Returns

bool

Contains(Line, PdfPoint)

Whether the point is located on the line segment.

public static bool Contains(this PdfSubpath.Line line, PdfPoint point)

Parameters

line PdfSubpath.Line
point PdfPoint

Returns

bool

Contains(PdfPath, PdfPoint, bool)

Whether the point is located inside the path.

public static bool Contains(this PdfPath path, PdfPoint point, bool includeBorder = false)

Parameters

path PdfPath

The path that should contain the point.

point PdfPoint

The point that should be contained within the path.

includeBorder bool

If set to false, will return false if the point belongs to the path's border.

Returns

bool

Contains(PdfPath, PdfRectangle, bool)

Whether the rectangle is located inside the path.

public static bool Contains(this PdfPath path, PdfRectangle rectangle, bool includeBorder = false)

Parameters

path PdfPath

The path that should contain the rectangle.

rectangle PdfRectangle

The rectangle that should be contained within the path.

includeBorder bool

If set to false, will return false if the rectangle is on the path's border.

Returns

bool

Contains(PdfPath, PdfSubpath, bool)

Whether the subpath is located inside the path.

public static bool Contains(this PdfPath path, PdfSubpath subpath, bool includeBorder = false)

Parameters

path PdfPath

The path that should contain the subpath.

subpath PdfSubpath

The subpath that should be contained within the path.

includeBorder bool

If set to false, will return false if the subpath is on the path's border.

Returns

bool

Contains(PdfPath, PdfPath, bool)

Whether the other path is located inside the path.

public static bool Contains(this PdfPath path, PdfPath other, bool includeBorder = false)

Parameters

path PdfPath

The path that should contain the path.

other PdfPath

The other path that should be contained within the path.

includeBorder bool

If set to false, will return false if the other subpath is on the path's border.

Returns

bool

DotProduct(PdfPoint, PdfPoint)

Get the dot product of both points.

public static double DotProduct(this PdfPoint point1, PdfPoint point2)

Parameters

point1 PdfPoint

The first point.

point2 PdfPoint

The second point.

Returns

double

GetArea(PdfPath)

Get the area of the path.

public static double GetArea(this PdfPath path)

Parameters

path PdfPath

Returns

double

GrahamScan(IEnumerable<PdfPoint>)

Algorithm to find the convex hull of the set of points with time complexity O(n log n).

public static IEnumerable<PdfPoint> GrahamScan(IEnumerable<PdfPoint> points)

Parameters

points IEnumerable<PdfPoint>

Returns

IEnumerable<PdfPoint>

Intersect(PdfLine, PdfLine)

Get the PdfPoint that is the intersection of two lines.

public static PdfPoint? Intersect(this PdfLine line, PdfLine other)

Parameters

line PdfLine
other PdfLine

Returns

PdfPoint?

Intersect(PdfLine, PdfRectangle)

Gets the PdfLine that is the intersection of the rectangle and the line.

public static PdfLine? Intersect(this PdfLine line, PdfRectangle rectangle)

Parameters

line PdfLine
rectangle PdfRectangle

Returns

PdfLine?

Intersect(PdfLine, Line)

Get the PdfPoint that is the intersection of two lines.

public static PdfPoint? Intersect(this PdfLine line, PdfSubpath.Line other)

Parameters

line PdfLine
other PdfSubpath.Line

Returns

PdfPoint?

Intersect(PdfRectangle, List<PdfLine>)

Gets the list of PdfLines that are the intersection of the rectangle and the lines.

public static List<PdfLine> Intersect(this PdfRectangle rectangle, List<PdfLine> lines)

Parameters

rectangle PdfRectangle
lines List<PdfLine>

Returns

List<PdfLine>

Intersect(PdfRectangle, PdfLine)

Gets the PdfLine that is the intersection of the rectangle and the line.

public static PdfLine? Intersect(this PdfRectangle rectangle, PdfLine line)

Parameters

rectangle PdfRectangle
line PdfLine

Returns

PdfLine?

Intersect(PdfRectangle, PdfRectangle)

Gets the PdfRectangle that is the intersection of two rectangles.

Only works for axis-aligned rectangles.

public static PdfRectangle? Intersect(this PdfRectangle rectangle, PdfRectangle other)

Parameters

rectangle PdfRectangle
other PdfRectangle

Returns

PdfRectangle?

Intersect(BezierCurve, PdfLine)

Get the PdfPoints that are the intersections of the line and the curve.

public static PdfPoint[] Intersect(this PdfSubpath.BezierCurve bezierCurve, PdfLine line)

Parameters

bezierCurve PdfSubpath.BezierCurve
line PdfLine

Returns

PdfPoint[]

Intersect(BezierCurve, Line)

Get the PdfPoints that are the intersections of the line and the curve.

public static PdfPoint[] Intersect(this PdfSubpath.BezierCurve bezierCurve, PdfSubpath.Line line)

Parameters

bezierCurve PdfSubpath.BezierCurve
line PdfSubpath.Line

Returns

PdfPoint[]

Intersect(Line, PdfLine)

Get the PdfPoint that is the intersection of two lines.

public static PdfPoint? Intersect(this PdfSubpath.Line line, PdfLine other)

Parameters

line PdfSubpath.Line
other PdfLine

Returns

PdfPoint?

Intersect(Line, Line)

Get the PdfPoint that is the intersection of two lines.

public static PdfPoint? Intersect(this PdfSubpath.Line line, PdfSubpath.Line other)

Parameters

line PdfSubpath.Line
other PdfSubpath.Line

Returns

PdfPoint?

IntersectT(BezierCurve, PdfLine)

Get the t values that are the intersections of the line and the curve.

public static double[] IntersectT(this PdfSubpath.BezierCurve bezierCurve, PdfLine line)

Parameters

bezierCurve PdfSubpath.BezierCurve
line PdfLine

Returns

double[]

List of t values where the PdfSubpath.BezierCurve and the PdfLine intersect.

IntersectT(BezierCurve, Line)

Get the t values that are the intersections of the line and the curve.

public static double[] IntersectT(this PdfSubpath.BezierCurve bezierCurve, PdfSubpath.Line line)

Parameters

bezierCurve PdfSubpath.BezierCurve
line PdfSubpath.Line

Returns

double[]

List of t values where the PdfSubpath.BezierCurve and the PdfSubpath.Line intersect.

IntersectsWith(PdfLine, PdfLine)

Whether two lines intersect.

public static bool IntersectsWith(this PdfLine line, PdfLine other)

Parameters

line PdfLine
other PdfLine

Returns

bool

IntersectsWith(PdfLine, PdfRectangle)

Whether the rectangle and the line intersect.

public static bool IntersectsWith(this PdfLine line, PdfRectangle rectangle)

Parameters

line PdfLine
rectangle PdfRectangle

Returns

bool

IntersectsWith(PdfLine, Line)

Whether two lines intersect.

public static bool IntersectsWith(this PdfLine line, PdfSubpath.Line other)

Parameters

line PdfLine
other PdfSubpath.Line

Returns

bool

IntersectsWith(PdfPoint, PdfPoint, PdfPoint, PdfPoint)

Whether the line formed by p11 and p12 intersects the line formed by p21 and p22.

public static bool IntersectsWith(PdfPoint p11, PdfPoint p12, PdfPoint p21, PdfPoint p22)

Parameters

p11 PdfPoint
p12 PdfPoint
p21 PdfPoint
p22 PdfPoint

Returns

bool

IntersectsWith(PdfRectangle, PdfLine)

Whether the rectangle and the line intersect.

public static bool IntersectsWith(this PdfRectangle rectangle, PdfLine line)

Parameters

rectangle PdfRectangle
line PdfLine

Returns

bool

IntersectsWith(PdfRectangle, PdfPoint, PdfPoint)

Whether the line formed by pl1 and pl2 intersects the rectangle.

public static bool IntersectsWith(PdfRectangle rectangle, PdfPoint pl1, PdfPoint pl2)

Parameters

rectangle PdfRectangle
pl1 PdfPoint
pl2 PdfPoint

Returns

bool

IntersectsWith(PdfRectangle, PdfRectangle)

Whether two rectangles overlap.

Returns false if the two rectangles only share a border.

public static bool IntersectsWith(this PdfRectangle rectangle, PdfRectangle other)

Parameters

rectangle PdfRectangle
other PdfRectangle

Returns

bool

IntersectsWith(BezierCurve, PdfLine)

Checks if the curve and the line are intersecting.

Avoid using this method as it is not optimised. Use Intersect(BezierCurve, PdfLine) instead.

public static bool IntersectsWith(this PdfSubpath.BezierCurve bezierCurve, PdfLine line)

Parameters

bezierCurve PdfSubpath.BezierCurve
line PdfLine

Returns

bool

IntersectsWith(BezierCurve, Line)

Checks if the curve and the line are intersecting.

Avoid using this method as it is not optimised. Use Intersect(BezierCurve, Line) instead.

public static bool IntersectsWith(this PdfSubpath.BezierCurve bezierCurve, PdfSubpath.Line line)

Parameters

bezierCurve PdfSubpath.BezierCurve
line PdfSubpath.Line

Returns

bool

IntersectsWith(Line, PdfLine)

Whether two lines intersect.

public static bool IntersectsWith(this PdfSubpath.Line line, PdfLine other)

Parameters

line PdfSubpath.Line
other PdfLine

Returns

bool

IntersectsWith(Line, Line)

Whether two lines intersect.

public static bool IntersectsWith(this PdfSubpath.Line line, PdfSubpath.Line other)

Parameters

line PdfSubpath.Line
other PdfSubpath.Line

Returns

bool

MinimumAreaRectangle(IEnumerable<PdfPoint>)

Algorithm to find the (oriented) minimum area rectangle (MAR) by first finding the convex hull of the points and then finding its MAR.

public static PdfRectangle MinimumAreaRectangle(IEnumerable<PdfPoint> points)

Parameters

points IEnumerable<PdfPoint>

The points.

Returns

PdfRectangle

Normalise(PdfRectangle)

Gets the axis-aligned rectangle that completely containing the original rectangle, with no rotation.

public static PdfRectangle Normalise(this PdfRectangle rectangle)

Parameters

rectangle PdfRectangle

Returns

PdfRectangle

OrientedBoundingBox(IReadOnlyList<PdfPoint>)

Algorithm to find the oriented bounding box (OBB) by first fitting a line through the points to get the slope, then rotating the points to obtain the axis-aligned bounding box (AABB), and then rotating back the AABB.

public static PdfRectangle OrientedBoundingBox(IReadOnlyList<PdfPoint> points)

Parameters

points IReadOnlyList<PdfPoint>

The points.

Returns

PdfRectangle

ParallelTo(PdfLine, PdfLine)

Checks if both lines are parallel.

public static bool ParallelTo(this PdfLine line, PdfLine other)

Parameters

line PdfLine
other PdfLine

Returns

bool

ParallelTo(PdfLine, Line)

Checks if both lines are parallel.

public static bool ParallelTo(this PdfLine line, PdfSubpath.Line other)

Parameters

line PdfLine
other PdfSubpath.Line

Returns

bool

ParallelTo(Line, PdfLine)

Checks if both lines are parallel.

public static bool ParallelTo(this PdfSubpath.Line line, PdfLine other)

Parameters

line PdfSubpath.Line
other PdfLine

Returns

bool

ParallelTo(Line, Line)

Checks if both lines are parallel.

public static bool ParallelTo(this PdfSubpath.Line line, PdfSubpath.Line other)

Parameters

line PdfSubpath.Line
other PdfSubpath.Line

Returns

bool

Split(BezierCurve, double)

Split a bezier curve into 2 bezier curves, at tau.

public static (PdfSubpath.BezierCurve, PdfSubpath.BezierCurve) Split(this PdfSubpath.BezierCurve bezierCurve, double tau)

Parameters

bezierCurve PdfSubpath.BezierCurve

The original bezier curve.

tau double

The t value were to split the curve, usually between 0 and 1, but not necessary.

Returns

(PdfSubpath.BezierCurve, PdfSubpath.BezierCurve)

Subtract(PdfPoint, PdfPoint)

Get a point with the substracted coordinates of both points.

public static PdfPoint Subtract(this PdfPoint point1, PdfPoint point2)

Parameters

point1 PdfPoint

The first point.

point2 PdfPoint

The second point.

Returns

PdfPoint