Geometry Helper Library

Created:8/23/2002
Description:

This sample provides some utility functions to create primitive geometries: points, lines, circular arcs, elliptic arcs, circles, ellipses, envelopes, rings, paths, polylines, and polygons. There are also utility functions to get the code creating string of ring, path, polyline, and polygon. With these functions, it becomes easier to inspect, reproduce, and manipulate geometry objects.

How to use:
  1. Register GeometryLib.dll using "regsvr32 GeometryLib.dll" at command line.
  2. In VB or VBA IDE, add reference to GeometryLib.
  3. Declare an object like "Dim h as GeometryLib.GeomHelper" and use the methods of this object. The following code shows the usage.

Public Sub Test()
  Dim h As New GeometryLib.GeomHelper
  Dim env As IEnvelope
  Set env = h.EnvelopeC(0, 0, 1, 1)
  Dim polyEnv As IPolygon
  Set polyEnv = h.EnvToPoly(env)
  Dim aLine As ILine
  Set aLine = h.LineC(h.PtC(2, 2), h.PtC(2, 3))
  Dim aPl As IPolyline
  Set aPl = h.PlC_paths(h.PathC(eLine, Array(h.PtC(0, 0), h.PtC(0, 10), h.PtC(10, 10), h.PtC(10, 0), h.PtC(0, 0))), _
                  h.PathC(eCircularArc, h.create_full_Circle(h.PtC(20, 20), 5)), _
                  h.PathC(eEllipticArc, h.create_full_Ellipse(h.PtC(40, 40), 4 * Atn(1) / 3, 10, 0.4)), _
                  h.PathC(eBezierCurve, h.create_BezierCurve(h.PtC(60, 0), h.PtC(60, 20), h.PtC(80, 20), h.PtC(80, 0))), _
                  h.PathC(eCircularArc, h.create_CircularArc(h.PtC(-20, -20), h.PtC(-10, -30), h.PtC(-10, -10)), eLine, Array(h.PtC(-10, -10), h.PtC(-20, -20), h.PtC(-10, -30))))
  Dim aPg As IPolygon
  Set aPg = h.PgC_rings(h.RingC(eLine, Array(h.PtC(0, 0), h.PtC(0, 10), h.PtC(10, 10), h.PtC(10, 0), h.PtC(0, 0))), _
                  h.RingC(eCircularArc, h.create_full_Circle(h.PtC(20, 20), 5)), _
                  h.RingC(eEllipticArc, h.create_full_Ellipse(h.PtC(40, 40), 4 * Atn(1) / 3, 10, 0.4)), _
                  h.RingC(eBezierCurve, h.create_BezierCurve(h.PtC(60, 0), h.PtC(60, 20), h.PtC(80, 20), h.PtC(80, 0))), _
                  h.RingC(eCircularArc, h.create_CircularArc(h.PtC(-20, -20), h.PtC(-10, -30), h.PtC(-10, -10)), eLine, Array(h.PtC(-10, -10), h.PtC(-20, -20), h.PtC(-10, -30))))
  
  Dim simplePg As IPolygon
  Set simplePg = h.PgC(Array(h.PtC(0, 0), h.PtC(0, 5), h.PtC(5, 5), h.PtC(5, 0), h.PtC(0, 0)), _
                    Array(h.PtC(10, 0), h.PtC(10, 5), h.PtC(15, 5), h.PtC(15, 0), h.PtC(10, 0)))
  
  Dim simplePl As IPolyline
  Set simplePl = h.PlC(Array(h.PtC(0, 0), h.PtC(0, 5), h.PtC(5, 5), h.PtC(5, 0)), _
                    Array(h.PtC(10, 0), h.PtC(10, 5), h.PtC(15, 5), h.PtC(15, 0)))
  Dim part_sz As String
  
  Dim aRing As IRing
  Set aRing = h.RingC_points(h.PtC(0, 0), h.PtC(1, 1), h.PtC(1, 0))
  Dim aPath As IPath
  Set aPath = h.PathC_points(h.PtC(0, 0), h.PtC(1, 1), h.PtC(1, 0))
  
  Debug.Print h.poly_to_string(simplePg)
  Debug.Print h.poly_to_string(simplePl)
  Debug.Print h.poly_to_string(aPg)
  Debug.Print h.poly_to_string(aPl)
  Debug.Print h.path_to_string(aPath)
  Debug.Print h.ring_to_string(aRing)
  Debug.Print h.poly_to_string(polyEnv)
End Sub
Application: N/A

Requires: N/A

Difficulty: Intermediate


Visual Basic
File Description
ErrorHandling.bas Error handling functions
GeomHelper.cls The class module
GeometryLib.vbp Visual Basic Project file
GeometryLib.dll The compiled DLL containing the implementation of the sample.


Key CoClasses: Point, Line, CircularArc, EllipticArc, BezierCurve, Ring, Path, Polyline, Polygon
Key Interfaces: IPoint, ILine, ICircularArc, IEllipticArc, IBezierCurve, IEnvelope, IGeometryCollection, ISegmentCollection, IRing, IPath, IPolyline, IPolygon
Key Members: ISegmentCollection::AddSegment, IGeometryCollection::AddGeometry, IEllipticArc::PutCoords, IBezierCurve::PutCoords, ICircularArc::PutCoords