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 248263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:19:42+00:00 2026-05-11T21:19:42+00:00

I’ve got two rectangles represented by structures that contain the x1, y1, x2, y2

  • 0

I’ve got two rectangles represented by structures that contain the x1, y1, x2, y2 coordinates. One rectangle can be considered the parent, another the child.

I already know how to detect if the child rectangle is within the parent rectangle; what I’m trying to figure out now is the simplest, fastest way to determine the rectangular areas within the parent that are not being overlapped by the child rectangle.

For example, consider a 100×100 parent rectangle, and a 50×50 child rectangle located exactly in the center of the parent. This would mean there would be four rectangles representing the four areas in the parent rectangle that aren’t being overlapped by the child.

Of course, the child could be in the top left, top right, bottom left, bottom right corner, or a little to the left, a little to the right, etc… there might be one, two, three, or four rectangles that represent the non-overlapped areas.

I’ve had some ideas for implementations to figure this out, but all seem overly complex. Is there a simple, fast way to figure this out?

  • 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-11T21:19:42+00:00Added an answer on May 11, 2026 at 9:19 pm

    So there could be up to 4 rectangles of non-overlapped area. Let’s make a list of them.

    leftrect = rightrect = toprect = bottomrect = None
    trimmedparent = duplicate(parent)
    
    if parent.x1 < child.x1:
        leftrect = duplicate(parent)
        leftrect.x2 = child.x1
        trimmedparent.x1 = child.x1
    
    if parent.x2 > child.x2:
        rightrect = duplicate(parent)
        rightrect.x1 = child.x2
        trimmedparent.x2 = child.x2
    
    if parent.y1 < child.y1:
        toprect = duplicate(trimmedparent)
        toprect.y2 = child.y1
    
    if parent.y2 > child.y2:
        bottomrect = duplicate(trimmedparent)
        bottomrect.y1 = child.y2
    

    The only tricky part is eliminating the part where e.g leftrect and toprect might intersect. I used ‘trimmedparent’ as an intermediate step to trim that section from toprect.

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

Sidebar

Ask A Question

Stats

  • Questions 213k
  • Answers 213k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Usually this is based on the operating system its self.… May 12, 2026 at 10:37 pm
  • Editorial Team
    Editorial Team added an answer I don't think it puts different data in the .gcov… May 12, 2026 at 10:37 pm
  • Editorial Team
    Editorial Team added an answer Markus Müller's comment is correct, that is, your code is… May 12, 2026 at 10:37 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I want use html5's new tag to play a wav file (currently only supported

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.