Skip to content

update project to python 36 #2

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Ray caster execution products
*.png

# 2to3 backups
*.bak

# PyCharm
.idea/

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
53 changes: 28 additions & 25 deletions CSG.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
from builtins import object
from geom3 import Vector3, Point3, Ray3, dot, unit
from hit import Hit


class Intersection(object):
def __init__(self, objects):
self.objs = objects
self.objs = objects

def intersect(self, ray):
hit = Hit(self, ray, None, None)
for o in self.objs:
hit = hit.intersection(o.intersect(ray))
if hit == None or hit.miss():
if self.objs.index(o) != 0:
self.objs.remove(o)
self.objs = [o] + self.objs
return None
return hit
hit = Hit(self, ray, float('-inf'), float('-inf'))
for o in self.objs:
hit = hit.intersection(o.intersect(ray))
if hit is None or hit.miss():
if self.objs.index(o) != 0:
self.objs.remove(o)
self.objs = [o] + self.objs
return None
return hit


class Union(object):
def __init__(self, objects):
self.objs = objects
self.objs = objects

def intersect(self, ray):
hit = Hit(self, ray, None, None)
for o in self.objs:
hit = hit.union(o.intersect(ray))
if hit.entry < hit.exit:
return hit
return None
hit = Hit(self, ray, float('-inf'), float('-inf'))
for o in self.objs:
hit = hit.union(o.intersect(ray))
if hit.entry < hit.exit:
return hit
return None


class Difference(object):
def __init__(self, objects):
self.objs = objects
self.objs = objects

def intersect(self, ray):
hit = self.objs[0].intersect(ray)
if hit is not None:
hit = hit.difference(self.objs[1].intersect(ray))
if hit and hit.entry < hit.exit:
return hit
return None

hit = self.objs[0].intersect(ray)
if hit is not None:
hit = hit.difference(self.objs[1].intersect(ray))
if hit and hit.entry < hit.exit:
return hit
return None
129 changes: 76 additions & 53 deletions antiAlaising.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,102 @@
from __future__ import division
from builtins import range
from builtins import object
from past.utils import old_div
from geom3 import Point3, Vector3, Ray3, cross, dot, unit, length
from colour import Colour
from math import sqrt
import random


class NoAA(object):
def __init__(self, eyepoint, rayfunc):
self.eye = eyepoint
self.rayfunc = rayfunc
self.eye = eyepoint
self.rayfunc = rayfunc

def getPixel(self, pixelBox):
(x, y, x2, y2) = pixelBox
pixelCentre = Point3((x + x2)/2, (y2 + y)/2, 1)
ray = Ray3(self.eye, pixelCentre - self.eye)
return self.rayfunc(ray)
(x, y, x2, y2) = pixelBox
pixelCentre = Point3(old_div((x + x2), 2), old_div((y2 + y), 2), 1)
ray = Ray3(self.eye, pixelCentre - self.eye)
return self.rayfunc(ray)


class SuperSampling(object):
def __init__(self, eyepoint, rayfunc, subPixels=4):
self.eye = eyepoint
self.rayfunc = rayfunc
self.subPixels= int(sqrt(subPixels))
self.eye = eyepoint
self.rayfunc = rayfunc
self.subPixels = int(sqrt(subPixels))

def getPixel(self, pixelBox):
(x, y, x2, y2) = pixelBox
pitch = (x2 - x)/ (self.subPixels * 2)
xx = x
yy = y
count = 0
colour = Colour(0,0,0)
for col in range(self.subPixels):
for row in range(self.subPixels):
colour += self.rayfunc(Ray3(self.eye, (Point3(xx + pitch,yy + pitch,1) - self.eye)))
(x, y, x2, y2) = pixelBox
pitch = old_div((x2 - x), (self.subPixels * 2))
xx = x
yy = y
count = 0
colour = Colour(0, 0, 0)
for col in range(self.subPixels):
for row in range(self.subPixels):
colour += self.rayfunc(Ray3(self.eye,
(Point3(xx + pitch, yy + pitch, 1) - self.eye)))
count += 1
yy += pitch * 2
yy = y
xx += pitch * 2
assert count == self.subPixels * self.subPixels
return colour / count
yy += pitch * 2
yy = y
xx += pitch * 2
assert count == self.subPixels * self.subPixels
return old_div(colour, count)


class Jitter(object):
def __init__(self, eyepoint, rayfunc, subPixels=4):
self.eye = eyepoint
self.rayfunc = rayfunc
self.subPixels= int(sqrt(subPixels))
self.eye = eyepoint
self.rayfunc = rayfunc
self.subPixels = int(sqrt(subPixels))

def getPixel(self, pixelBox):
(x, y, x2, y2) = pixelBox
pitch = (x2 - x)/ self.subPixels
xx = x
yy = y
count = 0
colour = Colour(0,0,0)
for col in range(self.subPixels):
for row in range(self.subPixels):
colour += self.rayfunc(Ray3(self.eye, (Point3(xx + random.uniform(0, pitch) ,yy + random.uniform(0, pitch),1) - self.eye)))
(x, y, x2, y2) = pixelBox
pitch = old_div((x2 - x), self.subPixels)
xx = x
yy = y
count = 0
colour = Colour(0, 0, 0)
for col in range(self.subPixels):
for row in range(self.subPixels):
colour += self.rayfunc(
Ray3(
self.eye,
(Point3(
xx +
random.uniform(
0,
pitch),
yy +
random.uniform(
0,
pitch),
1) -
self.eye)))
count += 1
yy += pitch
yy = y
xx += pitch
assert count == self.subPixels * self.subPixels
return colour / count
yy += pitch
yy = y
xx += pitch
assert count == self.subPixels * self.subPixels
return old_div(colour, count)


class Jitter2(object):
def __init__(self, eyepoint, rayfunc, subPixels=4):
self.eye = eyepoint
self.rayfunc = rayfunc
self.subPixels= subPixels
self.eye = eyepoint
self.rayfunc = rayfunc
self.subPixels = subPixels

def getPixel(self, pixelBox):
(x, y, x2, y2) = pixelBox
pixSize = x2 - x
colour = Colour(0,0,0)
for i in range(self.subPixels):
colour += self.rayfunc(Ray3(self.eye, (Point3(random.uniform(x,x2) ,random.uniform(y,y2),1) - self.eye)))
return colour / self.subPixels



(x, y, x2, y2) = pixelBox
pixSize = x2 - x
colour = Colour(0, 0, 0)
for i in range(self.subPixels):
colour += self.rayfunc(
Ray3(
self.eye, (Point3(
random.uniform(
x, x2), random.uniform(
y, y2), 1) - self.eye)))
return old_div(colour, self.subPixels)
Loading