summaryrefslogtreecommitdiff
path: root/gerberex/utility.py
blob: f90df967952dc3a8a829d6d8bcb59b23c67b39d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>

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])

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)