Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed a few things in sphere, cylinder and functions. #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pierrebai
Copy link

Added new Paths implementations. Made the one in function.go pluggable at run-time.

@fogleman
Copy link
Owner

Very cool!

My intention with the API was to do it as described here:

https://github.com/fogleman/ln#custom-texturing

That is, creating a "subclass" that overrides Paths() instead of passing in a Paths() implementation. You can also see OutlineSphere as an example of that.

I am interested in integrating your work but would like to head that direction. Do you think you can refactor your pull request with that in mind? Also, thanks for renaming my bad ones like Paths2(), Paths3() 😄

func RandomUnitVector() Vector {
for {
x := rand.Float64()*2 - 1
y := rand.Float64()*2 - 1
z := rand.Float64()*2 - 1
if x*x+y*y+z*z > 1 {
if x == 0 && y == 0 && z == 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change would result in some bias in the random vectors.

@fogleman
Copy link
Owner

Part of the thinking behind doing it that way was so the subclass could include other configuration / parameters. For example a GridFunction type could include parameters for the grid size.

@pierrebai
Copy link
Author

Hi,

TBH, this code is actually a backport of my Python port of ln. I did that because I initially didn't have go installed and wanted to try to port it to see how it would go. Turns out Python is much slower than compiled go, so what gain I have not compiling is lost at runtime.

Anyway, that's why I had this pluggable-function approach, since it is easy and natural in Python. Other changes I did were in line with your recent changes: refactor out cairo for another lib. (I had used vmimg.)

As such, my pull rquest was already a refactor of a backport from Python, so feel free to simply rewrite my changes as you see fit. I don't think I'll be very active anyway.

@pierrebai
Copy link
Author

BTW, FWIW, my port to Python revealed two potential issues with the code that I didn't backport:

  1. in csg.go, you can have an infinite recursion in Intersect() for boolean shapes. I replaced the recursive calls with a loop in Python to at least not blow the stack. (Maybe go optimize tail calls?)
  2. There are a few places where you end-up dividing by zero. Seems in go it just produces NaN, but in Python it threw exceptions, so I had to add checks in a few places and produce NaN by hand. I don't know if it was intentional to leave those divide-by-zero in there.

@fogleman
Copy link
Owner

Cool, thanks for the info!

@pierrebai
Copy link
Author

I have done some refactorization: created multiple function sub-classes and put back the random vector stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants