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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:43:14+00:00 2026-05-26T02:43:14+00:00

I have a function where I try to find a matching Point between 2

  • 0

I have a function where I try to find a matching Point between 2 collections of 4 Points each, but sometimes the function reports the collections do not share a common Point even though in the debugger I see they do. is the debugger not showing me the full precision of the points so I do not see the difference? or is there something else going on here? here’s the code to blame:

public static Point CorrectForAllowedDrawArea(Point previousDisplayLocation, Point newDisplayLocation, Rect displayLimitedArea, Rect newBoundingBox)
{
    // get area that encloses both rectangles
    Rect enclosingRect = Rect.Union(displayLimitedArea, newBoundingBox);
    // get corners of outer rectangle, index matters for getting opposite corner
    var outsideCorners = new[] { enclosingRect.TopLeft, enclosingRect.TopRight, enclosingRect.BottomRight, enclosingRect.BottomLeft }.ToList();
    // get corners of inner rectangle
    var insideCorners = new[] { displayLimitedArea.TopLeft, displayLimitedArea.TopRight, displayLimitedArea.BottomRight, displayLimitedArea.BottomLeft }.ToList();
    // get the first found corner that both rectangles share
    Point sharedCorner = outsideCorners.FirstOrDefault((corner) => insideCorners.Contains(corner));
    // find the index of the opposite corner
    int oppositeCornerIndex = (outsideCorners.IndexOf(sharedCorner) + 2) % 4;

on the last line ‘sharedCorner’ is sometimes set to default(Point) even though both Point collections appear to share 1 Point.

EDIT: I should mention if I place the debugger back to the top of the function and restart it still does not find the matching point. I should also mention that this function uses the Point class of the System.Windows namespace and not of the System.Drawing namespace! Thanks for pointing this out to me in the comments.

  • 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-26T02:43:14+00:00Added an answer on May 26, 2026 at 2:43 am

    We really need to see what the definition of insideCorners.Contains(corner) is, but I suspect that your problem is due to the inherent inaccuracies with floating point numbers.

    You cannot compare two floating point values like this:

    if (a == b)
    {
        // Values are equal
    }
    

    especially if either a or b are calculated values.

    You’ll need to implement something along the lines of:

    if (Math.Abs(a - b) < some_small_value)
    {
        // Values are equal
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some content from server using $.ajax() function. I try to replace some
I have that function: $(#tabela tr).toggle(function(){ $(this).addClass(zaznaczone); $(this).find( :checkbox).attr(checked, 1); },function(){ $(this).removeClass(zaznaczone); $(this).find( :checkbox).attr(checked,
I have a function in Ruby: def find_item(keyword) potential = [] $items.each do |item|
I have a JavaScript function named openDatabase() that starts with: function openDatabase() { try
I have this function: function! Find(name) let l:list=system(find . -name '.a:name.' | perl -ne
I have some code that used to work. But I today when I try
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
I have function getCartItems in cart.js and I want to call that function in
If I have function names stored as strings in a Hashtable. Is there a

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.