00001 """
00002 Copyright 2008 Free Software Foundation, Inc.
00003 This file is part of GNU Radio
00004
00005 GNU Radio Companion is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009
00010 GNU Radio Companion is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00018 """
00019
00020
00021
00022
00023 def get_angle_from_coordinates((x1,y1), (x2,y2)):
00024 """!
00025 Given two points, calculate the vector direction from point1 to point2, directions are multiples of 90 degrees.
00026 @param (x1,y1) the coordinate of point 1
00027 @param (x2,y2) the coordinate of point 2
00028 @return the direction in degrees
00029 """
00030 if y1 == y2:
00031 if x2 > x1: return 0
00032 else: return 180
00033 else:
00034 if y2 > y1: return 270
00035 else: return 90
00036
00037 def xml_encode(string):
00038 """
00039 Encode a string into an xml safe string by replacing special characters.
00040 @param string the input string
00041 @return output string with safe characters
00042 """
00043 string = str(string)
00044 for char, safe in (
00045 ('&', '&'),
00046 ('<', '<'),
00047 ('>', '>'),
00048 ('"', '"'),
00049 ("'", '''),
00050 ): string = string.replace(char, safe)
00051 return string
00052