Results 1 to 6 of 6

Thread: Simplifying

  1. #1
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default Simplifying

    Can I simplify this further?
    SCAR Code:
    If da > 0 then
      Begin
        If T<180 then
        Begin
          If ((Fx < 0) and (Fy < Ny)) or ((Fx > 0) and (Fy < -1 * Ny)) then dA:=dA + 180;
        End else
        Begin
          If ((Fx < 0) and (Fy > -1 * Ny)) or ((Fx > 0) and (Fy > Ny)) then dA:=dA + 180;
        End;
      End;

    I know that
    SCAR Code:
    If a then b
      else
        c;
    is possible.
    but can
    SCAR Code:
    if e then c;
    replace the b?


    EDIT: I fixed the problem in the second embed, its still the same but I replaced "c end;" with "c;" which is correct but my question remains the same. I hope you guys can see what am on about.


    EDIT 2: I realized my example can but I couldn't get it to work with what I have in the first embed. so it would be a if ..then within a if..then and within a if..then without begin and end if the final then ends up with a procedure like this;. Yeah this thing is a bit hard to explain.. I just want to see if i can save some space
    Last edited by Main; 02-03-2011 at 05:22 AM.
    Oh Hai Dar

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    It can be shortened, one sec.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Simba Code:
    if (da < 0) then
        Exit;
      if ((((Fx < 0) and (Fy < Ny)) or ((Fx > 0) and (Fy < -1 * Ny)) and (T < 180)) or (((Fx < 0) and (Fy > -1 * Ny)))) or (((Fx > 0) and (Fy > Ny)) and (T >= 180)) then
        IncEx(dA, 180);

  4. #4
    Join Date
    Feb 2009
    Location
    AZ, USA
    Posts
    460
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Simba Code:
    if (T < 180) then n := 1 else n := -1;
    if dA > 0 then
    begin
      if (Fx < 0) and (n * Fy < Ny) then dA := dA + 180;
      if (Fx > 0) and (-n * Fy > Ny) then dA := dA + 180;
    end;

    This is cleanest, imo. (I'm pretty sure it works )
    You could also replace the n's with Sin(T)/Abs(Sin(T)) (degrees, not radians!) and remove the first if..then statement, but that would probably take longer and will give an error if T = 180 (If it never will be then you can also just replace the first if..then statement with n := Sin(T)/Abs(Sin(T)), but again that'd probably be slower)
    Last edited by Ogre; 02-03-2011 at 05:49 AM.
    Is your account in an old-school random? Help SRL-OSR solve randoms!

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Yeah, I was gonna do something similar to Ogre's so nevermind .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    thanks ogre, you actually fixed a mistake where I missed a begin and end in the first embed I posted.
    Oh Hai Dar

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •