ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Clipping again
@ 2006-06-25 19:19 David Arnold
  2006-06-25 19:37 ` Mojca Miklavec
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: David Arnold @ 2006-06-25 19:19 UTC (permalink / raw)


Hi,

I confess I got some earlier advice on this issue, but I've never  
been able to apply it to find a resolution. In the buffer that  
follows, I define a clipping box:

% clipping path
path cpath;
cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;
cpath:=cpath scaled 1u;

A function is created and scaled:

% scale and draw graph
P:=P scaled u;
draw P withcolor blue;

The picture is clipped and saved:

% clip and save current picture
picture pic;
clip currentpicture to cpath;
pic:=currentpicture;

Then it is redrawn later.

% redraw line
draw pic;

Unfortunately, even though this works, mathematicians really want  
arrows at each end of the graph. Easy enough to do with drawdblarrow  
P withcolor blue, but the arrows then get clipped. What I really need  
is to adapt the code below so that my function is clipped to the  
boundary box, but then redrawn with arrows at each end of it. If  
anyone can adjust my code to do that, it would be much appreciated,  
and it would break down a barrier I've faced for years with metapost  
coding.

Note that I've tried some stuff with cutbefore and cutafter with some  
success. But I should remark that the code below is generated by a  
perl script and some special coding we've set up to generate these  
graphics on the fly for student quizzes. This is not a situation  
where I can tweak an individual plot or two. Rather, our script might  
generate 100 sets of the code below, all with different parameters.  
So this magnifies the problem.

Again, any ideas would be greatly appreciated.





\startbuffer
numeric w,h;
w=4cm;h=4cm;
% inititialize numerator and denominator of the slope of f
numeric a;
a=2;

% initialize choice of function
numeric choice;
choice=1;

% initialize type of reflection
numeric reflect;
reflect=2;

% define linear function f
vardef f(expr x)=
	a*x*x
enddef;

% define linear function g
vardef g(expr x)=
	a*abs(x)
enddef;

% define linear function h
vardef h(expr x)=
	a*x*(x-2)*(x+2)/2
enddef;

% define paths for functions f, g, and h, respectively
path P, F, G, H;

F:=(-5,f(-5));
for x=-5 step .1 until 5:
	F:=F--(x,f(x));
endfor;

G:=(-5,g(-5));
for x=-5 step .1 until 5:
	G:=G--(x,g(x));
endfor;

H:=(-5,h(-5));
for x=-5 step .1 until 5:
	H:=H--(x,h(x));
endfor;

% choose the function to use, f, g, or h
if (choice=1):
	P:=F;
elseif (choice=2):
	P:=G;
else:
	P:=H;
fi;

% choose the type of reflection
if (reflect=1):
	P:=P;
elseif (reflect=2):
	P:=P reflectedabout((0,0),(1,1));
elseif (reflect=3):
	P:=P reflectedabout((0,0),(1,-1));
else:
	P:=P reflectedabout((-1,0),(1,0));
fi;

% initialize scale
numeric u; 10u=w;

% scale and draw graph
P:=P scaled u;
draw P withcolor blue;

% clipping path
path cpath;
cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;
cpath:=cpath scaled 1u;

% clip and save current picture
picture pic;
clip currentpicture to cpath;
pic:=currentpicture;

% erase currentpicture
currentpicture:=nullpicture;

% draw grid
for k=-5u step 1u until 5u:
	draw (-5u,k)--(5u,k) withcolor mygridcolor;
	draw (k,-5u)--(k,5u) withcolor mygridcolor;
endfor;

% draw axes
drawarrow (-5u,0)--(5u,0);
drawarrow (0,-5u)--(0,5u);

% label axes
label.rt(btex $x$ etex, (5.2u,0));
label.top(btex $y$ etex, (0,5.2.u));
label.bot(btex $5$ etex, (5u,0));
label.lft(btex $5$ etex, (0,5u));

% redraw line
draw pic;

% draw vertical line test
numeric xvert;
if (reflect=3):
	xvert:=-1;
else:
	xvert:=1;
fi;

% vertical line
path vert;
vert:=(xvert,-5)--(xvert,5);
vert:=vert scaled u;

pickup pencircle scaled 2pt;
drawdblarrow vert withcolor red;
pickup defaultpen;
	
\stopbuffer

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-25 19:19 Clipping again David Arnold
@ 2006-06-25 19:37 ` Mojca Miklavec
  2006-06-25 19:58   ` David Arnold
  2006-06-25 21:32 ` Hans Hagen
  2006-06-26  9:39 ` Mojca Miklavec
  2 siblings, 1 reply; 17+ messages in thread
From: Mojca Miklavec @ 2006-06-25 19:37 UTC (permalink / raw)


On 6/25/06, David Arnold wrote:
> Unfortunately, even though this works, mathematicians really want
> arrows at each end of the graph. Easy enough to do with drawdblarrow
> P withcolor blue, but the arrows then get clipped. What I really need
> is to adapt the code below so that my function is clipped to the
> boundary box, but then redrawn with arrows at each end of it. If
> anyone can adjust my code to do that, it would be much appreciated,
> and it would break down a barrier I've faced for years with metapost
> coding.

Just for clarification: What would you do with a "mexican hat"
(x^4-4*x^2+4, y between 0 and 3) it if would cut the boundary 4 times?
Use 4 arrows or just the two at the end?

Mojca

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-25 19:37 ` Mojca Miklavec
@ 2006-06-25 19:58   ` David Arnold
  2006-06-25 20:14     ` Mojca Miklavec
  0 siblings, 1 reply; 17+ messages in thread
