summaryrefslogtreecommitdiff
path: root/gerberex/utility.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-06-06 13:28:42 +0200
committerjaseg <git@jaseg.de>2021-06-06 13:28:42 +0200
commit889ea37d9b66cbfb7a61795c7750b9f4311faa3f (patch)
tree34db36bcdf0501445aaec30c845ed644537e638a /gerberex/utility.py
parent5a5ba2b709f01b2100cd767a25a41737541ad53c (diff)
parent71c371ca680483aa9ef18d2998832460dd43abdf (diff)
downloadgerbonara-889ea37d9b66cbfb7a61795c7750b9f4311faa3f.tar.gz
gerbonara-889ea37d9b66cbfb7a61795c7750b9f4311faa3f.tar.bz2
gerbonara-889ea37d9b66cbfb7a61795c7750b9f4311faa3f.zip
Graft pcb-tools-extension master onto gerbonara main
Diffstat (limited to 'gerberex/utility.py')
-rw-r--r--gerberex/utility.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/gerberex/utility.py b/gerberex/utility.py
new file mode 100644
index 0000000..37de5e8
--- /dev/null
+++ b/gerberex/utility.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+from math import cos, sin, pi, sqrt
+
+def rotate(x, y, angle, center):
+ x0 = x - center[0]
+ y0 = y - center[1]
+ angle = angle * pi / 180.0
+ return (cos(angle) * x0 - sin(angle) * y0 + center[0],
+ sin(angle) * x0 + cos(angle) * y0 + center[1])
+
+def is_equal_value(a, b, error_range=0):
+ return (a - b) * (a - b) <= error_range * error_range
+
+def is_equal_point(a, b, error_range=0):
+ return is_equal_value(a[0], b[0], error_range) and \
+ is_equal_value(a[1], b[1], error_range)
+
+def normalize_vec2d(vec):
+ length = sqrt(vec[0] * vec[0] + vec[1] * vec[1])
+ return (vec[0] / length, vec[1] / length)
+
+def dot_vec2d(vec1, vec2):
+ return vec1[0] * vec2[0] + vec1[1] * vec2[1] \ No newline at end of file