Bug 17341 - Roundoff error causes RectangleF.Contains to fail
Summary: Roundoff error causes RectangleF.Contains to fail
Status: RESOLVED NORESPONSE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-20 19:59 UTC by 999komi
Modified: 2016-05-24 21:03 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
screen shot of code running on my mac (1.67 MB, image/png)
2014-01-21 12:44 UTC, 999komi
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description 999komi 2014-01-20 19:59:24 UTC
// Output of the code below is "does not contain."  This is wrong.  The problem is that roundoff error is causing right and bottom values
// to be slightly different from each other, and Mono determines RectangleF.Contains via equality of left, right, top and bottom.

using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using System.Diagnostics;

namespace RectangleContainsFail
{
	// The UIApplicationDelegate for the application. This class is responsible for launching the
	// User Interface of the application, as well as listening (and optionally responding) to
	// application events from iOS.
	[Register ("AppDelegate")]
	public partial class AppDelegate : UIApplicationDelegate
	{
		// class-level declarations
		UIWindow window;
		//
		// This method is invoked when the application has loaded and is ready to run. In this
		// method you should instantiate the window, load the UI into it and then make the window
		// visible.
		//
		// You have 17 seconds to return from this method, or iOS will terminate your application.
		//
		public void RectangleFContainFail() {
			RectangleF big = new RectangleF(0, 0, 100, 100);
			RectangleF small = new RectangleF(50, 50, 1.0000003f, 1.0000003f);
			bool contains = big.Contains(small);
			if (contains) {
				Debug.WriteLine ("contains");
			} else {
				Debug.WriteLine ("Does not contain");
			}
		}

		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			// create a new window instance based on the screen size
			window = new UIWindow (UIScreen.MainScreen.Bounds);
			
			// If you have defined a root view controller, set it here:
			// window.RootViewController = myViewController;
			
			// make the window visible
			window.MakeKeyAndVisible ();
			this.RectangleFContainFail ();
			return true;
		}
	}
}
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-01-21 05:07:56 UTC
I tried this both in the simulator and on a device (iPad Air), and both cases printed "contains".

Can you reproduce this both in the simulator and on a device? Which version of Xamarin.iOS are you using (you can get the version information from Xamarin Studio's About menu -> Show Details).
Comment 2 999komi 2014-01-21 12:44:17 UTC
Created attachment 5879 [details]
screen shot of code running on my mac

Xamarin Studio 4.2.2.  This particular one is from an iPad 2, but the simulator does the same thing.  MacOS 10.8.5.  See the screen shot.  It might matter whether you are working on a 32 or 64 bit system.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-01-23 12:48:34 UTC
Can you get the complete version information from Xamarin Studio's About menu (click on the "Show Details" button)?
Comment 4 Rolf Bjarne Kvinge [MSFT] 2014-01-27 07:29:11 UTC
This seems to be a dup of bug #15518.
Comment 5 Sebastien Pouliot 2016-05-24 21:03:03 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and re-open the bug report. Thanks!