From: David Arnold @ 2006-06-25 19:58 UTC (permalink / raw)


Mojca,

Good question of course.

However, I am using this for intermediate algebra students so the  
graphs will be lines, absolute value, quadratics, polynomials,  
rational functions, radical functions, exponential and logarithmic  
functions.

In each case, I would adjust the window to see all important behavior  
of the function, extrema, etc. So, for example, if I needed to draw  
y=12-x^2, I would not clip this to the boundary (-10,-10)--(10,-10)-- 
(10,10)--(-10,10)--cycle, because that would chop off the top of the  
parabola, and if I added arrows, it would look like I had two  
branches. Rather, I might clip y=12-x^2 to the boundary (-10,-20)-- 
(10,-20)--(10,20)--(-10,20)--cycle in order to see the "turning  
point" of the parabola.

That is, I would choose a boundary that would present arrow heads at  
each end of the curve. In the case of rational functions, I would  
clip each branch separately.

I hope this answers the question.

Thanks.

On Jun 25, 2006, at 12:37 PM, Mojca Miklavec wrote:

> On 6/25/06, David Arnold wrote:
>> Unfortunately, even though this works, mathematicians really want
>> arrows at each end of the graph. Easy enough to do with drawdblarrow
>> P withcolor blue, but the arrows then get clipped. What I really need
>> is to adapt the code below so that my function is clipped to the
>> boundary box, but then redrawn with arrows at each end of it. If
>> anyone can adjust my code to do that, it would be much appreciated,
>> and it would break down a barrier I've faced for years with metapost
>> coding.
>
> Just for clarification: What would you do with a "mexican hat"
> (x^4-4*x^2+4, y between 0 and 3) it if would cut the boundary 4 times?
> Use 4 arrows or just the two at the end?
>
> Mojca
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-25 19:58   ` David Arnold
@ 2006-06-25 20:14     ` Mojca Miklavec
  2006-06-26  0:51       ` David Arnold
  0 siblings, 1 reply; 17+ messages in thread
From: Mojca Miklavec @ 2006-06-25 20:14 UTC (permalink / raw)


On 6/25/06, David Arnold wrote:
> That is, I would choose a boundary that would present arrow heads at
> each end of the curve. In the case of rational functions, I would
> clip each branch separately.
>
> I hope this answers the question.

So that necessary means an arrowhead each time when a function crosses
the boundary if I understand correctly (i.e. 1/x would have 4
arrowheads)?

Mojca

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-25 19:19 Clipping again David Arnold
  2006-06-25 19:37 ` Mojca Miklavec
@ 2006-06-25 21:32 ` Hans Hagen
  2006-06-26  9:39 ` Mojca Miklavec
  2 siblings, 0 replies; 17+ messages in thread
From: Hans Hagen @ 2006-06-25 21:32 UTC (permalink / raw)


David Arnold wrote:
> Hi,
>
> I confess I got some earlier advice on this issue, but I've never  
> been able to apply it to find a resolution. In the buffer that  
> follows, I define a clipping box:
>
> % clipping path
> path cpath;
> cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;
> cpath:=cpath scaled 1u;
>
> A function is created and scaled:
>
> % scale and draw graph
> P:=P scaled u;
> draw P withcolor blue;
>
> The picture is clipped and saved:
>
> % clip and save current picture
> picture pic;
> clip currentpicture to cpath;
> pic:=currentpicture;
>
> Then it is redrawn later.
>
> % redraw line
> draw pic;
>
> Unfortunately, even though this works, mathematicians really want  
> arrows at each end of the graph. Easy enough to do with drawdblarrow  
> P withcolor blue, but the arrows then get clipped. What I really need  
> is to adapt the code below so that my function is clipped to the  
> boundary box, but then redrawn with arrows at each end of it. If  
> anyone can adjust my code to do that, it would be much appreciated,  
> and it would break down a barrier I've faced for years with metapost  
> coding.
>
> Note that I've tried some stuff with cutbefore and cutafter with some  
> success. But I should remark that the code below is generated by a  
> perl script and some special coding we've set up to generate these  
> graphics on the fly for student quizzes. This is not a situation  
> where I can tweak an individual plot or two. Rather, our script might  
> generate 100 sets of the code below, all with different parameters.  
> So this magnifies the problem.
>   
as you sat, the basics are in: 

P := (P cutbefore cpath) ;
P := (P cutafter cpath) ;
drawdblarrow P withcolor green;

