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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:01:21+00:00 2026-05-21T17:01:21+00:00

I have a method that is performing some arithmetic on a set of UIViews

  • 0

I have a method that is performing some arithmetic on a set of UIViews and their transformations. The unit test is expecting a specific answer; the program is kicking out a answer that is off by .0001 which just sounds like a minor rounding issue that I can deal with. What is the best way to deal with this? Is there a way to be less strict? Should I get pickier about the comparison and expect them to match perfectly?

The relevant code:

//the unit test
CGRect rect0 = CGRectMake(100, 100, 100, 100);
CGRect rect1 = CGRectMake(111, 111, 111, 111);
CGRect rect2 = CGRectMake(-200, -200, 2000, 2000);
CGRect rect3 = CGRectMake(333, -333, 333, 3333);
CGRect rect4 = CGRectMake(4, 4, 4, -4);
CGRect rect5 = CGRectMake(-54, 55, 55, -5555);

CGAffineTransform trans0 = CGAffineTransformIdentity;
CGAffineTransform trans1 = CGAffineTransformIdentity;
CGAffineTransform trans2 = CGAffineTransformMakeScale(2, 2);
CGAffineTransform trans3 = CGAffineTransformMakeScale(-5, 20);
CGAffineTransform trans4 = CGAffineTransformMakeRotation(M_PI / 2);
CGAffineTransform trans5 = CGAffineTransformMakeRotation(34);

CGRect rect0_1 = CGRectUnion(rect0, rect1);
CGRect rect0_2 = CGRectUnion(rect0, CGRectApplyAffineTransform(rect2, trans2));
CGRect rect0_3 = CGRectUnion(rect0, CGRectApplyAffineTransform(rect3, trans3));
CGRect rect0_4 = CGRectUnion(rect0, CGRectApplyAffineTransform(rect4, trans4));
CGRect rect0_5 = CGRectUnion(rect0, CGRectApplyAffineTransform(rect5, trans5));

.
.
.

rectTest = CGRectZero;
rectExpected = rect0_5;
STAssertNoThrow(rectTest = self.testCanvas.selectionBounds, @"Exception when retrieving selection bounds");
STAssertTrue(CGRectEqualToRect(rectTest, rectExpected), @"Selection bounds not correct: %@ vs %@", NSStringFromCGRect(rectTest), NSStringFromCGRect(rectExpected));

//the relevant method
- (CGRect)selectionBounds {
    CGRect selectionRect = CGRectZero;
    CGRect layerFrame;
    NSSet *layers = [self selectedLayers]; //TODO should this be optomized out?
    for(UIView *layer in layers) {
        CGPoint center = CGPointApplyAffineTransform(layer.center, layer.transform);
        layerFrame = layer.bounds;
        layerFrame = CGRectApplyAffineTransform(layerFrame, layer.transform);
        layerFrame = CGRectOffset(layerFrame, center.x - CGRectGetMidX(layerFrame), center.y - CGRectGetMidY(layerFrame));
        if(CGRectIsEmpty(selectionRect)) {
            selectionRect = layerFrame;
        } else {
            selectionRect = CGRectUnion(selectionRect, layerFrame);
        }
    }
    return selectionRect;
}

//the output
[snip]: error: -[CanvasTests testSelectionBounds] : "CGRectEqualToRect(rectTest, rectExpected)" should be true. Selection bounds not correct: {{-29.9481, -75.2419}, {2985.73, 4742.91}} vs {{-29.9481, -75.2418}, {2985.73, 4742.91}}
  • 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-21T17:01:22+00:00Added an answer on May 21, 2026 at 5:01 pm

    What is the best way to deal with this? Is there a way to be less strict?

    write a comparison function which allows suitable tolerance.

    Should I get pickier about the comparison and expect them to match perfectly?

    in this case, i would say that the tolerance/difference you observe is acceptable (after all, it’s fp, and an deviation you have said stated is acceptable).

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

Sidebar

Related Questions

I have a method that does some IO, and I'd like to limit the
I have a method that searches a list of objects based on some of
I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to
I have a method that can return either a single object or a collection
I have a method that takes an IQueryable. Is there a LINQ query that
I have a method that periodically (e.g. once in every 10 secs) try to
I have a method that's about ten lines of code. I want to create
I have a method that needs to accept an array of country names, and
I have a method that creates a MessageDigest (a hash) from a file, and

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.