Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3217878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:27:45+00:00 2026-05-17T15:27:45+00:00

I have a canvas where I can draw, resize and move rectangles around. I’m

  • 0

I have a canvas where I can draw, resize and move rectangles around.

I’m looking for an algorithm to prevent overlap and enable snapping of the rectangle I’m editing with other rectangles.

I’m tried different approaches but I couldn’t get one working properly.

All my approaches are based on a simple loop that check the rectangle I’m editing (E) with other rectangles (O[n]).

Preventing overlap is not the problem, my problem is snapping as it can modify E while iterating O.

For example, if I’m moving E near O[1] it will snap with it, but this snap might create an overlap with O[0], overlap that won’t be checked.

Before I start doing something recursive or too naïve, I was wondering if anybody knew a better approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:27:46+00:00Added an answer on May 17, 2026 at 3:27 pm

    Would a two-pass approach help, e.g.

    1. In the first pass, check E against the O’s and generate a short list of snap candidates.

    2. In the second pass, check each of the snap candidates for overlap against the O’s.

    If scanning the entire list of O’s is prohibitively expensive (the effort grows linearly with the number of objects), consider a quad-tree for storing the objects and/or their vertices. A quadtree lets you narrow down on nearby points much faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my program that can draw rectangles. I have two problems I can't
I have a canvas tag, I use it draw lines on that, the canvas
I have a canvas wich is a drawing area. This canvas can be scrolled
How can i draw a view on a canvas by giving the x,y position
I have a canvas onto which I draw shapes like rectangle etc. When I
I have a WPF canvas that I can scale, scroll and whatever. Now I
I have a drawing app where the user can draw lines with their finger,
I have a Canvas that i draw text on. (this is quite advanced i
I'm trying to draw curved arrows in a html canvas. I have no problem
I have a canvas in Flex that shall be able only to be scrolled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.