it should not be too hard for a mathematician to make sure that this works ok; i think that as long as one makes sure that the directions are  right (do a reverse P if needed) 

Hans 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-25 20:14     ` Mojca Miklavec
@ 2006-06-26  0:51       ` David Arnold
  0 siblings, 0 replies; 17+ messages in thread
From: David Arnold @ 2006-06-26  0:51 UTC (permalink / raw)


Not necessary. Let me add comments to my code in places where I need  
help. My comments are marked with [DA 6/25].

\startbuffer
numeric w,h;
w=4cm;h=4cm;
% inititialize numerator and denominator of the slope of f
numeric a;
a=1.5;

% initialize choice of function
numeric choice;
choice=2;                     %<=====[DA 6/25]Test to see if code  
works for 1, 2, or 3.

% initialize type of reflection
numeric reflect;
reflect=3;                   %<======[DA 6/25]Test to see if code  
works for 1, 2, 3, or 4

% define linear function f
vardef f(expr x)=
	a*x*x
enddef;

% define linear function g
vardef g(expr x)=
	a*abs(x)
enddef;

% define linear function h
vardef h(expr x)=
	a*x*(x-2)*(x+2)/2
enddef;

% define paths for functions f, g, and h, respectively
path P, F, G, H;

F:=(-5,f(-5));
for x=-5 step .1 until 5:
	F:=F--(x,f(x));
endfor;

G:=(-5,g(-5));
for x=-5 step .1 until 5:
	G:=G--(x,g(x));
endfor;

H:=(-5,h(-5));
for x=-5 step .1 until 5:
	H:=H--(x,h(x));
endfor;

% choose the function to use, f, g, or h
if (choice=1):
	P:=F;
elseif (choice=2):
	P:=G;
else:
	P:=H;
fi;

% choose the type of reflection
if (reflect=1):
	P:=P;
elseif (reflect=2):
	P:=P reflectedabout((0,0),(1,1));
elseif (reflect=3):
	P:=P reflectedabout((0,0),(1,-1));
else:
	P:=P reflectedabout((-1,0),(1,0));
fi;

% initialize scale
numeric u; 10u=w;

% scale and draw graph
P:=P scaled u;
draw P withcolor blue;

% clipping path
path cpath;
cpath:=(-5,-5)--(5,-5)--(5,5)--(-5,5)--cycle;
cpath:=cpath scaled 1u;


%[DA 6/25]<========Replace this code from here to next mark with new  
clipping routine
% clip and save current picture
picture pic;
clip currentpicture to cpath;
pic:=currentpicture;

% erase currentpicture
currentpicture:=nullpicture;
%[DA 6/25]<========End of code to replace with new clipping routine

%[DA 6/25] Put new clipping routine here. It should return P clipped  
to clipping path
%[DA 6/25] for all choices of "choice" and "reflect:

% draw grid
for k=-5u step 1u until 5u:
	draw (-5u,k)--(5u,k) withcolor mygridcolor;
	draw (k,-5u)--(k,5u) withcolor mygridcolor;
endfor;

% draw axes
drawarrow (-5u,0)--(5u,0);
drawarrow (0,-5u)--(0,5u);

% label axes
label.rt(btex $x$ etex, (5.2u,0));
label.top(btex $y$ etex, (0,5.2.u));
label.bot(btex $5$ etex, (5u,0));
label.lft(btex $5$ etex, (0,5u));

%[DA 6/25]<==========Replace with "draw pic" command with  
"drawdblarrow P"
% redraw line
draw pic;

\stopbuffer

\startlinecorrection[blank]
\midaligned{\processMPbuffer}
\stoplinecorrection





On Jun 25, 2006, at 1:14 PM, Mojca Miklavec wrote:

> On 6/25/06, David Arnold wrote:
>> That is, I would choose a boundary that would present arrow heads at
>> each end of the curve. In the case of rational functions, I would
>> clip each branch separately.
>>
>> I hope this answers the question.
>
> So that necessary means an arrowhead each time when a function crosses
> the boundary if I understand correctly (i.e. 1/x would have 4
> arrowheads)?
>
> Mojca
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-25 19:19 Clipping again David Arnold
  2006-06-25 19:37 ` Mojca Miklavec
  2006-06-25 21:32 ` Hans Hagen
