Hi Wade, yeah, that's exactly the sort of thing I'm doing. Seems like
inventing a loopless way of doing it would be sorta fun, but maybe a bit
difficult to handle all the situations in which one might do it. As you
point out though, it does seem to arise frequently!

 

Cheers

David

 

From: [email protected] [mailto:[email protected]]
On Behalf Of G. Wade Johnson
Sent: Thursday, November 08, 2012 11:28 PM
To: [email protected]
Subject: Re: [svg-developers] an SVG /Javascript question

 

  

Hi David,

On Thu, 8 Nov 2012 20:10:06 -0500
"David Dailey" <[email protected] <mailto:ddailey%40zoominternet.net>
> wrote:

> In order to perform transform operations in script rather than doing
> it declaratively (whence the stack of transforms can become gnarly),
> I was thinking about ways to simplify the code (from the human rather
> than the computational perspective). By such perspective, the minimum
> number of statements is to be optimized rather than minimizing
> run-time - I know it is a funny metric, but people have been looking
> at things like this since the 1970's believe it or not.
> 
> 
> 
> Anyhow, I wanted to develop a function which would take the d
> attribute of paths or glyphs (of any sort):
> 
> 
> 
> d="M 1550 710.5 Q 1650 840 1610.5 920.5 Q 1580 1010 1130.5 970 Q 690
> 930 840 810 Q 990 690 1010.5 450.5 Q 1040 220 1190 190.5 Q 1340 170
> 1480.5 210 Q 1630 250 1540 420 Q 1450 590 1550 710.5 M 940.5 860.5 Q
> 610 1100 630.5 1170 Q 660 1240 770 1250.5 Q 880 1270 1110.5 1270 Q
> 1350 1270 1610 1300 Q 1870 1330 1920 1250.5 Q 1970 1180 1810 1060 Q
> 1650 940 1460.5 780.5 Q 1280 630 940.5 860.5 z"
> 
> 
> 
> Or
> 
> 
> 
> d="M50,100
> 
> A100,50 0 0 1 250,100
> 
> A80,40 0 0 1 90,100
> 
> A60,30 0 0 1 210,100
> 
> A40,20 0 0 1 130,100
> 
> A20,10 0 0 1 170,100"

This description reminds me of a kind of functional programming
approach I've used in the past.

In pseudo-code, it would do something like

new_d = join_command( transform_A(
function(a) { /* do something to each A */ },
split_commands( d )
)
);

The split_commands function would return a list of commands.
The transform_A function would identify A commands and apply the
supplied function to each, returning a modified A. The transform_A
function would then return the modified A commands along with the
original of any non-A commands.

Obviously, there would be a transform_M, etc. for each command type.

As an alternative, you could use a generic transform() that expects the
supplied function to recognize the command, parse it, modify the result
and put it back together.

I like the individual transform_* style because the identifying and
parsing/recombining logic would be hidden inside that one function.

The result would still require loop work, but it would be inside the
split_command, transform_*, and join_command functions.

This style takes a little getting used to, but it can be quite powerful
for problems with this structure.

HTH,
G. Wade

> and then separate the subcommands (A,M, Q, L, l, s, z, etc) from the
> coordinates thusly
> 
> 
> 
> A=d.match(/regexp/g)
> 
> B=d.split(/regexp/g)
> 
> 
> 
> And then perform arithmetic on all i in A and then join everything
> back together in one swell foop:
> 
> 
> 
> C=d.gaps(/regexp/g,/regexp2/g) (where the mythical "gaps" method of
> the array object would return an array of the number of
> regexp2-delimited items between A's boundaries)
> 
> 
> 
> The properly defined "gaps" method would then allow something like
> 
> 
> 
> D=superJoin(A,B,C) ==d
> 
> And D=superjoin (A,arithmetic(B),C) == transform(d) 
> 
> 
> 
> As it is, I'm going to have to write loops to walk through the
> structure, pushing operators, numbers and coordinates onto separate
> stacks and then to loop through again to reconstitute the whole mess.
> Not a terrible thing, but .. Such tedium!
> 
> 
> 
> Any ideas if such a construct has been posited before? It would be
> very handy for SVG path processing. 
> 
> 
> 
> Cheers
> 
> David
> 
> 
> 
> [Non-text portions of this message have been removed]
> 





[Non-text portions of this message have been removed]



------------------------------------

-----
To unsubscribe send a message to: [email protected]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
----Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/svg-developers/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to