Converts an SVG-rect element to a Path d-string.
    
    The rectangle will start at the (x,y) coordinate specified by the 
    rectangle object and proceed counter-clockwise.
162476
def rect2pathd(rect):
    """"""
    x0, y0 = float(rect.get('x', 0)), float(rect.get('y', 0))
    w, h = float(rect.get('width', 0)), float(rect.get('height', 0))
    x1, y1 = x0 + w, y0
    x2, y2 = x0 + w, y0 + h
    x3, y3 = x0, y0 + h

    d = ("M{} {} L {} {} L {} {} L {} {} z"
         "".format(x0, y0, x1, y1, x2, y2, x3, y3))
    return d
67475
def path(self, separator="/"):
        """"""
        rt = ""
        for i in reversed(self):
            rt = "{}{}{}".format(rt, i.name, separator)
        return rt[:-1]
1068388
function compare(pathData,opts={}) {
	var polys = svgPathToPolygons(pathData,opts);
	var minX=Infinity, maxX=-Infinity, minY=Infinity, maxY=-Infinity;
	polys.forEach(poly => {
		poly.forEach(pt => {
			if (pt[0]<minX) minX=pt[0];
			if (pt[1]<minY) minY=pt[1];
			if (pt[0]>maxX) maxX=pt[0];
			if (pt[1]>maxY) maxY=pt[1];
		});
	});
	let dx=maxX-minX, dy=maxY-minY;
	console.log(`
<svg xmlns="http://www.w3.org/2000/svg" width="${dx}px" height="${dy}px" viewBox="${minX} ${minY} ${dx*2} ${dy}">
<style>path,polygon,polyline { fill-opacity:0.2; stroke:black }</style>
<path d="${pathData}"/>
<g transform="translate(${dx},0)">
${polys.map(poly => `  <${poly.closed ? 'polygon' : 'polyline'} points="${poly.join(' ')}"/>`).join("\n")}
</g>
</svg>
	`.trim());
}
538666
def arc(document, bounding_rect, start, extent, style):
	""
	(x1, y1, x2, y2) = bounding_rect
	import math
	
	cx = (x1 + x2)/2.0
	cy = (y1 + y2)/2.0

	rx = (x2 - x1)/2.0
	ry = (y2 - y1)/2.0
	
	start  = math.radians(float(start))
	extent = math.radians(float(extent))

	# from SVG spec:
	# http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
	x1 =  rx * math.cos(start) + cx
	y1 = -ry * math.sin(start) + cy # XXX: ry is negated here

	x2 =  rx * math.cos(start + extent) + cx
	y2 = -ry * math.sin(start + extent) + cy # XXX: ry is negated here

	if abs(extent) > math.pi:
		fa = 1
	else:
		fa = 0

	if extent > 0.0:
		fs = 0
	else:
		fs = 1
	
	path = []
	# common: arc
	path.append('M%s,%s' % (x1, y1))
	path.append('A%s,%s 0 %d %d %s,%s' % (rx, ry, fa, fs, x2, y2))
	
	if style == ARC:
		pass
	
	elif style == CHORD:
		path.append('z')

	else: # default: pieslice
		path.append('L%s,%s' % (cx, cy))
		path.append('z')

	return setattribs(document.createElement('path'), d = ''.join(path))
506385
def convert_rect(self, rect):
        '''
        
        '''
        return self.container.convert_rect(rect.move(self.pos))
549627
public SVGPath drawTo(double x, double y) {
    return !isStarted() ? moveTo(x, y) : lineTo(x, y);
  }
895068
def _rect_to_css(rect):
    
    return rect.top(), rect.right(), rect.bottom(), rect.left()