@ 2006-06-26  9:39 ` Mojca Miklavec
  2006-06-26 15:01   ` Hans Hagen
  2006-06-26 19:51   ` David Arnold
  2 siblings, 2 replies; 17+ messages in thread
From: Mojca Miklavec @ 2006-06-26  9:39 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 2104 bytes --]

On 6/25/06, David Arnold wrote:
> Hi,
>
> I confess I got some earlier advice on this issue, but I've never
> been able to apply it to find a resolution. In the buffer that
> follows, I define a clipping box:
>
> /.../
>
> Unfortunately, even though this works, mathematicians really want
> arrows at each end of the graph. Easy enough to do with drawdblarrow
> P withcolor blue, but the arrows then get clipped. What I really need
> is to adapt the code below so that my function is clipped to the
> boundary box, but then redrawn with arrows at each end of it. If
> anyone can adjust my code to do that, it would be much appreciated,
> and it would break down a barrier I've faced for years with metapost
> coding.
>
> Note that I've tried some stuff with cutbefore and cutafter with some
> success. But I should remark that the code below is generated by a
> perl script and some special coding we've set up to generate these
> graphics on the fly for student quizzes. This is not a situation
> where I can tweak an individual plot or two. Rather, our script might
> generate 100 sets of the code below, all with different parameters.
> So this magnifies the problem.
>
> Again, any ideas would be greatly appreciated.

Can you check the attached file? I changed a bit more of the code than
you asked for, but I hope that that's not the problem. Only by using
"cutbefore/cutafter" you would have to consider too much cases of
curve orientation and I avoided the usace of clipping completely. It
has some minor problems when drawing a pole of odd orders: this part
of the code
		elseif isInside and (not fallsInside(mytransform((x,ff(x))),cbox)):
should be fixed a bit for such cases, so please let me know if you
need help for the fix.

The nice part about metapost is that it's a programming language, so
you should write your code in such a way that you never code the same
number more than once - you should avoid hardcoding the numbers (5
appears quite often in your code) as often as possible.

Please let me know if you need some explanation - I didn't comment
much in the source itself.

Mojca

[-- Attachment #2: dblarrow.tex --]
[-- Type: application/x-tex, Size: 4016 bytes --]

[-- Attachment #3: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26  9:39 ` Mojca Miklavec
@ 2006-06-26 15:01   ` Hans Hagen
  2006-06-26 19:51   ` David Arnold
  1 sibling, 0 replies; 17+ messages in thread
From: Hans Hagen @ 2006-06-26 15:01 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 6/25/06, David Arnold wrote:
>> Hi,
>>
>> I confess I got some earlier advice on this issue, but I've never
>> been able to apply it to find a resolution. In the buffer that
>> follows, I define a clipping box:
>>
>> /.../
>>
>> Unfortunately, even though this works, mathematicians really want
>> arrows at each end of the graph. Easy enough to do with drawdblarrow
>> P withcolor blue, but the arrows then get clipped. What I really need
>> is to adapt the code below so that my function is clipped to the
>> boundary box, but then redrawn with arrows at each end of it. If
>> anyone can adjust my code to do that, it would be much appreciated,
>> and it would break down a barrier I've faced for years with metapost
>> coding.
>>
>> Note that I've tried some stuff with cutbefore and cutafter with some
>> success. But I should remark that the code below is generated by a
>> perl script and some special coding we've set up to generate these
>> graphics on the fly for student quizzes. This is not a situation
>> where I can tweak an individual plot or two. Rather, our script might
>> generate 100 sets of the code below, all with different parameters.
>> So this magnifies the problem.
>>
>> Again, any ideas would be greatly appreciated.
>
> Can you check the attached file? I changed a bit more of the code than
> you asked for, but I hope that that's not the problem. Only by using
> "cutbefore/cutafter" you would have to consider too much cases of
> curve orientation and I avoided the usace of clipping completely. It
> has some minor problems when drawing a pole of odd orders: this part
> of the code
>         elseif isInside and (not 
> fallsInside(mytransform((x,ff(x))),cbox)):
> should be fixed a bit for such cases, so please let me know if you
> need help for the fix.
>
> The nice part about metapost is that it's a programming language, so
> you should write your code in such a way that you never code the same
> number more than once - you should avoid hardcoding the numbers (5
> appears quite often in your code) as often as possible.
>
> Please let me know if you need some explanation - I didn't comment
> much in the source itself.
impressive 

btw, no need for an if in: 

vardef fallsInside(expr apoint, cbox) =
  (xpart apoint >= xpart llcorner cbox) and
  (xpart apoint <= xpart urcorner cbox) and
  (ypart apoint >= ypart llcorner cbox) and
  (ypart apoint <= ypart urcorner cbox)
enddef;

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26  9:39 ` Mojca Miklavec
  2006-06-26 15:01   ` Hans Hagen
@ 2006-06-26 19:51   ` David Arnold
  2006-06-26 20:35     ` Mojca Miklavec
  1 sibling, 1 reply; 17+ messages in thread
From: David Arnold @ 2006-06-26 19:51 UTC (permalink / raw)


Mojca,

Doesn't compile at my end:

