ContourGroup: Difference between revisions

From SDK
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
This object is used to move along a contour a fixed distance at a time irrespective of the number of spans in the contour or the type of spans.   
This object is used to move along a contour a fixed distance at a time irrespective of the number of spans in the contour or the type of spans.   


Constructor
==Constructor==


ContourCarriage( Contour ctr, Point2D pt)
===ContourCarriage( Contour ctr, Point2D pt) ===


Creates a ‘carriage’ for the passed contour and positions it at the nearest point on the contour to the passed point.   
Creates a ‘carriage’ for the passed contour and positions it at the nearest point on the contour to the passed point.   
Line 17: Line 17:
    
    


ContourCarriage( integer span_index, double parameter)   
===ContourCarriage( integer span_index, double parameter)===  


Creates a ‘carriage’ for a contour and set its positions for the span with the passed index at the passed parameter position (in range 0-1.0) on the span. These values are normaly specified as 0,0.0 to position the carriage at the start of the first span in the contour.   
Creates a ‘carriage’ for a contour and set its positions for the span with the passed index at the passed parameter position (in range 0-1.0) on the span. These values are normaly specified as 0,0.0 to position the carriage at the start of the first span in the contour.   
Line 31: Line 31:
    
    


Properties   
==Properties==  


.IsInvalid   
===.IsInvalid===  


R/O - bool - Returns true if current position is invalid   
R/O - bool - Returns true if current position is invalid   
Line 39: Line 39:
   
   


.SpanIndex   
===.SpanIndex===  


R/O - integer - Return span index for current position of carriage   
R/O - integer - Return span index for current position of carriage   
Line 45: Line 45:
   
   


.SpanParameter   
===.SpanParameter===  


R/O - double - Return span parameter (in range 0-1.0) for current position of carriage   
R/O - double - Return span parameter (in range 0-1.0) for current position of carriage   
Line 51: Line 51:
    
    


Methods
==Methods==


:Move( Contour ctr, double distance)   
===:Move( Contour ctr, double distance)===  


Moves the carriage the requested distance along the contour. Returns true if manage to move requested distance successfully. If the contour is closed we will wrap around at the end, if it is open and you attempt to move past the end this method will return false.   
Moves the carriage the requested distance along the contour. Returns true if manage to move requested distance successfully. If the contour is closed we will wrap around at the end, if it is open and you attempt to move past the end this method will return false.   
Line 63: Line 63:
    
    


:Position( Contour ctr)   
===:Position( Contour ctr)===  


Returns a Point2D representing the current position on the carriage on the passed contour   
Returns a Point2D representing the current position on the carriage on the passed contour   
Line 71: Line 71:
    
    


:UpdatePosition( Contour ctr, Point2D pt)   
===:UpdatePosition( Contour ctr, Point2D pt)===  


Update the position of the carriage to the nearest position on the contour to the passed point.   
Update the position of the carriage to the nearest position on the contour to the passed point.   

Revision as of 11:57, 30 August 2024

Back.jpg

This object is used to move along a contour a fixed distance at a time irrespective of the number of spans in the contour or the type of spans.

Constructor

ContourCarriage( Contour ctr, Point2D pt)

Creates a ‘carriage’ for the passed contour and positions it at the nearest point on the contour to the passed point.

ctr-Contour -The contour that the carriage travels along

pt-Point2D -The carriage is positioned on the contour at the closest position to this point



ContourCarriage( integer span_index, double parameter)

Creates a ‘carriage’ for a contour and set its positions for the span with the passed index at the passed parameter position (in range 0-1.0) on the span. These values are normaly specified as 0,0.0 to position the carriage at the start of the first span in the contour.

span_index-integer -Index of span, carriage will be positioned at parameter-double -Parameter along span carriage will be positioned at



e.g local cursor = ContourCarriage(0, 0.0)


Properties

.IsInvalid

R/O - bool - Returns true if current position is invalid


.SpanIndex

R/O - integer - Return span index for current position of carriage


.SpanParameter

R/O - double - Return span parameter (in range 0-1.0) for current position of carriage


Methods

:Move( Contour ctr, double distance)

Moves the carriage the requested distance along the contour. Returns true if manage to move requested distance successfully. If the contour is closed we will wrap around at the end, if it is open and you attempt to move past the end this method will return false.

ctr-Contour -The contour this carriage rides along

distance - double –The distance to move along the contour, negative values will move back towards the start


:Position( Contour ctr)

Returns a Point2D representing the current position on the carriage on the passed contour

ctr-Contour -The contour this carriage rides along


:UpdatePosition( Contour ctr, Point2D pt)

Update the position of the carriage to the nearest position on the contour to the passed point.

ctr-Contour -The contour that the carriage travels along

pt-Point2D -The carriage is positioned on the contour at the closest position to this point


Example Code

| Insert a marker at each parameter step around the contour and display the | distance from the start point |

function MarkContourParameterSteps(num_steps, contour, layer)


  local cursor = ContourCarriage(0, 0.0)  


  local contour_length = contour.Length    local step_dist = contour_length / num_steps  


  local end_index = num_steps    if contour.IsOpen then       end_index = end_index + 1      end          
  for i = 1, end_index do  
    local ctr_pos = cursor:Position(contour)  
    local marker = CadMarker("D:" .. (step_dist * (i - 1)), ctr_pos, 3)           layer:AddObject(marker, true)      cursor:Move(contour, step_dist)  
     end  end  







Back.jpg

References

Please Note: The base material for the contents found in this WiKi was sourced from Vectric Lua Interface for Gadgets, version 2.05, published September 12, 2018. by Vectric Ltd. Most current document from Vertric can be downloaded at Vertric Developer Information