748549
function poly2path(polygon) {
  var pos = polygon.pos;
  var points = polygon.calcPoints;
  var result = 'M' + pos.x + ' ' + pos.y;
  result += 'M' + (pos.x + points[0].x) + ' ' + (pos.y + points[0].y);
  for (var i = 1; i < points.length; i++) {
    var point = points[i];
    result += 'L' + (pos.x + point.x) + ' ' + (pos.y + point.y);
  }
  result += 'Z';
  return result;
}
1341317
private static Path processPoly(Element element, StringTokenizer tokens) throws ParsingException {
		int count = 0;
		
		ArrayList pts = new ArrayList();
		boolean moved = false;
		boolean reasonToBePath = false;
		Path path = null;
		
		while (tokens.hasMoreTokens()) {
			try {
				String nextToken = tokens.nextToken();
				if (nextToken.equals("L")) {
					float x = Float.parseFloat(tokens.nextToken());
					float y = Float.parseFloat(tokens.nextToken());
					path.lineTo(x,y);
					continue;
				}
				if (nextToken.equals("z")) {
					path.close();
					continue;
				}
				if (nextToken.equals("M")) {
					if (!moved) {
						moved = true;
						float x = Float.parseFloat(tokens.nextToken());
						float y = Float.parseFloat(tokens.nextToken());
						path = new Path(x,y);
						continue;
					}
	
					reasonToBePath = true;
					float x = Float.parseFloat(tokens.nextToken());
					float y = Float.parseFloat(tokens.nextToken());
					path.startHole(x,y);
					
					continue;
				}
				if (nextToken.equals("C")) {
					reasonToBePath = true;
					float cx1 = Float.parseFloat(tokens.nextToken());
					float cy1 = Float.parseFloat(tokens.nextToken());
					float cx2 = Float.parseFloat(tokens.nextToken());
					float cy2 = Float.parseFloat(tokens.nextToken());
					float x = Float.parseFloat(tokens.nextToken());
					float y = Float.parseFloat(tokens.nextToken());
					path.curveTo(x,y,cx1,cy1,cx2,cy2);
					continue;
				}
			} catch (NumberFormatException e) {
				throw new ParsingException(element.getAttribute("id"), "Invalid token in points list", e);
			}
		}
		
		if (!reasonToBePath) {
			return null;
		}
		
		return path;
	}
216300
function(plot) {
            if (plot.options.type === "square") {
                plot.options.attrs.width = plot.options.size;
                plot.options.attrs.height = plot.options.size;
                plot.options.attrs.x = plot.coords.x - (plot.options.size / 2);
                plot.options.attrs.y = plot.coords.y - (plot.options.size / 2);
            } else if (plot.options.type === "image") {
                plot.options.attrs.src = plot.options.url;
                plot.options.attrs.width = plot.options.width;
                plot.options.attrs.height = plot.options.height;
                plot.options.attrs.x = plot.coords.x - (plot.options.width / 2);
                plot.options.attrs.y = plot.coords.y - (plot.options.height / 2);
            } else if (plot.options.type === "svg") {
                plot.options.attrs.path = plot.options.path;

                // Init transform string
                if (plot.options.attrs.transform === undefined) {
                    plot.options.attrs.transform = "";
                }

                // Retrieve original boundary box if not defined
                if (plot.mapElem.originalBBox === undefined) {
                    plot.mapElem.originalBBox = plot.mapElem.getBBox();
                }

                // The base transform will resize the SVG path to the one specified by width/height
                // and also move the path to the actual coordinates
                plot.mapElem.baseTransform = "m" + (plot.options.width / plot.mapElem.originalBBox.width) + ",0,0," +
                                                   (plot.options.height / plot.mapElem.originalBBox.height) + "," +
                                                   (plot.coords.x - plot.options.width / 2) + "," +
                                                   (plot.coords.y - plot.options.height / 2);

                plot.options.attrs.transform = plot.mapElem.baseTransform + plot.options.attrs.transform;

            } else { // Default : circle
                plot.options.attrs.x = plot.coords.x;
                plot.options.attrs.y = plot.coords.y;
                plot.options.attrs.r = plot.options.size / 2;
            }
        }