This is MetaPost, Version 0.901 (Web2C 7.5.5)
(/usr/local/teTeX/share/texmf.local/web2c/natural.tcx)
(dblarrow-mpgraph.mp [1]
! Redundant equation.
<to be read again>
                    ;
l.272 10u=w;

?



On Jun 26, 2006, at 2:39 AM, Mojca Miklavec wrote:

> On 6/25/06, David Arnold wrote:
>> Hi,
>>
>> I confess I got some earlier advice on this issue, but I've never
>> been able to apply it to find a resolution. In the buffer that
>> follows, I define a clipping box:
>>
>> /.../
>>
>> Unfortunately, even though this works, mathematicians really want
>> arrows at each end of the graph. Easy enough to do with drawdblarrow
>> P withcolor blue, but the arrows then get clipped. What I really need
>> is to adapt the code below so that my function is clipped to the
>> boundary box, but then redrawn with arrows at each end of it. If
>> anyone can adjust my code to do that, it would be much appreciated,
>> and it would break down a barrier I've faced for years with metapost
>> coding.
>>
>> Note that I've tried some stuff with cutbefore and cutafter with some
>> success. But I should remark that the code below is generated by a
>> perl script and some special coding we've set up to generate these
>> graphics on the fly for student quizzes. This is not a situation
>> where I can tweak an individual plot or two. Rather, our script might
>> generate 100 sets of the code below, all with different parameters.
>> So this magnifies the problem.
>>
>> Again, any ideas would be greatly appreciated.
>
> Can you check the attached file? I changed a bit more of the code than
> you asked for, but I hope that that's not the problem. Only by using
> "cutbefore/cutafter" you would have to consider too much cases of
> curve orientation and I avoided the usace of clipping completely. It
> has some minor problems when drawing a pole of odd orders: this part
> of the code
> 		elseif isInside and (not fallsInside(mytransform((x,ff(x))),cbox)):
> should be fixed a bit for such cases, so please let me know if you
> need help for the fix.
>
> The nice part about metapost is that it's a programming language, so
> you should write your code in such a way that you never code the same
> number more than once - you should avoid hardcoding the numbers (5
> appears quite often in your code) as often as possible.
>
> Please let me know if you need some explanation - I didn't comment
> much in the source itself.
>
> Mojca
> <dblarrow.tex>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26 19:51   ` David Arnold
@ 2006-06-26 20:35     ` Mojca Miklavec
  2006-06-26 22:30       ` Hans Hagen
  2006-06-27  1:04       ` David Arnold
  0 siblings, 2 replies; 17+ messages in thread
From: Mojca Miklavec @ 2006-06-26 20:35 UTC (permalink / raw)


On 6/26/06, David Arnold wrote:
> Mojca,
>
> Doesn't compile at my end:
>
> This is MetaPost, Version 0.901 (Web2C 7.5.5)
> (/usr/local/teTeX/share/texmf.local/web2c/natural.tcx)
> (dblarrow-mpgraph.mp [1]
> ! Redundant equation.
> <to be read again>
>                     ;
> l.272 10u=w;

Do you use some other high-level command to process the MP code? (Two
graphics may not be processed in the same file unless you add an
assignment instead.) What happens if you write u:=w/10?

To Hans: thanks for the hint! (Slowly starting to believe that the
code might indeed reach 4 lines ;)

Mojca

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26 20:35     ` Mojca Miklavec
@ 2006-06-26 22:30       ` Hans Hagen
  2006-06-26 22:44         ` Mojca Miklavec
  2006-06-27  1:04       ` David Arnold
  1 sibling, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2006-06-26 22:30 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 6/26/06, David Arnold wrote:
>   
>> Mojca,
>>
>> Doesn't compile at my end:
>>
>> This is MetaPost, Version 0.901 (Web2C 7.5.5)
>> (/usr/local/teTeX/share/texmf.local/web2c/natural.tcx)
>> (dblarrow-mpgraph.mp [1]
>> ! Redundant equation.
>> <to be read again>
>>                     ;
>> l.272 10u=w;
>>     
>
> Do you use some other high-level command to process the MP code? (Two
> graphics may not be processed in the same file unless you add an
> assignment instead.) What happens if you write u:=w/10?
>
> To Hans: thanks for the hint! (Slowly starting to believe that the
> code might indeed reach 4 lines ;)
>   
another one:

vardef mytransform(expr pathorpicture) =
  pathorpicture
    if reflect=2:
      reflectedabout((0,0),(1,1))
    elseif reflect=3:
      reflectedabout((0,0),(1,-1))
    elseif reflect=4:
      reflectedabout((-1,0),(1,0))
    fi
enddef;

-) 

Hans 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26 22:30       ` Hans Hagen
@ 2006-06-26 22:44         ` Mojca Miklavec
  2006-06-26 23:04           ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Mojca Miklavec @ 2006-06-26 22:44 UTC (permalink / raw)


On 6/27/06, Hans Hagen wrote:
> Mojca Miklavec wrote:
> > To Hans: thanks for the hint! (Slowly starting to believe that the
> > code might indeed reach 4 lines ;)
> >
> another one:
>
> vardef mytransform(expr pathorpicture) =
>   pathorpicture
>     if reflect=2:
>       reflectedabout((0,0),(1,1))
>     elseif reflect=3:
>       reflectedabout((0,0),(1,-1))
>     elseif reflect=4:
>       reflectedabout((-1,0),(1,0))
>     fi
> enddef;
>
> -)

What a waste of space ;) !

