Author Topic: Clipped line routine ?  (Read 6067 times)

0 Members and 1 Guest are viewing this topic.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Clipped line routine ?
« Reply #15 on: November 17, 2012, 12:08:47 pm »
I agree with the ElseIf part (I had put it in my first routine but didn't put it in this one yet because I first wanted it to work before optimizing) but not with the -1->r1 because in the line that changes r2 needs r1 to be unchanged, so I have to change r1 only after I changed r2.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Clipped line routine ?
« Reply #16 on: November 17, 2012, 12:58:12 pm »
Oops,  you're right about that. Anyway here are some algebraic optimizations. I subbed in X for r1-r3 and Y for r2-r4 for readability but i think you'll have to put that into the code each time (or you could make a lambda out of it to save on size, but i don't know how that would affect the speed.
Code: [Select]
Lbl LINE

If r1<<0
 -Y*r3//X+r4->r2
 0->r1
ElseIf r1>94
 94-r1*Y//X+r2->r2
 94->r1
End

If r2<<0
 -X*r2//Y+r1->r1
 0->r2
ElseIf r2>62
 62-r2*X//Y+r1->r1
 62->r2
End

If r3<<0
 -Y*r3//X+r4->r4
 0->r3
ElseIf r3>94
 94-r1*Y//X+r2->r4
 94->r3
End

If r4<<0
 -X*r2//Y+r1->r3
 0->r4
ElseIf r4>62
 62-r2*X//Y+r1->r3
 62->r4
End
Line(r1,r2,r3,r4)
Return
« Last Edit: November 17, 2012, 12:58:43 pm by squidgetx »