It's UWAweek 18 (1st semester, week 9)

help2005

This forum is provided to promote discussion amongst students enrolled in CITS2005 Object Oriented Programming.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 2 articles in this topic
Showing 2 of 112 articles.
Currently no other people reading this forum.


 UWA week 16 (1st semester, week 7) ↓
SVG not supported

Login to reply

👍x1
helpful
11:00am Mon 15th Apr, ANONYMOUS

Hi, I having trouble wrapping my head around the given answer for this question on the lms. Specifically, the part about checking if a point is within a rectangle as this is the Boolean used: return x >= this.x && x <= this.x+width && y >= this.y && y <= this.y+height; In this case above I tried running the example (-1,1) within a rectangle with dimensions: x = -2, y =2, height = 2 and width = 2. -1 >= -2 is True -1 <= -2+2 is True 1 >= 2 FALSE **********************(This is the part I'm having an issue with) 1 <= 2+2 True The point (-1,1) should be within a rectangle with these parameters correct? Or have I misinterpreted this question?


SVG not supported

Login to reply

👍?
helpful
3:17pm Tue 16th Apr, Andrew G.

ANONYMOUS wrote:

Hi, I having trouble wrapping my head around the given answer for this question on the lms. Specifically, the part about checking if a point is within a rectangle as this is the Boolean used:

return x >= this.x && x <= this.x+width && y >= this.y && y <= this.y+height;

In this case above I tried running the example (-1,1) within a rectangle with dimensions: x = -2, y =2, height = 2 and width = 2.

-1 >= -2 is True -1 <= -2+2 is True 1 >= 2 FALSE **********************(This is the part I'm having an issue with) 1 <= 2+2 True

The point (-1,1) should be within a rectangle with these parameters correct? Or have I misinterpreted this question?

This is a quirk of programming convention that was unfortunately not specified in the question: In programming, we often do geometry in "screen coordinates" such that the origin is the top left corner of the screen, with x increasing to the right and y increasing downwards. This reverses the y-axis compared to classic Cartesian coordinates. This is why the question chose the upper-left corner as the "anchor" of the rectangle.

In classic Cartesian coordinates, you are correct, (-1, 1) is within the rectangle you specified, but not in screen coordinates.

If such a question were run in a test, any reasonable coordinate system would be accepted as a valid answer, so long as you are consistent in its use.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  5:07AM Sep 06 2023
Privacy policy