vardef mytransform(expr pathorpicture) =
 pathorpicture
   if reflect > 1: reflectedabout(
     if     reflect=2: (0,0),(1,1)
     elseif reflect=3: (0,0),(1,-1)
     elseif reflect=4: (-1,0),(1,0)
     fi)
   fi
enddef;

(Slowly starting to believe that MP might become as horrible &
unreadable as perl ;)

Mojca

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26 22:44         ` Mojca Miklavec
@ 2006-06-26 23:04           ` Hans Hagen
  2006-06-27  2:27             ` David Arnold
  0 siblings, 1 reply; 17+ messages in thread
From: Hans Hagen @ 2006-06-26 23:04 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 6/27/06, Hans Hagen wrote:
>   
>> Mojca Miklavec wrote:
>>     
>>> To Hans: thanks for the hint! (Slowly starting to believe that the
>>> code might indeed reach 4 lines ;)
>>>
>>>       
>> another one:
>>
>> vardef mytransform(expr pathorpicture) =
>>   pathorpicture
>>     if reflect=2:
>>       reflectedabout((0,0),(1,1))
>>     elseif reflect=3:
>>       reflectedabout((0,0),(1,-1))
>>     elseif reflect=4:
>>       reflectedabout((-1,0),(1,0))
>>     fi
>> enddef;
>>
>> -)
>>     
>
> What a waste of space ;) !
>
> vardef mytransform(expr pathorpicture) =
>  pathorpicture
>    if reflect > 1: reflectedabout(
>      if     reflect=2: (0,0),(1,1)
>      elseif reflect=3: (0,0),(1,-1)
>      elseif reflect=4: (-1,0),(1,0)
>      fi)
>    fi
> enddef;
>
> (Slowly starting to believe that MP might become as horrible &
> unreadable as perl ;)
>
>   
that's why i seldom go that far

but the if inside an expresion is ok for me (many languages provide that)

of course a clean solution is:

transform _mt_[] ; reflect := 1 ;

_mt_[1] := identity ;
_mt_[2] := identity reflectedabout(( 0,0),(1, 1)) ;
_mt_[3] := identity reflectedabout(( 0,0),(1,-1)) ;
_mt_[4] := identity reflectedabout((-1,0),(1, 0)) ;

vardef mytransform(expr p) = p transformed _mt_[reflect] enddef; % one 
line -)

draw mytransform(fullcircle scaled 10cm) ;

draw fullcircle scaled 4cm transformed _mt_[reflect] ;


Hans

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26 20:35     ` Mojca Miklavec
  2006-06-26 22:30       ` Hans Hagen
@ 2006-06-27  1:04       ` David Arnold
  1 sibling, 0 replies; 17+ messages in thread
From: David Arnold @ 2006-06-27  1:04 UTC (permalink / raw)


I just ran:  texexec dblarrow.tex

tmp $ texexec dblarrow.tex

TeXExec 5.4.3 - ConTeXt / PRAGMA ADE 1997-2005

fixing engine variable : pdfetex
             executable : pdfetex
                 format : cont-en
              inputfile : dblarrow
                 output : standard
              interface : en
           current mode : none
                TeX run : 1

This is pdfeTeX, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5)
(/usr/local/teTeX/share/texmf.local/web2c/natural.tcx)
entering extended mode
(./dblarrow.tex

ConTeXt  ver: 2006.03.20 10:19  fmt: 2006.3.21  int: english  mes:  
english

language        : language en is active
<protectionstate 0>
system          : cont-new loaded
(/usr/local/teTeX/share/texmf.local/tex/context/base/cont-new.tex
systems         : beware: some patches loaded from cont-new.tex
color           : palette rollover is available
)
system          : cont-old loaded
(/usr/local/teTeX/share/texmf.local/tex/context/base/cont-old.tex
loading         : Context Old Macros
)
system          : cont-fil loaded
(/usr/local/teTeX/share/texmf.local/tex/context/base/cont-fil.tex
loading         : Context File Synonyms
)
system          : cont-sys.rme loaded
(/usr/local/teTeX/share/texmf.local/tex/context/user/cont-sys.rme
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-exa.tex)
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-syn.tex)
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-enc.tex)
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-siz.tex)
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-map.tex)
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-spe.tex)
(/usr/local/teTeX/share/texmf.local/tex/context/base/type-akb.tex))
bodyfont        : 12pt rm is loaded
language        : patterns en->ec:ec->1->2:3 uk->ec:ec->2->2:3 de- 
 >texnansi:tex
nansi->3->2:3 de->ec:ec->4->2:3 fr->texnansi:texnansi->5->2:3 fr- 
 >ec:ec->6->2:3
es->ec:ec->7->2:3 pt->texnansi:texnansi->8->2:3 pt->ec:ec->9->2:3 it- 
 >texnansi
:texnansi->10->2:3 it->ec:ec->11->2:3 nl->texnansi:texnansi->12->2:3  
nl->ec:ec-
 >13->2:3 cz->il2:il2->14->2:3 cz->ec:ec->15->2:3 sk->il2:il2->16- 
 >2:3 sk->ec:ec
