From 690df56bb71020901167605a87ec451081fa18d7 Mon Sep 17 00:00:00 2001 From: opiopan Date: Sat, 23 Mar 2019 21:59:13 +0900 Subject: add rotation fuction --- gerberex/utility.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 gerberex/utility.py (limited to 'gerberex/utility.py') diff --git a/gerberex/utility.py b/gerberex/utility.py new file mode 100644 index 0000000..852519a --- /dev/null +++ b/gerberex/utility.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2019 Hiroshi Murayama + +from math import cos, sin, pi + +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]) -- cgit From cb420e39e278f7ab6f002600a7698d7be101eb7d Mon Sep 17 00:00:00 2001 From: opiopan Date: Wed, 3 Apr 2019 00:30:00 +0900 Subject: fix a rotaion issue --- gerberex/utility.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gerberex/utility.py') diff --git a/gerberex/utility.py b/gerberex/utility.py index 852519a..f90df96 100644 --- a/gerberex/utility.py +++ b/gerberex/utility.py @@ -11,3 +11,11 @@ def rotate(x, y, angle, center): 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 <= error_range and a - b >= -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) -- cgit From e3c59e39cf9bc64ce9d76c324b82956a65515f16 Mon Sep 17 00:00:00 2001 From: opiopan Date: Sun, 7 Apr 2019 22:22:33 +0900 Subject: expand test and fix many issues --- gerberex/utility.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gerberex/utility.py') diff --git a/gerberex/utility.py b/gerberex/utility.py index f90df96..4c89fa6 100644 --- a/gerberex/utility.py +++ b/gerberex/utility.py @@ -13,8 +13,7 @@ def rotate(x, y, angle, center): sin(angle) * x0 + cos(angle) * y0 + center[1]) def is_equal_value(a, b, error_range=0): - return a - b <= error_range and a - b >= -error_range - + 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 \ -- cgit From 244fcaa5346f4fad819cc2b72857cfb2c472944a Mon Sep 17 00:00:00 2001 From: Hiroshi Murayama Date: Sat, 28 Dec 2019 23:45:33 +0900 Subject: add a function that generate filled gerberdata with representing internal shape by fliping polarity --- gerberex/utility.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gerberex/utility.py') diff --git a/gerberex/utility.py b/gerberex/utility.py index 4c89fa6..37de5e8 100644 --- a/gerberex/utility.py +++ b/gerberex/utility.py @@ -3,7 +3,7 @@ # Copyright 2019 Hiroshi Murayama -from math import cos, sin, pi +from math import cos, sin, pi, sqrt def rotate(x, y, angle, center): x0 = x - center[0] @@ -18,3 +18,10 @@ def is_equal_value(a, b, error_range=0): 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 -- cgit