Dear Aman,

Am 05.06.2015 um 09:23 schrieb Aman Bhatia <[email protected]>:
> I was not able to find any example for opening a SVG file however I find 
> functions in the src for this stuff. Is it possible? If yes, can someone 
> provide a working example.

We do not have an example, but there are some test codes (a functional test at 
https://sourceforge.net/p/pyx/code/HEAD/tree/trunk/pyx/test/functional/test_svgfile.py
 and running some parts of an svg test suite by 
https://sourceforge.net/p/pyx/code/HEAD/tree/trunk/pyx/test/svg/svgtest.py). It 
works like the following:

from pyx import *

p = path.path(path.moveto(-1, 2), path.curveto(-1, 1, 0, 0, 1, 0))

c = canvas.canvas()
c.stroke(p)
c.writeSVGfile("aman1.svg")

c = canvas.canvas()
c.stroke(p, [trafo.mirror(90)])
c.writeSVGfile("aman2.svg")

c = canvas.canvas()

s1 = svgfile.svgfile(0, 0, "aman1.svg", parsed=True)
t1a = s1.canvas.trafo
t1b = s1.canvas[0].trafo
p1 = s1.canvas[0][0].path
p1 = p1.transformed(t1a*t1b)

s2 = svgfile.svgfile(0, 0, "aman2.svg", parsed=True)
t2a = s2.canvas.trafo
t2b = s2.canvas[0].trafo
p2 = s2.canvas[0][0].path
p2 = p2.transformed(t1a*t1b)

c.stroke(p1)
c.stroke(p2)

i1, i2 = p1.intersect(p2)

for a in i1:
    x, y = p1.at(a)
    c.fill(path.circle(x, y, 0.1))

c.writeSVGfile("aman.svg")

We create two svg files here, and then read them again, intersect the two paths 
and write some result.

Unfortunately you have to walk inside the pathitems of the svg file you loaded 
in parsed mode (see http://pyx.sourceforge.net/manual/svgfile.html for a brief 
information about parsed mode). In this simple case we have two nested canvas 
instances, you have to walk inside yourself. Also note that the path is not 
inserted into the canvas itself, but it is done by a decorated path (a path 
with some stroke and fill features), where you have to reference the path to 
get the original path. Furthermore some of the canvas instances you walked 
inside might apply some transformations, you have to apply yourself to the path 
to have aligned properly.

> Actually, I want to know if two paths in a SVG intersect or not. Now, pyx has 
> function intersects in the path class, which returns list of intersection 
> points. But all I want is a boolean that if two paths intersect or not. So, 
> calculating list of intersection points would be waste of resources. Is there 
> any such functionality?

In PyX we don't have a feature to just check whether two paths intersect. 
Sorry. Also, for bezier curves, our algorithm is to split down the bezier 
curves to narrow for the intersection point(s). We then do not just get the 
information whether the curves intersect, but also have found the solution 
itself. I don't know whether there are more efficient algorithms to just check 
for intersection or not.

Best,


André

> ------------------------------------------------------------------------------
> _______________________________________________
> PyX-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyx-user

-- 
by  _ _      _    Dr. André Wobst, Amselweg 22, 85716 Unterschleißheim
   / \ \    / )   [email protected], http://www.wobsta.de/
  / _ \ \/\/ /    PyX - High quality PostScript and PDF figures
 (_/ \_)_/\_/     with Python & TeX: visit http://pyx.sourceforge.net/

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to