->17->2:3 pl->pl0:pl0->18->2:3 pl->ec:ec->19->2:3 pl->qx:qx->20->2:3  
loaded
specials        : tex,postscript,rokicki loaded
system          : dblarrow.top loaded
(./dblarrow.top)
systems         : system commands are disabled
color           : system rgb is global activated
(./dblarrow.tuo) (./dblarrow.tuo) (./dblarrow.tuo) (./dblarrow.tuo)
(./dblarrow.tuo) (./dblarrow.tuo) (./dblarrow.tuo) (./dblarrow.tuo)
(./dblarrow.tuo) (./dblarrow.tuo) (./dblarrow.tuo) (./dblarrow.tuo)
(./dblarrow.tuo)
systems         : begin file dblarrow at line 5
[MP as EPS ./dblarrow-mpgraph.1] [MP as EPS ./dblarrow-mpgraph.2]
[MP as EPS ./dblarrow-mpgraph.3] [MP as EPS ./dblarrow-mpgraph.4]
fonts           : resetting map file list
fonts           : using map file: original-base
fonts           : using map file: ec-public-lm
fonts           : using map file: ec-base
fonts           : using map file: 8r-base
fonts           : using map file: t5-base
fonts           : using map file: original-ams-base
fonts           : using map file: original-ams-euler
fonts           : using map file: original-public-lm
[1.1]
systems         : end file dblarrow at line 187
[flush and process dblarrow-mpgraph.mp afterwards] )
Output written on dblarrow.dvi (1 page, 916 bytes).
Transcript written on dblarrow.log.

            return code : 0
               run time : 0 seconds
    generating graphics : metaposting dblarrow-mpgraph.mp

TeXExec 5.4.3 - ConTeXt / PRAGMA ADE 1997-2005

               metapost : dblarrow-mpgraph
                 format : metafun
