Platforms to show: All Mac Windows Linux Cross-Platform
/Tools/Clipper/MinkowskiSum Test
Required plugins for this example: MBS Tools Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/Clipper/MinkowskiSum Test
This example is the version from Mon, 5th May 2019.
Project "MinkowskiSum Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
EventHandler Sub Open()
dim p as new Picture(Width, Height, 32)
dim g as Graphics = p.Graphics
dim path as ClipperPathMBS
dim pattern as ClipperPathMBS
dim solution as ClipperPathsMBS
//Greek capital sigma (sum sign) ...
dim ints1() as integer = Array( 300, 400, 100, 400, 200, 300, 100, 200, 300, 200 )
path = IntsToPolygon(ints1)
//diagonal brush pattern ...
dim ints2() as integer = Array( 4, -6, 6, -6, -4, 6, -6, 6 )
pattern = IntsToPolygon(ints2)
ClipperMBS.MinkowskiSum(pattern, path, solution, false)
//move 'pattern' to the end of 'path' ...
pattern = pattern.TranslatePath(300, 200)
//Display solution ± pattern ...
DrawPolygon g, path, &cFFFF00 // yellow for original path
DrawPolygons g, solution, &c0000FF // blue for drawing path
DrawPolygon g, pattern, &cFF0000 // red for pattern
Backdrop = p
End EventHandler
Sub DrawPolygon(g as graphics, p as ClipperPathMBS, c as color, ox as integer = 0, oy as integer = 0)
dim coordinates(0) as integer
dim points() as ClipperPointMBS = p.Values
for each point as ClipperPointMBS in points
coordinates.Append point.x + ox
coordinates.Append point.y + oy
next
g.ForeColor = c
g.FillPolygon coordinates
End Sub
Sub DrawPolygons(g as Graphics, paths as ClipperPathsMBS, c1 as color, c2 as color, ox as integer = 0, oy as integer = 0)
dim pathsList() as ClipperPathMBS = paths.Values
dim b as Boolean
for each p as ClipperPathMBS in pathsList
if b then
DrawPolygon(g, p, c2, ox, oy)
else
DrawPolygon(g, p, c1, ox, oy)
end if
b = not b
next
End Sub
Sub DrawPolygons(g as Graphics, paths as ClipperPathsMBS, c as color, ox as integer = 0, oy as integer = 0)
dim pathsList() as ClipperPathMBS = paths.Values
dim b as Boolean
for each p as ClipperPathMBS in pathsList
DrawPolygon(g, p, c, ox, oy)
b = not b
next
End Sub
Function IntsToPolygon(points() as int32) As ClipperPathMBS
dim path as new ClipperPathMBS
dim u as integer = UBound(points)-1
for i as integer = 0 to u step 2
path.Append points(i), points(i+1)
next
return path
End Function
Function IntsToPolygon(points() as int64) As ClipperPathMBS
dim path as new ClipperPathMBS
dim u as integer = UBound(points)-1
for i as integer = 0 to u step 2
path.Append points(i), points(i+1)
next
return path
End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
The items on this page are in the following plugins: MBS Tools Plugin.