Previous Document Next Document

Object Model Reference : Classes : N : Node : Methods : Node.GetDistanceFrom


Node.GetDistanceFrom

Function GetDistanceFrom(Node As Node) As Double

Description

Member of Node

The GetDistanceFrom method returns the distance from the current node to a specified node.

Parameter
Description
Node
Specifies the node from which to return the distance

VBA example

The following VBA example closes all open subpaths in a curve by joining or connecting each one with the closest node of another open subpath.

Sub CloseShape()
 Dim s As Shape
 Dim e As Double, r As Double, nr As Double
 Dim sp As SubPath
 Dim sn As Node, en As Node, n1 As Node, n2 As Node
 Dim b As Boolean
 Set s = ActiveShape
 If s.Type <> cdrCurveShape Then
  MsgBox "Curve must be selected"
  Exit Sub
 End If
 ' E is auto-join limit beyond which the nodes are joined rather than connected
 ' Here assumed to be 1% of an average object size
 e = s.SizeHeight * s.SizeWidth / 10000
 Do
  Set sn = Nothing
  Set en = Nothing
  Set n1 = Nothing
  Set n2 = Nothing
  b = False
  For Each sp In s.Curve.Subpaths
   If Not sp.Closed Then
    Set n1 = sp.StartNode
    Set n2 = sp.EndNode
    nr = n1.GetDistanceFrom(n2)
    If nr < e And sp.Nodes.Count > 2 Then
     n1.JoinWith n2
     b = True
    Else
     If sn Is Nothing Then
      Set sn = n1
      Set en = n2
      r = nr
     Else
      nr = sn.GetDistanceFrom(n1)
      If nr < r Then
       Set en = n1
       r = nr
      End If
      nr = sn.GetDistanceFrom(n2)
      If nr < r Then
       Set en = n2
       r = nr
      End If
     End If
    End If
   End If
   If b Then Exit For
  Next sp
  If Not b And Not sn Is Nothing Then
   If r < e Then sn.JoinWith en Else sn.ConnectWith en
   b = True
  End If
 Loop While b
End Sub

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.