This is MetaPost, Version 0.901 (Web2C 7.5.5)
(/usr/local/teTeX/share/texmf.local/web2c/natural.tcx)
(dblarrow-mpgraph.mp [1]
! Redundant equation.
<to be read again>
                    ;
l.272 10u=w;

?

On Jun 26, 2006, at 1:35 PM, Mojca Miklavec wrote:

> On 6/26/06, David Arnold wrote:
>> Mojca,
>>
>> Doesn't compile at my end:
>>
>> This is MetaPost, Version 0.901 (Web2C 7.5.5)
>> (/usr/local/teTeX/share/texmf.local/web2c/natural.tcx)
>> (dblarrow-mpgraph.mp [1]
>> ! Redundant equation.
>> <to be read again>
>>                     ;
>> l.272 10u=w;
>
> Do you use some other high-level command to process the MP code? (Two
> graphics may not be processed in the same file unless you add an
> assignment instead.) What happens if you write u:=w/10?
>
> To Hans: thanks for the hint! (Slowly starting to believe that the
> code might indeed reach 4 lines ;)
>
> Mojca
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-26 23:04           ` Hans Hagen
@ 2006-06-27  2:27             ` David Arnold
  2006-06-27  9:01               ` Mojca Miklavec
  0 siblings, 1 reply; 17+ messages in thread
From: David Arnold @ 2006-06-27  2:27 UTC (permalink / raw)


I hope I get to see the final file. Nice work.

On Jun 26, 2006, at 4:04 PM, Hans Hagen wrote:

> Mojca Miklavec wrote:
>> On 6/27/06, Hans Hagen wrote:
>>
>>> Mojca Miklavec wrote:
>>>
>>>> To Hans: thanks for the hint! (Slowly starting to believe that the
>>>> code might indeed reach 4 lines ;)
>>>>
>>>>
>>> another one:
>>>
>>> vardef mytransform(expr pathorpicture) =
>>>   pathorpicture
>>>     if reflect=2:
>>>       reflectedabout((0,0),(1,1))
>>>     elseif reflect=3:
>>>       reflectedabout((0,0),(1,-1))
>>>     elseif reflect=4:
>>>       reflectedabout((-1,0),(1,0))
>>>     fi
>>> enddef;
>>>
>>> -)
>>>
>>
>> What a waste of space ;) !
>>
>> vardef mytransform(expr pathorpicture) =
>>  pathorpicture
>>    if reflect > 1: reflectedabout(
>>      if     reflect=2: (0,0),(1,1)
>>      elseif reflect=3: (0,0),(1,-1)
>>      elseif reflect=4: (-1,0),(1,0)
>>      fi)
>>    fi
>> enddef;
>>
>> (Slowly starting to believe that MP might become as horrible &
>> unreadable as perl ;)
>>
>>
> that's why i seldom go that far
>
> but the if inside an expresion is ok for me (many languages provide  
> that)
>
> of course a clean solution is:
>
> transform _mt_[] ; reflect := 1 ;
>
> _mt_[1] := identity ;
> _mt_[2] := identity reflectedabout(( 0,0),(1, 1)) ;
> _mt_[3] := identity reflectedabout(( 0,0),(1,-1)) ;
> _mt_[4] := identity reflectedabout((-1,0),(1, 0)) ;
>
> vardef mytransform(expr p) = p transformed _mt_[reflect] enddef; % one
> line -)
>
> draw mytransform(fullcircle scaled 10cm) ;
>
> draw fullcircle scaled 4cm transformed _mt_[reflect] ;
>
>
> Hans
>
> -----------------------------------------------------------------
>                                           Hans Hagen | PRAGMA ADE
>               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
>                                              | www.pragma-pod.nl
> -----------------------------------------------------------------
>
> _______________________________________________
> ntg-context mailing list
> ntg-context@ntg.nl
> http://www.ntg.nl/mailman/listinfo/ntg-context

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-27  2:27             ` David Arnold
@ 2006-06-27  9:01               ` Mojca Miklavec
  2006-06-27  9:32                 ` Hans Hagen
  0 siblings, 1 reply; 17+ messages in thread
From: Mojca Miklavec @ 2006-06-27  9:01 UTC (permalink / raw)


On 6/27/06, David Arnold wrote:
>
> TeXExec 5.4.3 - ConTeXt / PRAGMA ADE 1997-2005
> This is pdfeTeX, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5)
> ConTeXt  ver: 2006.03.20 10:19  fmt: 2006.3.21
>
> I hope I get to see the final file. Nice work.

You can see it here, but the only changes to your graphics can be seen
in the source, not in the final PDF:
    http://pub.mojca.org/tex/temp/dblarrow.pdf

I don't know what exactly has changed in ConTeXt that could influence
that specific behaviour (I guess that the graphics are simply
processed one after another instead of processing them separately),
but indeed I was able to reproduce the behaviour on contextgarden
(I'll try to write to Patrick once more - the garden still uses the
perl version and doesn't have all the variables set priperly, but he
seems to be extremely busy).

The (temporal) remedy for that is to use
    u:=w/10;
instead as I said last time, but then again the labels won't work as
they should. There might a remedy for that as well, but it's not worth
investigating it.

You probably have heard that trillions of times already, but you
*really*, *really* and again *really* should do two things before
trying to proceed:
- update your ConTeXt (just unzip the cont-tmf.zip over the old files;
later you'll be able to do that with ctxtools --update). Some
*enormous* changes were introduced to metafun graphics handling in
April and May.
- call ConTeXt with "texmfstart texexec". See the folder
texmf-local/scripts/stubs/unix. You should use it's content as the
source of executables.

texexec --version should return you
TeXExec | version 6.2.0 - 1997-2006 - PRAGMA ADE/POD

Mojca

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Clipping again
  2006-06-27  9:01               ` Mojca Miklavec
@ 2006-06-27  9:32                 ` Hans Hagen
  0 siblings, 0 replies; 17+ messages in thread
From: Hans Hagen @ 2006-06-27  9:32 UTC (permalink / raw)


Mojca Miklavec wrote:
> On 6/27/06, David Arnold wrote:
>   
>> TeXExec 5.4.3 - ConTeXt / PRAGMA ADE 1997-2005
>> This is pdfeTeX, Version 3.141592-1.30.4-2.2 (Web2C 7.5.5)
>> ConTeXt  ver: 2006.03.20 10:19  fmt: 2006.3.21
>>
>> I hope I get to see the final file. Nice work.
>>     
>
> You can see it here, but the only changes to your graphics can be seen
> in the source, not in the final PDF:
>     http://pub.mojca.org/tex/temp/dblarrow.pdf
>
> I don't know what exactly has changed in ConTeXt that could influence
> that specific behaviour (I guess that the graphics are simply
> processed one after another instead of processing them separately),
> but indeed I was able to reproduce the behaviour on contextgarden
> (I'll try to write to Patrick once more - the garden still uses the
> perl version and doesn't have all the variables set priperly, but he
> seems to be extremely busy).
>   
when you do runtime processing, each graphic is on its own, otherwise 
you can indeed run into redundant equations, just change = into := then 
or do a proper allocation of local vars (numeric u ; etc)

Hans


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2006-06-27  9:32 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-25 19:19 Clipping again David Arnold
2006-06-25 19:37 ` Mojca Miklavec
2006-06-25 19:58   ` David Arnold
2006-06-25 20:14     ` Mojca Miklavec
2006-06-26  0:51       ` David Arnold
2006-06-25 21:32 ` Hans Hagen
2006-06-26  9:39 ` Mojca Miklavec
2006-06-26 15:01   ` Hans Hagen
2006-06-26 19:51   ` David Arnold
2006-06-26 20:35     ` Mojca Miklavec
2006-06-26 22:30       ` Hans Hagen
2006-06-26 22:44         ` Mojca Miklavec
2006-06-26 23:04           ` Hans Hagen
2006-06-27  2:27             ` David Arnold
2006-06-27  9:01               ` Mojca Miklavec
2006-06-27  9:32                 ` Hans Hagen
2006-06-27  1:04       ` David Arnold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).