From ac0a977aeb9f21b2c77d4522859d63365c48f164 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Wed, 12 Sep 2018 10:38:02 +0200 Subject: [PATCH] Fix. --- h2/.gitignore | 244 +++++++++++++++++++++++++++++++++++++ {project2 => h2}/proj2.pdf | Bin h2/sidedness.py | 57 +++++++++ project2/sidedness.py | 53 -------- 4 files changed, 301 insertions(+), 53 deletions(-) create mode 100644 h2/.gitignore rename {project2 => h2}/proj2.pdf (100%) create mode 100644 h2/sidedness.py delete mode 100644 project2/sidedness.py diff --git a/h2/.gitignore b/h2/.gitignore new file mode 100644 index 0000000..17e588c --- /dev/null +++ b/h2/.gitignore @@ -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 \ No newline at end of file diff --git a/project2/proj2.pdf b/h2/proj2.pdf similarity index 100% rename from project2/proj2.pdf rename to h2/proj2.pdf diff --git a/h2/sidedness.py b/h2/sidedness.py new file mode 100644 index 0000000..66daeb6 --- /dev/null +++ b/h2/sidedness.py @@ -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 diff --git a/project2/sidedness.py b/project2/sidedness.py deleted file mode 100644 index 532d78c..0000000 --- a/project2/sidedness.py +++ /dev/null @@ -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 \ No newline at end of file