Quote: "That's great work Clonkex"
Thanks
Quote: "I notice you are using the hash sign '#' after your UDT array for floats. You don't need to use them"
Now why would I want to do that?
I ALWAYS use hashes on my floats (I have very strict coding rules I impose on myself, including spacing and use of comments) so I can easily identify floats and because I find consistency to be incredibly important in coding. Thanks for telling me, though
Quote: "figuring out how it does what you want is better."
Yes! I totally agree. As it turns out...
Quote: "Finding code that does what you want is great"
...I found a faster method pre-coded (in C++) online. I'm glad I worked it out myself because now I understand the inner workings of the code. My own code wasn't anywhere near fast enough so I had to take a deep breath and dive into all the complex maths involved in the faster, more efficient methods. I survived and have one of two faster methods working perfectly (I'm still debugging the other new method). Here's the code for the Crossing Number variant (without the issues I described in an earlier post here):
function getpointinsideblob_c(posx,posy,offsetx,offsety) //crossing number variant
posx#=posx+offsetx
posy#=posy+offsety
cn=0 //crossing number counter
for i=0 to blobpointsize-1
bp1x#=blobpoint[i].posx
bp1y#=blobpoint[i].posy
bp2x#=blobpoint[blobpoint[i].connectedto].posx
bp2y#=blobpoint[blobpoint[i].connectedto].posy
if ((bp1y#<=posy#) and (bp2y#>posy#)) or ((bp1y#>posy#) and (bp2y#<=posy#))
vt#=(posy#-bp1y#)/(bp2y#-bp1y#)
if posx#<bp1x#+vt#*(bp2x#-bp1x#) then cn=cn+1
endif
next i
cn=mod(cn,2)
endfunction cn //0 = out, 1 = in
I like that one because it's small, fast and entirely self-contained. That's not quite the fastest that code could be because when I was getting it working I separated some of the variables into floats to make it divide correctly and haven't yet reduced the number of variable assignments.
It's still not quite fast enough for my liking, which forces me into the world of per-operation optimisation (like counting how many divisions are made). Unfortunately I don't know what are the slowest parts of DBPro (for example, are division operations unusually slow? Or is variable creation a big slow-down in repeated operations?) so making it faster will be a challenge and a half.
Anyway. That's what programming's about, right? And if I succeed with it all, it's not only very satisfying, it could potentially pay off enormously.
Clonkex