IMcLinesPointClosestToPoint Method |
![]() |
Namespace: MediaCy.IQL.Features
Function PointClosestToPoint ( TestX As Single, TestY As Single, <OutAttribute> ByRef ClosestDistance As Double, <OutAttribute> ByRef ClosestX As Single, <OutAttribute> ByRef ClosestY As Single, <OutAttribute> ByRef ClosestVertexIndex As Integer, <OutAttribute> ByRef DirectHit As Boolean, <OptionalAttribute> Selector As Object, Optional CalibratedDistance As Boolean = true ) As Integer
Sub ReportClosestPointToFeature(fX As Single, fY As Single, ftToTest As McFeatures, _ Optional Selector As Variant = Empty, Optional bCalibrated As Boolean = True) Dim lClosestFeature As Long, fCX As Single, fCY As Single Dim lVertex As Long, dDistance As Double, bDirectHit As Boolean lClosestFeature = ftToTest.PointClosestToPoint(fX, fY, dDistance, fCX, fCY, _ lVertex, bDirectHit, Selector, bCalibrated) Debug.Print "TestX/Y= " & McToText(Array(fX, fY)) & ", Feat= " & lClosestFeature _ & ", ClosestX/Y= " & McToText(Array(fCX, fCY)) _ & ", Dist= " & McToText(dDistance, "%g") _ & ", Vertex= " & lVertex & ", Hit: " & bDirectHit 'Now check out the distance along the feature to the hit point Dim dAlongLineToClosestPoint As Double dAlongLineToClosestPoint = _ ftToTest.DistanceToFeaturePoint(fCX, fCY, lClosestFeature, lVertex, bCalibrated) 'Test the round trip using FeaturePointAtDistanceFromStart Dim bOnLine As Boolean, lDistVertex As Long, AtDistX As Single, AtDistY As Single bOnLine = ftToTest.FeaturePointAtDistanceFromStart(dAlongLineToClosestPoint, lClosestFeature, _ AtDistX, AtDistY, lDistVertex, bCalibrated) Dim bRoundTripOK As Boolean bRoundTripOK = (bOnLine And lDistVertex = lVertex And AtDistX = fCX And AtDistY = fCY) Debug.Print "Dist to closest pt= " & McToText(dAlongLineToClosestPoint, "%g") _ & ", Roundtrip OK= " & bRoundTripOK End Sub 'ReportClosestPointToFeature Sub TestClosestPointToFeatureStuff() 'Create 2 region features Dim strXY As String strXY = InputBox("Input test X,Y") Dim varXY As Variant McFromText strXY, varXY, , 2 Dim fX As Single, fY As Single fX = varXY(0) fY = varXY(1) 'Test McRegions With ThisApplication.ActiveImage.RegionFeatures .Reset .SetBox 0, 10, 10, 30, 30 .SetFeaturePoints 1, Array(60, 10, 30, 50, 90, 50) 'triangle Debug.Print "McRegions" ReportClosestPointToFeature fX, fY, ThisApplication.ActiveImage.RegionFeatures End With 'ActiveImage.RegionFeatures 'Test McLines With ThisApplication.ActiveImage.LineFeatures .Reset .SetFeaturePoints 0, Array(10, 100, 40, 140, 40, 100) .SetFeaturePoints 1, Array(100, 100, 60, 130, 140, 130, 180, 100) Debug.Print "McLines" ReportClosestPointToFeature fX, fY, ThisApplication.ActiveImage.LineFeatures End With 'ActiveImage.LineFeatures 'Test McPoints With ThisApplication.ActiveImage.PointFeatures .Reset .SetFeaturePoints -1, Array(10, 200, 20, 215, 30, 225, 40, 225, 50, 215, 60, 200) Debug.Print "McPoints" ReportClosestPointToFeature fX, fY, ThisApplication.ActiveImage.PointFeatures End With 'ActiveImage.PointFeatures End Sub 'TestClosestPointToFeatureStuff