From: Lander <la...@we...> - 2007-03-15 14:29:04
|
Hello, I'd like to thank the PyX developers for this amazing package. Congratulations and keep up the good work. This is for PyX 0.9. There's something I don't understand about the tangent method provided by path. After reading the documentation, I thought that "length" was an optional argument, with None as default value. In this case, a normalized unit vector would be returned. Please, consider the following trivial example: cir = path.circle(0, 0, 1) tg = cir.tangent(cir.atbegin()) When Python executes the second line, it throws a TypeError exception. Here's the traceback: File "circles.py", line 9, in ? tg = cir.tangent(cir.begin(), None) File "[...]/pyx/path.py", line 1164, in tangent return self.normpath().tangent(params, length) File "[...]/pyx/normpath.py", line 1418, in wrappedmethod return method(self, [valueorlist], *args, **kwargs)[0] File "[...]/pyx/normpath.py", line 1900, in tangent return self._tangent(self._convertparams(params, self.arclentoparam), unit.topt(length)) File "[...]/pyx/unit.py", line 72, in topt return _convert_to(l, "pt") File "[...]/pyx/unit.py", line 55, in _convert_to l = length(l) # convert to length instance if necessary File "[...]/pyx/unit.py", line 94, in __init__ l = float(f) * _m[unit or _default_unit] TypeError: float() argument must be a string or a number If you add a length argument different from None, then it works as expected. I'm rather new to Python, so don't take the following very seriously: I've been reading over the code, and I suspect that neither the tangent method provided by path nor the one provided by normpath check the type of "length"; therefore, this length transparently passes as an argument to unit.topt, and a TypeError is thrown if it's None. I'd appreciate your helping me understand this. Cheers. Lander |
From: Lander <la...@we...> - 2007-03-15 15:48:48
|
[Lander, 2007-03-15 15:56:32 +0100] > tg = cir.tangent(cir.atbegin()) Damn it! The previous line should read: tg = cir.tangent(cir.begin()) I'm sorry. Cheers. Lander |
From: Michael J G. <mic...@fa...> - 2007-03-15 16:36:21
|
Lander venit, vidit, dixit 2007-03-15 15:56: > Hello, > > I'd like to thank the PyX developers for this amazing > package. Congratulations and keep up the good work. > > This is for PyX 0.9. There's something I don't understand > about the tangent method provided by path. After reading > the documentation, I thought that "length" was an optional > argument, with None as default value. In this case, a > normalized unit vector would be returned. Please, consider > the following trivial example: > > cir = path.circle(0, 0, 1) > tg = cir.tangent(cir.atbegin()) > > When Python executes the second line, it throws a TypeError > exception. Here's the traceback: You want to use cir.begin() instead of cir.atbegin(). begin() returns the path parameter, whereas atbegin() returns the coordinates, i.e. at(begin()). Still, there's the error thrown by the unit conversion for None. In PyX 0.8.1 things worked the way it ought to, so it's a regression. I'll attach a patch which fixes this. Oh, I see it's kind of patched in svn already: Now, the default value of length is 1, not None, so that things work if you don't specify a length. Passing "length=None" still doesn't work, so I guess the description should be changed. Cheers, Michael |
From: Lander <la...@we...> - 2007-03-15 17:12:15
|
Dear Michael, [Michael J Gruber, 2007-03-15 16:10:21 +0100] > You want to use cir.begin() instead of cir.atbegin(). > begin() returns the path parameter, whereas atbegin() > returns the coordinates, i.e. at(begin()). I know, I know... I sent a message to correct it just before reading yours. Again, I'm sorry. > Still, there's the error thrown by the unit conversion for > None. In PyX 0.8.1 things worked the way it ought to, so > it's a regression. I'll attach a patch which fixes this. > > Oh, I see it's kind of patched in svn already: Now, the > default value of length is 1, not None, so that things > work if you don't specify a length. Passing "length=None" > still doesn't work, so I guess the description should be > changed. All right, then; I'll check that patch out. Maybe I should have done it in the first place, but, you know, I still don't feel confortable with that svn stuff. Learning to do, doing to learn, huh? ;-) Michael, thank you very much for your answer. Cheers. Lander |
From: Michael S. <m-s...@us...> - 2007-03-15 17:33:31
|
Bonjour, On 15.03.07, Michael J Gruber wrote: > Lander venit, vidit, dixit 2007-03-15 15:56: > > Oh, I see it's kind of patched in svn already: Now, the default value of > length is 1, not None, so that things work if you don't specify a > length. Passing "length=None" still doesn't work, so I guess the > description should be changed. The same has already been reported by Stefan Schenk (see pyx bug 1632988). Also the manual has been corrected in the svn version. However, Jörg did not seem to be quite satisfied with the length=1 solution. Michael. |
From: Michael J G. <mic...@fa...> - 2007-03-16 10:34:31
|
Michael SCHINDLER venit, vidit, dixit 2007-03-15 18:14: > Bonjour, > > On 15.03.07, Michael J Gruber wrote: >> Lander venit, vidit, dixit 2007-03-15 15:56: >> >> Oh, I see it's kind of patched in svn already: Now, the default value of >> length is 1, not None, so that things work if you don't specify a >> length. Passing "length=None" still doesn't work, so I guess the >> description should be changed. > > The same has already been reported by Stefan Schenk (see pyx bug > 1632988). Also the manual has been corrected in the svn version. Who's looking at the manual ;) I meant the docstrings for path.path.tangent(), normpath.normpath.tangent() and the _pt variants. > > However, Jörg did not seem to be quite satisfied with the > length=1 solution. I was quite surprised, too. That indeed does scale the tangent in a way which depends on the default unit and the current scale factor. It seems it's done just in order to save one or two if's. Michael |
From: Joerg L. <jo...@us...> - 2007-03-19 08:39:09
|
On 16.03.07, Michael J Gruber wrote: > > On 15.03.07, Michael J Gruber wrote: > >> Lander venit, vidit, dixit 2007-03-15 15:56: > >> > >> Oh, I see it's kind of patched in svn already: Now, the default value of > >> length is 1, not None, so that things work if you don't specify a > >> length. Passing "length=None" still doesn't work, so I guess the > >> description should be changed. > > > > The same has already been reported by Stefan Schenk (see pyx bug > > 1632988). Also the manual has been corrected in the svn version. > > Who's looking at the manual ;) > > I meant the docstrings for path.path.tangent(), > normpath.normpath.tangent() and the _pt variants. > > > > > However, J?rg did not seem to be quite satisfied with the > > length=1 solution. > > I was quite surprised, too. That indeed does scale the tangent in a way > which depends on the default unit and the current scale factor. It seems > it's done just in order to save one or two if's. I agree, this was one of the reasons, I didn't like the patch. The scaling problem could be solved by using true cms. But the question is whether one should really introduce a more or less arbitrary length scale here? Jörg |
From: Michael S. <m-s...@us...> - 2007-03-19 11:03:57
|
On 19.03.07, Joerg Lehmann wrote: > On 16.03.07, Michael J Gruber wrote: > > > On 15.03.07, Michael J Gruber wrote: > > >> Lander venit, vidit, dixit 2007-03-15 15:56: > > >> > > >> Oh, I see it's kind of patched in svn already: Now, the default value of > > >> length is 1, not None, so that things work if you don't specify a > > >> length. Passing "length=None" still doesn't work, so I guess the > > >> description should be changed. > > > > > > The same has already been reported by Stefan Schenk (see pyx bug > > > 1632988). Also the manual has been corrected in the svn version. > > > > Who's looking at the manual ;) > > > > I meant the docstrings for path.path.tangent(), > > normpath.normpath.tangent() and the _pt variants. > > > > > > > > However, J?rg did not seem to be quite satisfied with the > > > length=1 solution. > > > > I was quite surprised, too. That indeed does scale the tangent in a way > > which depends on the default unit and the current scale factor. It seems > > it's done just in order to save one or two if's. No. The scaling is intended. When a user scales everything -- why not also the tangent? > I agree, this was one of the reasons, I didn't like the patch. The > scaling problem could be solved by using true cms. But the question is > whether one should really introduce a more or less arbitrary length > scale here? I do not see the problem. As I introduced the default value as a simple number and not a pyx.length, I will be scaled as many other default lengths in pyx. The following minimal example scales both the circle and the tangent by 5: from pyx import * unit.set(uscale=5) p = path.circle(0, 0, 1) c = canvas.canvas() c.stroke(p) c.stroke(p.tangent(1.57)) This is the behaviour I would expect from a useful default length. The only other possibility I see is to omit the default argument completely. This would avoid the -- somehow artificial -- introduction of a length scale here. Michael. |
From: Michael J G. <mic...@fa...> - 2007-03-19 15:51:34
|
Michael SCHINDLER venit, vidit, dixit 2007-03-19 10:42: > On 19.03.07, Joerg Lehmann wrote: ... > No. The scaling is intended. When a user scales everything -- why not also the > tangent? > >> I agree, this was one of the reasons, I didn't like the patch. The >> scaling problem could be solved by using true cms. But the question is >> whether one should really introduce a more or less arbitrary length >> scale here? > > I do not see the problem. As I introduced the default value as a > simple number and not a pyx.length, I will be scaled as many other > default lengths in pyx. Do you scale like a ``true'', ``user'', ``visual'', ``width'', or ``TEX'' length? Sorry I couldn't resist ;) Michael |
From: Michael S. <m-s...@us...> - 2007-03-19 16:30:59
|
On 19.03.07, Michael J Gruber wrote: > Michael SCHINDLER venit, vidit, dixit 2007-03-19 10:42: > > On 19.03.07, Joerg Lehmann wrote: > ... > > No. The scaling is intended. When a user scales everything -- why not also the > > tangent? > > > >> I agree, this was one of the reasons, I didn't like the patch. The > >> scaling problem could be solved by using true cms. But the question is > >> whether one should really introduce a more or less arbitrary length > >> scale here? > > > > I do not see the problem. As I introduced the default value as a > > simple number and not a pyx.length, I will be scaled as many other > > default lengths in pyx. > > Do you scale like a ``true'', ``user'', ``visual'', ``width'', or > ``TEX'' length? The unit is evaluated by normpath.normpath.tangent in the following way: unit.topt(length) Thus, it is only the unit module which defines the scaling here. It is therefore always the default scaling that the user has set with all his unit.set(...) commands. If the user does not change anything, this is user cm The user can change the "cm", but not the "user". I really like to stress that this type of scaling is used in PyX _everywhere_. Just consider the simple example p = path.circle(0, 0, 1) or check all the unit.topt() calls in normpath.py. Here, all the numbers are scaled in exactly the same way as the length above. The only difference is that there are no default arguments for path.circle. > Sorry I couldn't resist ;) BTW: I really find this discussion a bit boring. If there are severe objections against the default behaviour of the method tangent (which I find _completely_ _unnecessary_, besides that it has a wrong name, as it does not provide a tangent but a "line parallel to the tangent vector" (sic!)), then please make a suggestion, be it to remove the default behaviour -- or the complete method, which would be my favourite! Michael. |
From: Michael J G. <mic...@fa...> - 2007-03-20 09:00:18
|
Michael SCHINDLER venit, vidit, dixit 2007-03-19 17:30: > On 19.03.07, Michael J Gruber wrote: >> Michael SCHINDLER venit, vidit, dixit 2007-03-19 10:42: ... >>> I do not see the problem. As I introduced the default value as a >>> simple number and not a pyx.length, I will be scaled as many >>> other default lengths in pyx. >> Do you scale like a ``true'', ``user'', ``visual'', ``width'', or >> ``TEX'' length? > > The unit is evaluated by normpath.normpath.tangent in the following > way: ... >> Sorry I couldn't resist ;) > > BTW: I really find this discussion a bit boring. If there are severe > objections against the default behaviour of the method tangent (which > I find _completely_ _unnecessary_, besides that it has a wrong name, > as it does not provide a tangent but a "line parallel to the tangent > vector" (sic!)), then please make a suggestion, be it to remove the > default behaviour -- or the complete method, which would be my > favourite! I meant to hint ironically at a funny typo ("I will be scaled..."), I'm sorry this didn't come through right. No nitpicking intended. I'm completely OK with the current situation (not that my opinion would matter anyway), even with the naming (preferring shortness over conciseness). I didn't object the scale dependence, I was just surprised, remembering a patch by me which was refused due to scale issues (division of lengths, I think it's even in now). OK, that's it from me about tangents, promised ;) Michael |
From: Alan G I. <ai...@am...> - 2007-03-20 13:42:48
|
>>> Michael SCHINDLER venit, vidit, dixit 2007-03-19 10:42: >>>> I will be scaled as many other default lengths in pyx. >> On 19.03.07, Michael J Gruber wrote: >>> Do you scale like a ``true'', ``user'', ``visual'', ``width'', or >>> ``TEX'' length? On Tue, 20 Mar 2007, Michael J Gruber apparently wrote: > I meant to hint ironically at a funny typo ("I will be > scaled...") Too subtle; I missed it too. But actually funny. Cheers, Alan Isaac |