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

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

from math import cos, sin, pi, sqrt

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]