# User Inputs: Bounding Box, best practice?

I am creating a function in matlab that takes in two lat/long coordinates (opposite corners of a rectangle) and returns information about data in the region.

How do I group my inputs?

e.g. [lat1,long1] and [lat2,long2]; or [lat1,lat2], [long1,long2].

To make it easy on the user I currently have the lats and longs grouped together like the latter example, but am thinking the former is a bit more appropriate for science/math.

It depends, of course, on the semantics that the user of your function would expect, based on the domain. With `lat1, long1, lat2, long2` you’re essentially taking two points: `lat1, long1` and `lat2, long2`.

``````  *-(lat1, long1)     --+
|                     |

|                     |
+--                  -* (lat2, long2)
``````

Whereas with `lat1, lat2, long1, long2`, you’re taking 4 axis bounds: the top, bottom, left, and right. I’ve never seen this before, but I can imagine it might be common in some domains, or for example when using interval arithmetic.

``````  |                     |
-+---------lat1--------+-
|                     |
|                     |
long1                 long2
|                     |
|                     |
-+---------lat2--------+-
|                     |
``````

I don’t know how Matlab deals with types, but in a conventional imperative language I would expect functions to take arguments of more descriptive types, for example:

``````Info rect_info(Point top_left, Point bottom_right)
Info area_info(Range vertical, Range horizontal)
``````

It’s also worth considering terminology. Two arbitrary numbers are not necessarily a `Point`, but you can represent a `Point` with them—if your API takes numbers when it wants points, then you’re exposing implementation details to the user. You could go a step further—two arbitrary `Point`s are not necessarily a `Rectangle`, and two arbitrary `Range`s are not necessarily an `Area`.

• Yes, your scenarios describe this exactly. And unfortunately our user base is very small so they expect whatever I throw at them, haha (and therefore I should throw things that are commonly understoood). The matlab function is basically a wrapper to query our database, so types don't matter so much. Inputs get parsed into a query language that is then sent off. Because you say "you've never seen this before" regarding the second scenario, I'm thinking the point-based approach is best. – tenwest Sep 1 '15 at 20:41

In MATLAB a rectangle in Cartesian coordinates is typically represented as a 4-element row vector of the form [x, y, width, height], where [x,y] are the coordinates of the upper-left corner. You may consider following the same convention with latitude and longitude.

• very good to know, yes I suppose I was just looking for a standard. – tenwest Sep 17 '15 at 19:53