This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hugeblank's profile picture

Line Rendering Complications

Started by hugeblank, 24 April 2017 - 05:53 AM
hugeblank #1
Posted 24 April 2017 - 07:53 AM
So I believe I had mentioned a while back (I wasn't very adept at coding) that I was working on a little graphing API called GraphKit. I unfortunately stopped working on it due to a lack of motivation, mainly caused by some peculiar bug in my rendering function that dissatisfied me to the point of… well, giving up. I didn't touch it for the last few months, and suddenly today I had the urge to work on it again. However this time I wanted to Ask A P…Bro.

First, the installer I made for it:

pastebin run YivSuLQK
Then to run, just run "GKitProgram", this is my (incomplete) bodge of a program that would use the API
Now, Here's a breakdown of the issue:

On lines 70-101 is the function that is the cause of the issue. (called render)
As a test, I would suggest trying to graph a parabola.
1. Click Graph
2. Type in the equation (x*x) and press enter
3. type the name of the graph and press enter
4. select a color (Ex: red, green, blue. See "tocolor" API in the ".gkitprog" folder for more colors). Press enter
At this point you should see the graph show up on your screen. It should look like a parabola (shocker). You can also move around the graph by clicking "Move" and selecting the X/Y coordinates you want to move to. Everything should be working fine up until now…

Let's get to the problem. Cubic Graphs. Use the following tips as shown above for the parabola, except on step 2 use x*x*x, and on step 4, pick a different color than you parabola for viewing ease.
Everything should look perfectly normal initially, but they are not. Move the graph to X: 0, and Y: 36. You should see the parabolas sides, and then the cubic functions line in between it. Now move to X: 0, Y: 37.
Yeah, that's an issue… "Where the hell did the cubic graph go!?" ~Pissed off bagel, circa September 2016

It's so peculiar that the cubic graph just disappears off the face of the earth after that point, but the parabola still remains. Like I said above, lines 70-101 are where I believe the issue is. I beg of someone to have a jaunt through my (albeit bad) script, and just give me a heads up on what I am not doing here that would resolve this issue.

Thanks in advance,
~Your friendly Bagel
Bomb Bloke #2
Posted 24 April 2017 - 11:46 AM
Without testing the code (screenshots or a video or something would be nice), line 96 in the GraphKit API looks a bit iffy:

if y <= dy and y >= 1 or y1 <= dy and y1 >= 1 then

You're excluding any lines that extend outside of the visible display - even if part of them falls within that area.

To my mind, the way to go would be to first envision a pair of rectangles, one surrounding the area of the line, the other covering the current display area. If they overlap, render the line. Ideally you'll do that rendering using your own code, as the paintutils API won't skip over "pixels" outside the display area (Dan's got it listed as a to-do, but it's still more efficient to reduce your call count where you can, especially when writing a "renderer").

You could also stand to drop the "adapt" function. It's rather inefficient to make that block of code an extra call, especially since it queries term.getSize() every time you do, repeats the same mathematics over and over, and you never call that function from anywhere other than line 83 anyway…
Edited on 24 April 2017 - 09:47 AM
hugeblank #3
Posted 26 April 2017 - 04:24 AM
There were some inefficiencies in the code, again I wrote it ages ago, and I will make sure to fix that adapt function, as for the iffy line, that would probably be the culprit. I'll check it out when I'm not bogged down with homework :'(