Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I would like to paint big squares on an inkcanvas. I define the brush size to 20 and the form as a rectangle. But I do not want the squares overlap. They must always be one above the other or one beside the other.
How to do that ?
Thans in advance.
Posted

1 solution

1) Store all your existing squares' co-ordinates in a List<RectangleF>
2) Create a new possible square.
3) Iterate over all existing squares looking for overlaps (RectangleF.Intersects() may help)]
4) One overlap is enough to render this potential square unusable, try the next one.
 
Share this answer
 
Comments
daphne35 30-Jan-14 4:29am    
Thank you for your reply. I want this verification takes place at the same time the plot. You think it will work?
Moreover squares are part of the Strokes, I can get the coordinates of each square of the Stroke?
Thanks
lukeer 30-Jan-14 7:53am    
I'm just realizing that you've tagged this a WPF question. Unfortunately, I'm of no help with everything WPF specific. Adding to that, I'm having some difficulty understanding what exactly you're asking. However, if you're trying to build a straight line from squares, Bresenham's line algorithm[^] could be for you. Plus, there's also a version for circles.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900