Page 1 of 1

[sovled] coordinates (x2,y2) during drawing ?

Posted: Sat Dec 15, 2007 5:36 pm
by exkor
Hello
I'm thinking what is the best way to specify coordinates in drawing functions?

1st) drawRectangle(x1, y1, x2, y2)
or
2nd) drawRectangle(x1, y1, cx, cy)

cx & cx are lengtha while x1, y1 coordinates
x2 = x1+cx

Problem 1
- In 1st case if x1=x2 I don't know if caller wants 1 line or no lines at all but if x1=x2+1 this is definitely 2 lines I think
- if cx,cy is used I know: no lines if cx=0, 1 line if cx=1 ..., and user has choice: 1 line/no lines
Problem 2
and the 2nd problem is that I have to validate coordinates.
If I would use lengths(cx,cy) the caller would have choice to do validation or not depending on his design. If lines/rectangles are just coordinates saved in memory that are known to be good and only need to be drawn fast then doing validation in function would result in considerable performance decrease.

my functions do clipping if anybody wonders but that separate thing

currently each of my drawing function has following check which slows function(especially if small rectangle/line)

Code: Select all

;input:  ecx-x1 edx-y1   edi-x2 esi-y2

  sub  edi, ecx       ;x2-x1
  jc   .neg_dx
  sub  esi, edx       ;y2-y1
  jnc  .dx_dy_positive
.neg_dx:
  neg  edi            ;make dx positive
  sub  ecx, edi       ;ecx = mininum x
  sub  esi, edx       ;y2-y1
  jnc  .dx_dy_positive
.neg_dy:
  neg  esi            ;make dy positive
  sub  edx, esi       ;edx = mininum y
.dx_dy_positive:

  ;ECX = min x   EDX = min y   EDI = dx   ESI = dy     
I do need dx & dy because drawing loops check for flags

Which one would it be best to use and which one more convenient for user(for you):
1st) drawRectangle(x1, y1, x2, y2)
or
2nd) drawRectangle(x1, y1, cx, cy)

EDIT:
ok, I decided on the following(and sorry for the post):

Code: Select all

;input:  ecx-x1 edx-y1   edi-x2 esi-y2
drawRect1:
  push eax ebx ecx
  jmp short dx_dy_positive
drawRect2:
  push eax ebx ecx

dx_dy_positive:
  ;ECX = min x   EDX = min y   EDI = dx   ESI = dy 

  pop ecx ebx eax
ret
driver will export both functions