1341044
function rectToPoints (rect) {
  const rectPoints = {
    topLeft: {
      x: rect.left,
      y: rect.top
    },
    bottomRight: {
      x: rect.left + rect.width,
      y: rect.top + rect.height
    }
  };

  return rectPoints;
}
997861
def _svg_path_convert(paths):
    
    def complex_to_float(values):
        return np.array([[i.real, i.imag] for i in values])

    def load_line(svg_line):
        points = complex_to_float([svg_line.point(0.0),
                                   svg_line.point(1.0)])
        if starting:
            # return every vertex and use it
            return (entities_mod.Line(np.arange(2) + len(vertices)), points)
        else:
            # we are not starting so use the last referenced vertex as the
            # start point
            return (entities_mod.Line(
                np.arange(2) + len(vertices) - 1), points[1:])

    def load_arc(svg_arc):
        points = complex_to_float([svg_arc.start,
                                   svg_arc.point(.5),
                                   svg_arc.end])
        if starting:
            # return every vertex and use it
            return (entities_mod.Arc(np.arange(3) + len(vertices)), points)
        else:
            # we are not starting so use the last referenced vertex as the
            # start point
            return (entities_mod.Arc(np.arange(3) +
                                     len(vertices) - 1), points[1:])

    def load_quadratic(svg_quadratic):
        points = complex_to_float([svg_quadratic.start,
                                   svg_quadratic.control,
                                   svg_quadratic.end])
        if starting:
            # return every vertex and use it
            return (entities_mod.Bezier(np.arange(3) + len(vertices)), points)
        else:
            # we are not starting so use the last referenced vertex as the
            # start point
            return (entities_mod.Bezier(
                np.arange(3) + len(vertices) - 1), points[1:])

    def load_cubic(svg_cubic):
        points = complex_to_float([svg_cubic.start,
                                   svg_cubic.control1,
                                   svg_cubic.control2,
                                   svg_cubic.end])
        if starting:
            # return every vertex and use it
            return (entities_mod.Bezier(np.arange(4) + len(vertices)), points)
        else:
            # we are not starting so use the last referenced vertex as the
            # start point
            return (entities_mod.Bezier(
                np.arange(4) + len(vertices) - 1), points[1:])

    # store loaded values here
    entities = []
    vertices = []
    loaders = {'Arc': load_arc,
               'Line': load_line,
               'CubicBezier': load_cubic,
               'QuadraticBezier': load_quadratic}

    for path_string, matrix in paths:
        starting = True
        for svg_entity in parse_path(path_string):
            type_name = svg_entity.__class__.__name__
            if type_name in loaders:
                e, v = loaders[type_name](svg_entity)
                entities.append(e)
                vertices.extend(transform_points(v, matrix))
    # store results as kwargs
    loaded = {'entities': np.array(entities),
              'vertices': np.array(vertices)}
    return loaded
1240739
private static void recDrawEdges(SVGPath path, double minx, double miny, List<double[]> r_edges, long[] b) {
    // Draw all "missing" edges
    for(int i = 0; i < r_edges.size(); i++) {
      if(BitsUtil.get(b, i)) {
        continue;
      }
      final double[] edge = r_edges.get(i);
      final double x_i = minx + edge[0], y_i = miny + edge[1];
      if(!isFinite(x_i) || !isFinite(y_i)) {
        continue;
      }
      path.moveTo(minx, miny).drawTo(x_i, y_i);
      // Recursion
      BitsUtil.setI(b, i);
      recDrawEdges(path, x_i, y_i, r_edges, b);
      BitsUtil.clearI(b, i);
    }
  }
1231741
public void translateRectangle(Rectangle rect, float dx, float dy) {
		float width = rect.getWidth();
		float height = rect.getHeight();
		rect.setLeft(rect.getLeft() + dx);
		rect.setBottom(rect.getBottom() + dy);
		rect.setRight(rect.getLeft() + dx + width);
		rect.setTop(rect.getBottom() + dy + height);
	}
170543
function (x, y, w, h, wrapper) {

			if (wrapper) {
				w = h = 2 * wrapper.r;
			}

			// Center correction, #1682
			if (wrapper && wrapper.isCircle) {
				x -= w / 2;
				y -= h / 2;
			}

			// Return the path
			return [
				'wa', // clockwisearcto
				x, // left
				y, // top
				x + w, // right
				y + h, // bottom
				x + w, // start x
				y + h / 2,     // start y
				x + w, // end x
				y + h / 2,     // end y
				//'x', // finish path
				'e' // close
			];
		}
756783
public SVGPath quadTo(double c1x, double c1y, double x, double y) {
    return append(PATH_QUAD_TO).append(c1x).append(c1y).append(x).append(y);
  }
1332556
function convertPath(path) {
    function indexOf(ch, startPosition) {
      var pos = path.indexOf(ch, startPosition);
      if (pos === -1)
        return pos;

      var slashNumber = 0;
      while (path.charAt(pos - 1 - slashNumber) === '\\')
        ++slashNumber;

      if (slashNumber % 2 === 0)
        return pos;

      //Skip escaped symbols
      return indexOf(ch, pos + 1);
    }

    var match;

    //RegEx should be inside loop to reset iteration
    while (match = /{([^}:]+):/g.exec(path)) {
      var deleteBegin = match.index + match[0].length - 1;
      var deleteEnd = deleteBegin;

      var unmatched = 1;
      while (unmatched !== 0) {

        var open = indexOf('{', deleteEnd + 1);
        var close = indexOf('}', deleteEnd + 1);

        if (close === -1)
          throw Error('Unmatched curly brackets in path: ' + path);

        if (open !==  -1 && open < close) {
          ++unmatched;
          deleteEnd = open;
        }
        else {
          --unmatched;
          deleteEnd = close;
        }
      }

      //For future use: regex itself is
      //path.substring(deleteBegin + 1, deleteEnd)

      path = path.slice(0, deleteBegin) + path.slice(deleteEnd);
    }

    return path;
  }