This commit is contained in:
Casper 2018-09-12 10:38:02 +02:00
parent eafd9b4be4
commit ac0a977aeb
4 changed files with 301 additions and 53 deletions

244
h2/.gitignore vendored Normal file
View File

@ -0,0 +1,244 @@
# Created by https://www.gitignore.io/api/python,pycharm,pycharm+all,pycharm+iml
### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Ruby plugin and RubyMine
/.rakeTasks
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
# Sonarlint plugin
.idea/sonarlint
### PyCharm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
# Sensitive or high-churn files:
# Gradle:
# CMake
# Mongo Explorer plugin:
## File-based project format:
## Plugin-specific files:
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# Ruby plugin and RubyMine
# Crashlytics plugin (for Android Studio and IntelliJ)
### PyCharm+all Patch ###
# Ignores the whole idea folder
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
.idea/
### PyCharm+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
# Sensitive or high-churn files:
# Gradle:
# CMake
# Mongo Explorer plugin:
## File-based project format:
## Plugin-specific files:
# IntelliJ
# mpeltonen/sbt-idea plugin
# JIRA plugin
# Cursive Clojure plugin
# Ruby plugin and RubyMine
# Crashlytics plugin (for Android Studio and IntelliJ)
### PyCharm+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
*.iml
modules.xml
.idea/misc.xml
*.ipr
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# 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/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# 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/
# End of https://www.gitignore.io/api/python,pycharm,pycharm+all,pycharm+iml

57
h2/sidedness.py Normal file
View File

@ -0,0 +1,57 @@
import random
from collections import namedtuple
from enum import Enum, auto
Point = namedtuple('Point', ['x', 'y'])
class Side(Enum):
ON = auto()
ABOVE = auto()
BELOW = auto()
def sidedness(p1, p2, p3, eps=0.00000001):
y = p1.y * (p3.x - p2.x)
x = p1.x
a = (p3.y - p2.y)
b = p3.y * (p3.x - p2.x) - a * p3.x
if y - eps < a * x + b < y + eps:
return Side.ON
elif y > a * x + b:
return Side.ABOVE
return Side.BELOW
# test
p1 = Point(4, 4)
p2 = Point(0, 0)
p3 = Point(5, 2)
# print(sidedness(p1, p2, p3))
def genPoint():
a = random.uniform(1, 10)
b = random.uniform(1, 10)
p = []
for i in range(3):
x_i = random.uniform(1, 10)
p_i = Point(x_i, a * x_i + b)
p.append(p_i)
return p
hej = genPoint()
print(hej)
print(sidedness(*hej))
def graham_scan():
3

View File

@ -1,53 +0,0 @@
import random
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y'])
def sidedness(p1, p2, p3):
eps = 0.00000001
y = p1.y*(p3.x - p2.x)
x = p1.x
a = (p3.y - p2.y)
b = p3.y*(p3.x - p2.x) - a*p3.x
if y - eps < a*x + b < y + eps:
return "ON"
elif y > a*x + b:
return "ABOVE"
else:
return "BELOW"
# test
p1 = Point(4,4)
p2 = Point(0,0)
p3 = Point(5,2)
#print(sidedness(p1, p2, p3))
def genPoint():
a = random.uniform(1, 10)
b = random.uniform(1, 10)
p = []
for i in range(3):
x_i = random.uniform(1, 10)
p_i = Point(x_i, a*x_i + b)
p.append(p_i)
return p
hej = genPoint()
print(hej)
print(sidedness(*hej))
def graham_scan():
3