Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Tools/Clipper/Clipper Intersecion Test
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/Clipper/Clipper Intersecion Test
This example is the version from Wed, 9th Jan 2018.
Project "Clipper Intersecion Test.rbp"
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 subj as new ClipperPathsMBS dim clip as new ClipperPathsMBS //define outer blue 'subject' polygon subj.Append new ClipperPathMBS(array(new ClipperPointMBS(180,200), new ClipperPointMBS(260,200), new ClipperPointMBS(260,150), new ClipperPointMBS(180,150))) //define subject's inner triangular 'hole' (with reverse orientation) subj.Append new ClipperPathMBS(array(new ClipperPointMBS(215,160), new ClipperPointMBS(230,190), new ClipperPointMBS(200,190))) //define orange 'clipping' polygon clip.Append new ClipperPathMBS(array(new ClipperPointMBS(190,210), new ClipperPointMBS(240,210), new ClipperPointMBS(240,130), new ClipperPointMBS(190,130))) //draw input polygons with user-defined routine ... DrawPolygons(g, subj, &c0000FF16, &c00FF0060) //blue DrawPolygons(g, clip, &cFFFF0020, &cFF000030) //orange DrawPolygons(g, subj, &c0000FF16, &c00FF0060, -100, -100) //blue DrawPolygons(g, clip, &cFFFF0020, &cFF000030, -100, 100) //orange //perform intersection ... dim c as new ClipperEngineMBS call c.AddPaths(subj, ClipperMBS.PolyType.Subject, true) call c.AddPaths(clip, ClipperMBS.PolyType.Clip, true) dim cliptype as ClipperMBS.ClipType = ClipperMBS.ClipType.Intersection dim PolyFillType as ClipperMBS.PolyFillType = ClipperMBS.PolyFillType.NonZero dim solution as ClipperPathsMBS if c.Execute(ClipType, solution, PolyFillType, PolyFillType) then //draw solution with user-defined routine ... DrawPolygons(g, solution, &c00FF0030, &cFF006600) //solution shaded green DrawPolygons(g, solution, &c00FF0030, &cFF006600, 100) //solution shaded green with red hole end if 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
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

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Tools Plugin.




Links
MBS Xojo Plugins