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

  • SEARCH
  • Home
  • 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 8006255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:27:03+00:00 2026-06-04T17:27:03+00:00

Questions regarding NSRect…In the Hillegass book we are creating an NSRect into which we

  • 0

Questions regarding NSRect…In the Hillegass book we are creating an NSRect into which we are drawing an oval (NSBezierPath *). Depending on where in our view we mouse down and subsequently drag, the NSRect’s size.width and/or size.height may be negative (i.e. if we start in upper right, drag lower left – both are negative). When actually drawing, does the system use our negative width and/or height to merely locate the NSPoint of where we dragged? Thus updating the NSRect? And if we ever need the size of the NSRect, should we just use the absolute values?

In the chapter, the authors used the MIN() and MAX() macros to create an NSRect. However, in the challenge solution they provide these three methods in response to mouse events:

- (void)mouseDown:(NSEvent *)theEvent
{
    NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] fromView:nil];
    // Why do we offset by 0.5? Because lines drawn exactly on the .0 will end up spread over two pixels.
    workingOval = NSMakeRect(pointInView.x + 0.5, pointInView.y + 0.5, 0, 0);
    [self setNeedsDisplay:YES];
}

- (void)mouseDragged:(NSEvent *)theEvent
{
    NSPoint pointInView = [self convertPoint:[theEvent locationInWindow] fromView:nil];
    workingOval.size.width = pointInView.x - (workingOval.origin.x - 0.5);
    workingOval.size.height = pointInView.y - (workingOval.origin.y - 0.5);
    [self setNeedsDisplay:YES];
}

- (void)mouseUp:(NSEvent *)theEvent
{
    [[self document] addOvalWithRect:workingOval];
    workingOval = NSZeroRect; // zero rect indicates we are not presently drawing
    [self setNeedsDisplay:YES];
}

This code produces a successful rectangle regardless of the potential negative values. I understand that the negative values merely reflect the shift left with respect to the origin ( the point from which we “mouse downed”). What is going on behind the scenes in properly calculating the NSPoint to which we dragged?

  • 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-06-04T17:27:06+00:00Added an answer on June 4, 2026 at 5:27 pm

    An NSRect is just defined as an NSPoint and an NSSize. An NSSize is just defined as a pair of CGFloats, but the documentation says:

    Normally, the values of width and height are non-negative. The functions that create an NSSize structure do not prevent you from setting a negative value for these attributes. If the value of width or height is negative, however, the behavior of some methods may be undefined.

    In the code you show above, absolutely nothing fancy is going on behind the scenes. You’re creating a rectangle (workingOval) that happens to have a negative size or width, and you’re not actually using it anywhere.

    Depending on what you do with workingOval elsewhere, what’s going on behind the scenes will be different. But it’ll be one of three very simple things. Some methods treat a rect like (origin=(30, 40), size=(-10, -20)) as identical to (origin=(20, 20), size=(10, 20)); others treat it as an invalid rect; some make assumptions that they don’t test and just give you garbage results. For example, NSMinX will return 30, not 10.

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

Sidebar

Related Questions

two little questions regarding the UISearchBar/SearchDisplayController: Is it possible to prevent/hide the overlay which
Hi I have 2 questions regarding linux directory permissions which I do not understand.
I have got few questions regarding creating windows service. I have created a windows
I have several questions regarding CI application design. Q. When creating a new form
I have some questions regarding MVC that I would like to clarify. At our
Additional questions regarding SilentGhost's initial answer to a problem I'm having parsing Twitter RSS
I have some questions regarding the following css that I found: html, body {
I actually have two questions regarding exception/error handling in the iPhone app that I
I had some questions regarding the structure and behavior of a model, using UML,
I have couple questions regarding some C++ rules. Why am I able to call

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.