mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-05 17:07:11 +02:00
51 lines
979 B
C
51 lines
979 B
C
/*
|
|
* misc.c - Helper functions for geometry and attributes
|
|
*
|
|
* Written 2016 by Werner Almesberger
|
|
* Copyright 2016 Werner Almesberger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
static bool eq(int m[6], int xx, int xy, int yx, int yy)
|
|
{
|
|
return m[1] == xx && m[2] == xy && m[4] == yx && m[5] == yy;
|
|
}
|
|
|
|
|
|
unsigned matrix_to_angle(int m[6])
|
|
{
|
|
if (eq(m, 1, 0, 0, -1))
|
|
return 0;
|
|
if (eq(m, 0, -1, -1, 0))
|
|
return 90;
|
|
if (eq(m, -1, 0, 0, 1))
|
|
return 180;
|
|
if (eq(m, 0, 1, 1, 0))
|
|
return 270;
|
|
fprintf(stderr, "unrecognized matrix %d %d %d %d\n",
|
|
m[1], m[2], m[4], m[5]);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
int angle_add(int a, int b)
|
|
{
|
|
a += b;
|
|
while (a < 0)
|
|
a += 360;
|
|
return a % 360;
|
|
}
|
|
|