ContourGroup: Difference between revisions
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
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. | ||
Line 81: | Line 81: | ||
Example Code | ====Example Code==== | ||
<nowiki> | |||
[[ -------------- MarkContourParameterSteps --------------------------------- | | [[ -------------- MarkContourParameterSteps --------------------------------- | | ||
| Insert a marker at each parameter step around the contour and display the | | Insert a marker at each parameter step around the contour and display the | ||
| distance from the start point | | distance from the start point | ||
| ]] | | ]] | ||
function MarkContourParameterSteps(num_steps, contour, layer) | function MarkContourParameterSteps(num_steps, contour, layer) | ||
local cursor = ContourCarriage(0, 0.0) | local cursor = ContourCarriage(0, 0.0) | ||
local contour_length = contour.Length | |||
local step_dist = contour_length / num_steps | |||
local end_index = num_steps | |||
local contour_length = contour.Length local step_dist = contour_length / num_steps | if contour.IsOpen then | ||
end_index = end_index + 1 | |||
end -- if end | |||
local end_index = num_steps if contour.IsOpen then | |||
for i = 1, end_index do | for i = 1, end_index do | ||
local ctr_pos = cursor:Position(contour) | local ctr_pos = cursor:Position(contour) | ||
local marker = CadMarker("D:" .. (step_dist * (i - 1)), ctr_pos, 3) | |||
local marker = CadMarker("D:" .. (step_dist * (i - 1)), ctr_pos, 3) layer:AddObject(marker, true) cursor:Move(contour, step_dist) | layer:AddObject(marker, true) | ||
cursor:Move(contour, step_dist) | |||
end -- for end | |||
end -- function end | |||
</nowiki> | |||
Line 126: | Line 120: | ||
[[File:Back.jpg|right|50px|link=Creating Vectors From Script]] | [[File:Back.jpg|right|50px|link=Creating Vectors From Script]] | ||
==References== | ==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 [https://gadgets.vectric.com/developerinfo.html Vertric Developer Information] | '''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 [https://gadgets.vectric.com/developerinfo.html Vertric Developer Information] |
Latest revision as of 12:04, 30 August 2024
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
[[ -------------- MarkContourParameterSteps --------------------------------- | | 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 -- if 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 -- for end end -- function end
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