PDA

View Full Version : cVec thinBasic math vector class



kryton9
10-05-2017, 02:11
I made a math vector class for thinBasic. It is focused on ease of use rather than efficiency. I based a lot of the methods of the class from the Processing language, hope that it might bring more users to thinBasic. Because of name conflicts in thinBasic I had to change my method names, but the functional use is there. You can download a zip from github here:

https://github.com/kryton9/thinBasic-cVec

cVec.tbasicu is the include file needed to use this class.

cVecUnitTests.tbasic is a complete unit test of this class. A good way to see the use of all the methods.
testcVecOutMethod.tbasic is a test focused more in depth on the out method of the class.

all tests green thanks to Primo
9692

You don't need Git to use these files. Just follow the link and click on the following to download a zip file of all the needed code:
Click image for larger version.
9689

Michael Hartlef
10-05-2017, 06:49
Because of name conflicts in thinBasic I had to change my method names, but the functional use is there.

Thanks, that is awesome. But why would there be a name conflict. These are methods of a class. Not functions.

ErosOlmi
10-05-2017, 10:22
Thanks a lot for using GitHub.
This improve thinBasic visibility.



Do you know ... #INCLUDE also works loading data directly from a web page.
If in GitHub you go into your source code file https://github.com/kryton9/thinBasic-cVec/blob/master/cVec.tbasicu and click on raw, you will get direct file link and you can use into a script.
Of course you need to be connected on internet.

Example:



Uses "Console"
#INCLUDE "https://raw.githubusercontent.com/kryton9/thinBasic-cVec/master/cVec.tbasicu"


' a 3d vector
Dim t As cVec 10.12345678, 23.12345678, 5.12345678
PrintL "Testing out function for 3d vectors"
t.out ' no parameters prints default 2 decimals, x and y and z
t.out 1 ' prints 1 decimal, x and y and z
t.out 2 ' prints 2 decimals, x and y and z
t.out 3 ' prints 3 decimals, x and y and z
t.out 4 ' prints 4 decimals, x and y and z
t.out 5 ' prints 5 decimals, x and y and z
PrintL
PrintL


' a 2d vector
Dim p As cVec 2.12345678, 12.12345678
PrintL "Testing out function for 2d vectors"
p.out ' no parameters prints default 2 decimals, x and y
p.out 1 ' prints 1 decimal, x and y
p.out 2 ' prints 2 decimals, x and y
p.out 3 ' prints 3 decimals, x and y
p.out 4 ' prints 4 decimals, x and y
p.out 5 ' prints 5 decimals, x and y
PrintL




PrintL "Press a key to end program"
WaitKey

kryton9
10-05-2017, 11:34
@Eros I had no idea, that is really cool to be able to do that. I will update my code, so it will be there as an option commented out.

@Michael That is what I thought, but I was getting errors with name conflicts with keywords.

kryton9
10-05-2017, 12:24
All updated and working.
http://www.thinbasic.com/community/showthread.php?12764-cVec-thinBasic-math-vector-class&p=93522&viewfull=1#post93522

Petr Schreiber
11-05-2017, 18:56
Hi Kent,

thanks a lot for this contribution!

I run into odd thingy - when I clone your repository, all files are immediately marked as changed.
Did you perform any specific setup of git on your PC by any chance? :)

Steps to replicate:


git clone https://github.com/kryton9/thinBasic-cVec.git
git status



Petr

kryton9
11-05-2017, 20:48
Petr, github had driven me nuts. I tried both the desktop program and the command line shell, but I found many times it would say things were fine but when I manually checked the latest version was not where it should be.

So, I deleted the repositories and recreated but from then on have been manually uploading files and downloading them using the buttons
on the webpage at github.

This works best for me, but not great if working together with anyone else.

Petr Schreiber
12-05-2017, 09:06
Hmm,

Kent, I will guide you through GitHub desktop application step by step. We need to crack this down!

For now, I would recommend to download the latest files, delete the repository (in Settings), create new with the same name and open it in GitHub for Desktop.
Once you reach this point, let me know here and I will guide you further. Deal?


Petr

kryton9
12-05-2017, 13:45
I have done that Petr many times already, believe me. I will focus on the command line as you can do more there than with Desktop program. That is why I switched to the command line because it told me in the desktop program that it did all it could do and the rest would need to be done by command line.


Thanks for help offer.
I will do as you said and delete the repositories again and not upload manually.
Will post here when that is finished.

kryton9
12-05-2017, 15:02
...
Once you reach this point, let me know here and I will guide you further. Deal?
Petr
I am finished recreating the repositories Petr. I did notice, one of the repositories worked as expected, but the other didn't doing the same thing... I then realized it took 4 minutes for the second repository to show up. So perhaps my previous problems were not seeing the changes right away. I did use the GitHub Program.

Michael Hartlef
12-05-2017, 21:05
Yes, I noticed it too with Github, sometimes you need to wait a little. The changes don't show up right away.

Petr Schreiber
12-05-2017, 21:45
I get the same "changed" state with vec3, even in its reborn form. Pure. Mystery :cray:

I could give pull request to normalize it my way... but then I wonder what happens to Kent :D


Petr

kryton9
12-05-2017, 22:14
Petr, I downloaded zips of the repositories, so if you need to request to pull, go ahead, if it messes me up, I will be ok with backups.

Michael thanks for letting me know you noticed similar behavior, this way I know it is not something on my end.

Petr Schreiber
12-05-2017, 23:06
Kent,

I restarted the Git client and the problem is gone! So I could prepare pull request for you, here:
https://github.com/kryton9/thinBasic-cVec/pull/1

It basically keeps the same functionality (unit tests are passing) while reducing code complexity.


Petr

kryton9
12-05-2017, 23:15
Kent,

I restarted the Git client and the problem is gone! So I could prepare pull request for you, here:
https://github.com/kryton9/thinBasic-cVec/pull/1

It basically keeps the same functionality (unit tests are passing) while reducing code complexity.


Petr

Thanks Petr, superb job. Really cleaned it up, thanks so much!