from __future__ import print_function
from __future__ import absolute_import
import os
import sys
import math
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(THIS_DIR, '..'))
import sumolib
def setCircle(idx, x, y, r, c, prefix, type, color, fill, layer, output):
angle = 2 * math.pi / c
shape = ""
for i in range(c):
shape += "%.2f,%.2f " % (math.cos(i * angle) * r + x,
math.sin(i * angle) * r + y)
if i == 0:
beginPoint = shape
shape += beginPoint
print(' <poly id="%s%s" type="%s" color="%s" fill="%i" layer="%s" shape="%s"/>' % (
prefix, idx, type, color, fill, layer, shape[:-1]),
file=output)
if __name__ == "__main__":
op = sumolib.options.ArgumentParser(description="Make a circle polygon")
op.add_option("files", nargs='+', category="input", type=op.file_list,
help="List of XML files to plot")
op.add_option("-r", "--radius", type=float, default=100,
help="default radius")
op.add_option("-p", "--prefix", default="poly",
help="id prefix")
op.add_option("-t", "--type", default="unknown",
help="type string")
op.add_option("--color", default="1,0,0",
help="color string")
op.add_option("-f", "--fill", action="store_true",
default=False, help="fill the polygons")
op.add_option("-l", "--layer", type=float, default=-1,
help="layer")
op.add_option("-x", "--corners", type=int, default=100,
help="default number of corners")
op.add_option("-o", "--output-file", category="output", type=op.file,
help="output file (default: standard output)")
try:
options = op.parse_args()
except (NotImplementedError, ValueError) as e:
print(e, file=sys.stderr)
sys.exit(1)
output = sys.stdout if options.output_file is None else open(options.output_file, 'w')
print("<additional>", file=output)
for idx, d in enumerate(options.files):
desc = d.split(",")
x = float(desc[0])
y = float(desc[1])
r = float(desc[2]) if len(desc) > 2 else options.radius
c = int(desc[3]) if len(desc) > 3 else options.corners
setCircle(idx, x, y, r, c, options.prefix, options.type, options.color, options.fill, options.layer, output)
print("</additional>", file=output)