Catmull-Rom interpolation on SVG Paths - svg
I am experimenting with creating high-performance, good-looking pencil tools using SVG paths.
I am logging the mouse coordinates to draw a path. To get a high-fidelity path (accurate to the user's movements) I need to log a point for every pixel movement.
Keeping each and every point in the path creates a huge amount of points which is not ideal for collaborative features later-on (sending huge amount of points back and forth is not efficient), plus parsing huge paths every time I need to manipulate them is a bottleneck
On linear areas of the path, redundant points are removed keeping only the points necessary to represent the segment - I do this using the Ramer-Douglas-Peucker algorithm.
But simplifying a path turns it into a low-fidelity polygon
At this point the paths are effectively just connected lines - therefore the paths look jagged.
A possible solution is to connect the path points with Cubic Bezier's - however this doesn't work nice on simplified paths. The distance between each point is too large for the Cubic Bezier's to "sit" nice so the smoothed path no longer accurately represents the intended path of the user.
Another solution is to simply use a "post-processing" algorithm such as Schneider's Algorithm on the original path - This algorithm won't practically work in real-time though since it's a performance hog
An ideal solution
A solution that(I think) could work is to use a Centripetal Catmull-Rom interpolation.
Out of all the algorithms I researched, this seems to be the most promising since:
It doesn't create self-intersections on tight corners
It fits more snug on the points thus it more accurately represents the
original path.
Is Catmull-Rom an algorithm that interpolates a series of
regular x/y points or does the original path need to be comprised of
curves?
To answer your questions directly:
Yes. Catmull-Rom spline is an algorithm to interpolate a series of (x, y, z) points. It will generate a cubic polynomial curve between each two consecutive points.
You cannot direcly use Catmull Rom spline for SVG path. You need to convert it to cubic Bezier curve first.
For a curve segment defined by point P0, P1, P2 and P3 and knot sequence t0, t1, t2, t3, the centripetal Catmull-Rom spline (defined between point P1 and P2) can be computed by the recursive formula provided in https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline. Therefore, I will not elaborate here.
To convert it to cubic Bezier curve, you need to compute the first
derivative at P1 and P2 as
M1 = (t2-t1)*(c1*(P1-P0)/(t1-t0) + c2*(P2-P1)/(t2-t1))
M2 = (t2-t1)*(d1*(P2-P1)/(t2-t1) + d2*(P3-P2)/(t3-t2))
Where
c1 = (t2-t1)/(t2-t0),
c2 = (t1-t0)/(t2-t0),
d1 = (t3-t2)/(t3-t1),
d2 = (t2-t1)/(t3-t1)
Then you can convert it to cubic Bezier curve with 4 control points: Q0, Q1, Q2 and Q3:
Q0 = P1
Q1 = P1 + M1/3
Q2 = P2 - M2/3
Q3 = P2
I use interpolation cubics for this
sample point on
mouse direction change in any axis
if mouse traveled some distance for more precision can add: if the angle of direction change too much (I do not use this)
if mouse stops (this can be ignored if you use on mouse up/down too)
use the sampled points as control points for interpolation cubic
see Interpolation cubic vs. Bezier cubic you find there also the transformation between interpolation and Bezier cubic
if that is not enough you can join lines with the same direction
Here an example of hand drawings in this way:
And the SVG:
<svg width="512" height="512" viewBox="-131.734968 -63.890725 383.802249 203.65153" >
<path fill="none" stroke="black" stroke-width="1px" data-tool="-1" data-cfg="-1" data-group="-1" data-hair="0" data-dir="0" transform="matrix(1,0,0,1,0,0" d="M -81.842337 36.317509 c 0 0 -0.494188 0.282842 0 0 c 0 0 4.1653 -2.262737 4.447693 -2.545579 c 0.494188 -0.282842 2.188547 -2.262737 2.541539 -2.545579 c 0.282393 -0.282842 2.823932 -2.192026 3.176923 -2.545579 c 0.352991 -0.282842 2.965128 -2.828421 3.176923 -3.181974 c 0.352991 -0.353552 1.623761 -2.899132 1.906154 -3.181974 c 0.211794 -0.353552 2.329744 -2.192026 2.541539 -2.545579 c 0.282393 -0.282842 1.623761 -2.969842 1.906154 -3.181974 c 0.211794 -0.353552 2.400342 -1.697053 2.541539 -1.909184 c 0.282393 -0.212131 0.988376 -1.626342 1.270769 -1.909184 c 0.141196 -0.212131 2.329744 -2.333447 2.541539 -2.545579 c 0.282393 -0.282842 1.411966 -1.626342 1.906154 -1.909184 c 0.211794 -0.212131 3.953505 -2.474869 4.447693 -2.545579 c 0.494188 -0.282842 4.024103 -0.565684 4.447693 -0.636394 c 0.494188 -0.07071 3.247522 -0.494973 3.812308 -0.636394 c 0.423589 -0.07071 4.730086 -1.272789 5.083078 -1.272789 c 0.564786 -0.141421 2.823932 0 3.176923 0 c 0.352991 0 2.823932 0 3.176923 0 c 0.352991 0 2.753333 0 3.176923 0 c 0.352991 0 3.31812 -0.212131 3.812308 0 c 0.423589 0 4.024103 1.626342 4.447693 1.909184 c 0.494188 0.212131 3.459317 2.192026 3.812308 2.545579 c 0.423589 0.282842 2.965128 2.828421 3.176923 3.181974 c 0.352991 0.353552 1.764957 2.61629 1.906154 3.181974 c 0.211794 0.353552 1.270769 4.454764 1.270769 5.091159 c 0.141196 0.565684 0 5.23258 0 5.727554 c 0 0.636394 0 3.889079 0 4.454764 c 0 0.494973 -0.070598 4.596185 0 5.091159 c 0 0.565684 0.423589 4.101211 0.635384 4.454764 c 0.070598 0.494973 1.623761 2.899132 1.906154 3.181974 c 0.211794 0.353552 1.976752 2.474869 2.541539 2.545579 c 0.282393 0.282842 4.730086 0.636394 5.083078 0.636394 c 0.564786 0.07071 2.753333 0 3.176923 0 c 0.352991 0 3.529915 0 3.812308 0 c 0.423589 0 2.04735 0 2.541539 0 c 0.282393 0 4.024103 0 4.447693 0 c 0.494188 0 3.459317 0.07071 3.812308 0 c 0.423589 0 2.89453 -0.565684 3.176923 -0.636394 c 0.352991 -0.07071 2.04735 -0.353552 2.541539 -0.636394 c 0.282393 -0.07071 4.235898 -2.404158 4.447693 -2.545579 c 0.494188 -0.282842 1.482564 -0.989947 1.906154 -1.272789 c 0.211794 -0.141421 3.600513 -2.262737 3.812308 -2.545579 c 0.423589 -0.282842 1.694359 -2.262737 1.906154 -2.545579 c 0.211794 -0.282842 1.623761 -2.192026 1.906154 -2.545579 c 0.211794 -0.282842 2.329744 -2.969842 2.541539 -3.181974 c 0.282393 -0.353552 1.553162 -1.555631 1.906154 -1.909184 c 0.211794 -0.212131 2.823932 -2.899132 3.176923 -3.181974 c 0.352991 -0.353552 2.823932 -2.333447 3.176923 -2.545579 c 0.352991 -0.282842 2.753333 -1.697053 3.176923 -1.909184 c 0.352991 -0.212131 3.459317 -1.838474 3.812308 -1.909184 c 0.423589 -0.212131 2.823932 -0.565684 3.176923 -0.636394 c 0.352991 -0.07071 2.823932 -0.636394 3.176923 -0.636394 c 0.352991 -0.07071 2.823932 0 3.176923 0 c 0.352991 0 2.541539 -0.07071 3.176923 0 c 0.352991 0 5.436069 0.353552 5.718462 0.636394 c 0.635384 0.07071 2.400342 2.050605 2.541539 2.545579 c 0.282393 0.282842 1.058974 4.030501 1.270769 4.454764 c 0.141196 0.494973 1.835555 3.394106 1.906154 3.818369 c 0.211794 0.424263 0.423589 3.323395 0.635384 3.818369 c 0.070598 0.424263 1.553162 3.95979 1.906154 4.454764 c 0.211794 0.494973 2.753333 4.313343 3.176923 4.454764 c 0.352991 0.494973 3.459317 1.131368 3.812308 1.272789 c 0.423589 0.141421 2.823932 1.202079 3.176923 1.272789 c 0.352991 0.141421 2.682735 0.636394 3.176923 0.636394 c 0.352991 0.07071 3.74171 0 4.447693 0 c 0.494188 0 6.000856 0 6.353847 0 c 0.705983 0 2.753333 0 3.176923 0 c 0.352991 0 3.459317 0.07071 3.812308 0 c 0.423589 0 2.682735 -0.424263 3.176923 -0.636394 c 0.352991 -0.07071 4.1653 -1.697053 4.447693 -1.909184 c 0.494188 -0.212131 2.259145 -1.697053 2.541539 -1.909184 c 0.282393 -0.212131 2.04735 -1.697053 2.541539 -1.909184 c 0.282393 -0.212131 4.235898 -1.626342 4.447693 -1.909184 c 0.494188 -0.212131 1.553162 -2.333447 1.906154 -2.545579 c 0.211794 -0.282842 2.753333 -1.697053 3.176923 -1.909184 c 0.352991 -0.212131 3.529915 -1.767763 3.812308 -1.909184 c 0.423589 -0.212131 2.04735 -1.202079 2.541539 -1.272789 c 0.282393 -0.141421 4.094701 -0.636394 4.447693 -0.636394 c 0.494188 -0.07071 2.823932 0 3.176923 0 c 0.352991 0 2.823932 0 3.176923 0 c 0.352991 0 2.753333 0 3.176923 0 c 0.352991 0 3.388718 -0.212131 3.812308 0 c 0.423589 0 3.388718 1.767763 3.812308 1.909184 c 0.423589 0.212131 3.459317 0.919237 3.812308 1.272789 c 0.423589 0.141421 2.965128 2.969842 3.176923 3.181974 c 0.352991 0.353552 1.764957 1.555631 1.906154 1.909184 c 0.211794 0.212131 1.058974 2.899132 1.270769 3.181974 c 0.141196 0.353552 1.835555 2.192026 1.906154 2.545579 c 0.211794 0.282842 0.352991 2.828421 0.635384 3.181974 c 0.070598 0.353552 2.259145 2.899132 2.541539 3.181974 c 0.282393 0.353552 2.117949 2.474869 2.541539 2.545579 c 0.282393 0.282842 3.459317 0.565684 3.812308 0.636394 c 0.423589 0.07071 2.823932 0.636394 3.176923 0.636394 c 0.352991 0.07071 2.823932 -0.07071 3.176923 0 c 0.352991 0 2.753333 0.565684 3.176923 0.636394 c 0.352991 0.07071 3.459317 0.636394 3.812308 0.636394 c 0.423589 0.07071 2.823932 0 3.176923 0 c 0.352991 0 2.682735 0.07071 3.176923 0 c 0.352991 0 4.1653 -0.636394 4.447693 -0.636394 c 0.494188 -0.07071 2.188547 0.212131 2.541539 0 c 0.282393 0 2.682735 -1.697053 3.176923 -1.909184 c 0.352991 -0.212131 4.235898 -1.767763 4.447693 -1.909184 c 0.494188 -0.212131 1.623761 -1.131368 1.906154 -1.272789 c 0.211794 -0.141421 2.329744 -1.060658 2.541539 -1.272789 c 0.282393 -0.141421 1.906154 -1.909184 1.906154 -1.909184 c 0.211794 -0.212131 0 0 0 0m -334.847767 40.092879 c 0 0 -0.352991 -0.141421 0 0 c 0 0 2.682735 1.131368 3.176923 1.272789 c 0.352991 0.141421 4.1653 1.202079 4.447693 1.272789 c 0.494188 0.141421 2.259145 0.494973 2.541539 0.636394 c 0.282393 0.07071 2.188547 1.202079 2.541539 1.272789 c 0.282393 0.141421 2.823932 0.565684 3.176923 0.636394 c 0.352991 0.07071 2.753333 0.565684 3.176923 0.636394 c 0.352991 0.07071 3.459317 0.636394 3.812308 0.636394 c 0.423589 0.07071 2.823932 0 3.176923 0 c 0.352991 0 2.823932 0 3.176923 0 c 0.352991 0 2.823932 0 3.176923 0 c 0.352991 0 2.89453 0 3.176923 0 c 0.352991 0 2.188547 0 2.541539 0 c 0.282393 0 2.823932 0 3.176923 0 c 0.352991 0 2.753333 0 3.176923 0 c 0.352991 0 3.529915 0.141421 3.812308 0 c 0.423589 0 2.04735 -0.989947 2.541539 -1.272789 c 0.282393 -0.141421 4.1653 -2.262737 4.447693 -2.545579 c 0.494188 -0.282842 2.329744 -2.192026 2.541539 -2.545579 c 0.282393 -0.282842 1.835555 -2.687 1.906154 -3.181974 c 0.211794 -0.353552 0.564786 -3.95979 0.635384 -4.454764 c 0.070598 -0.494973 1.200171 -4.242632 0.635384 -4.454764 c 0.070598 -0.494973 -4.659488 -2.050605 -5.083078 -1.909184 c -0.564786 -0.212131 -3.529915 0.989947 -3.812308 1.272789 c -0.423589 0.141421 -2.188547 1.979895 -2.541539 2.545579 c -0.282393 0.282842 -3.176923 4.525474 -3.176923 5.091159 c -0.352991 0.565684 0 4.525474 0 5.091159 c 0 0.565684 -0.282393 4.808317 0 5.091159 c 0 0.565684 2.259145 2.474869 2.541539 2.545579 c 0.282393 0.282842 2.117949 0.424263 2.541539 0.636394 c 0.282393 0.07071 3.388718 1.838474 3.812308 1.909184 c 0.423589 0.212131 3.247522 0.565684 3.812308 0.636394 c 0.423589 0.07071 4.588889 0.636394 5.083078 0.636394 c 0.564786 0.07071 4.1653 0 4.447693 0 c 0.494188 0 2.04735 0 2.541539 0 c 0.282393 0 3.953505 0 4.447693 0 c 0.494188 0 3.671111 0.212131 4.447693 0 c 0.494188 0 6.565642 -1.838474 6.989232 -1.909184 c 0.776581 -0.212131 3.459317 -0.424263 3.812308 -0.636394 c 0.423589 -0.07071 2.753333 -1.767763 3.176923 -1.909184 c 0.352991 -0.212131 3.459317 -0.989947 3.812308 -1.272789 c 0.423589 -0.141421 2.823932 -2.050605 3.176923 -2.545579 c 0.352991 -0.282842 3.106325 -4.030501 3.176923 -4.454764 c 0.352991 -0.494973 1.058974 -3.676948 0.635384 -3.818369 c 0.070598 -0.424263 -3.388718 -1.484921 -3.812308 -1.272789 c -0.423589 -0.141421 -3.459317 1.697053 -3.812308 1.909184 c -0.423589 0.212131 -2.823932 1.626342 -3.176923 1.909184 c -0.352991 0.212131 -2.89453 2.262737 -3.176923 2.545579 c -0.352991 0.282842 -2.47094 2.050605 -2.541539 2.545579 c -0.282393 0.282842 -0.635384 3.889079 -0.635384 4.454764 c -0.070598 0.494973 -0.282393 4.808317 0 5.091159 c 0 0.565684 2.329744 2.404158 2.541539 2.545579 c 0.282393 0.282842 1.623761 1.131368 1.906154 1.272789 c 0.211794 0.141421 2.259145 1.202079 2.541539 1.272789 c 0.282393 0.141421 1.976752 0.424263 2.541539 0.636394 c 0.282393 0.07071 4.588889 1.909184 5.083078 1.909184 c 0.564786 0.212131 3.882906 -0.07071 4.447693 0 c 0.494188 0 4.800684 0.636394 5.083078 0.636394 c 0.564786 0.07071 2.188547 0 2.541539 0 c 0.282393 0 2.823932 -0.07071 3.176923 0 c 0.352991 0 2.612137 0.636394 3.176923 0.636394 c 0.352991 0.07071 4.730086 0 5.083078 0 c 0.564786 0 2.89453 0 3.176923 0 c 0.352991 0 2.188547 0.07071 2.541539 0 c 0.282393 0 2.753333 -0.494973 3.176923 -0.636394 c 0.352991 -0.07071 3.247522 -0.989947 3.812308 -1.272789 c 0.423589 -0.141421 4.730086 -2.333447 5.083078 -2.545579 c 0.564786 -0.282842 2.89453 -1.555631 3.176923 -1.909184 c 0.352991 -0.212131 2.400342 -2.969842 2.541539 -3.181974 c 0.282393 -0.353552 1.129572 -1.484921 1.270769 -1.909184 c 0.141196 -0.212131 1.270769 -3.394106 1.270769 -3.818369 c 0.141196 -0.424263 0 -3.394106 0 -3.818369 c 0 -0.424263 0.352991 -3.606237 0 -3.818369 c 0 -0.424263 -2.682735 -1.909184 -3.176923 -1.909184 c -0.352991 -0.212131 -4.024103 -0.07071 -4.447693 0 c -0.494188 0 -3.671111 0.353552 -3.812308 0.636394 c -0.423589 0.07071 -1.200171 1.979895 -1.270769 2.545579 c -0.141196 0.282842 -0.705983 4.525474 -0.635384 5.091159 c -0.070598 0.565684 0.352991 4.666895 0.635384 5.091159 c 0.070598 0.565684 2.259145 3.535527 2.541539 3.818369 c 0.282393 0.424263 2.259145 2.333447 2.541539 2.545579 c 0.282393 0.282842 2.04735 1.626342 2.541539 1.909184 c 0.282393 0.212131 3.882906 2.333447 4.447693 2.545579 c 0.494188 0.282842 4.800684 1.909184 5.083078 1.909184 c 0.564786 0.212131 2.188547 -0.212131 2.541539 0 c 0.282393 0 2.89453 1.909184 3.176923 1.909184 c 0.352991 0.212131 2.04735 -0.141421 2.541539 0 c 0.282393 0 4.024103 1.131368 4.447693 1.272789 c 0.494188 0.141421 3.247522 1.272789 3.812308 1.272789 c 0.423589 0.141421 4.800684 0 5.083078 0 c 0.564786 0 2.188547 0 2.541539 0 c 0.282393 0 2.823932 0 3.176923 0 c 0.352991 0 2.823932 0 3.176923 0 c 0.352991 0 2.682735 0 3.176923 0 c 0.352991 0 4.1653 0 4.447693 0 c 0.494188 0 2.188547 0.07071 2.541539 0 c 0.282393 0 2.823932 -0.565684 3.176923 -0.636394 c 0.352991 -0.07071 2.823932 -0.424263 3.176923 -0.636394 c 0.352991 -0.07071 2.612137 -1.626342 3.176923 -1.909184 c 0.352991 -0.212131 4.800684 -2.333447 5.083078 -2.545579 c 0.564786 -0.282842 2.188547 -1.626342 2.541539 -1.909184 c 0.282393 -0.212131 2.89453 -2.262737 3.176923 -2.545579 c 0.352991 -0.282842 2.329744 -2.192026 2.541539 -2.545579 c 0.282393 -0.282842 1.764957 -2.61629 1.906154 -3.181974 c 0.211794 -0.353552 1.270769 -4.384053 1.270769 -5.091159 c 0.141196 -0.565684 0.635384 -6.222527 0 -6.363949 c 0 -0.707105 -5.294872 -1.202079 -5.718462 -1.272789 c -0.635384 -0.141421 -3.31812 -0.636394 -3.812308 -0.636394 c -0.423589 -0.07071 -4.094701 -0.353552 -4.447693 0 c -0.494188 0 -3.176923 2.61629 -3.176923 3.181974 c -0.352991 0.353552 0 4.525474 0 5.091159 c 0 0.565684 -0.211794 4.525474 0 5.091159 c 0 0.565684 1.694359 4.949738 1.906154 5.091159 c 0.211794 0.565684 1.694359 1.060658 1.906154 1.272789 c 0.211794 0.141421 1.694359 1.767763 1.906154 1.909184 c 0.211794 0.212131 1.694359 1.131368 1.906154 1.272789 c 0.211794 0.141421 1.553162 0.989947 1.906154 1.272789 c 0.211794 0.141421 2.89453 2.404158 3.176923 2.545579 c 0.352991 0.282842 2.259145 1.202079 2.541539 1.272789 c 0.282393 0.141421 2.259145 0.494973 2.541539 0.636394 c 0.282393 0.07071 2.117949 1.131368 2.541539 1.272789 c 0.282393 0.141421 3.388718 1.202079 3.812308 1.272789 c 0.423589 0.141421 3.459317 0.494973 3.812308 0.636394 c 0.423589 0.07071 2.823932 1.272789 3.176923 1.272789 c 0.352991 0.141421 2.89453 0 3.176923 0 c 0.352991 0 2.188547 0 2.541539 0 c 0.282393 0 2.823932 0 3.176923 0 c 0.352991 0 2.823932 0 3.176923 0 c 0.352991 0 2.89453 0 3.176923 0 c 0.352991 0 2.188547 0 2.541539 0 c 0.282393 0 2.753333 0.07071 3.176923 0 c 0.352991 0 3.388718 -0.494973 3.812308 -0.636394 c 0.423589 -0.07071 3.388718 -0.919237 3.812308 -1.272789 c 0.423589 -0.141421 3.600513 -2.61629 3.812308 -3.181974 c 0.423589 -0.353552 1.835555 -4.596185 1.906154 -5.091159 c 0.211794 -0.565684 0.635384 -3.889079 0.635384 -4.454764 c 0.070598 -0.494973 0.211794 -4.525474 0 -5.091159 c 0 -0.565684 -1.553162 -4.879027 -1.906154 -5.091159 c -0.211794 -0.565684 -2.47094 -1.979895 -3.176923 -1.909184 c -0.352991 -0.212131 -6.142052 0.353552 -6.353847 0.636394 c -0.705983 0.07071 -1.694359 2.192026 -1.906154 2.545579 c -0.211794 0.282842 -1.835555 2.757711 -1.906154 3.181974 c -0.211794 0.353552 -0.564786 3.323395 -0.635384 3.818369 c -0.070598 0.424263 -0.776581 4.030501 -0.635384 4.454764 c -0.070598 0.494973 1.058974 3.535527 1.270769 3.818369 c 0.141196 0.424263 1.482564 2.333447 1.906154 2.545579 c 0.211794 0.282842 3.600513 1.767763 3.812308 1.909184 c 0.423589 0.212131 1.482564 1.131368 1.906154 1.272789 c 0.211794 0.141421 3.31812 1.131368 3.812308 1.272789 c 0.423589 0.141421 4.024103 1.202079 4.447693 1.272789 c 0.494188 0.141421 3.459317 0.636394 3.812308 0.636394 c 0.423589 0.07071 2.682735 0 3.176923 0 c 0.352991 0 4.094701 0 4.447693 0 c 0.494188 0 2.89453 0 3.176923 0 c 0.352991 0 2.117949 0 2.541539 0 c 0.282393 0 3.459317 0 3.812308 0 c 0.423589 0 2.89453 0.141421 3.176923 0 c 0.352991 0 2.04735 -1.060658 2.541539 -1.272789 c 0.282393 -0.141421 4.024103 -1.626342 4.447693 -1.909184 c 0.494188 -0.212131 3.600513 -2.333447 3.812308 -2.545579 c 0.423589 -0.282842 1.623761 -1.484921 1.906154 -1.909184 c 0.211794 -0.212131 2.400342 -3.676948 2.541539 -3.818369 c 0.282393 -0.424263 1.270769 -1.272789 1.270769 -1.272789 c 0.141196 -0.141421 0 0 0 0m -261.143135 -114.551083 c 0 0 -0.352991 0.212131 0 0 c 0 0 2.823932 -1.767763 3.176923 -1.909184 c 0.352991 -0.212131 2.89453 -1.202079 3.176923 -1.272789 c 0.352991 -0.141421 2.259145 -0.424263 2.541539 -0.636394 c 0.282393 -0.07071 2.117949 -1.626342 2.541539 -1.909184 c 0.282393 -0.212131 3.600513 -2.262737 3.812308 -2.545579 c 0.423589 -0.282842 1.623761 -2.404158 1.906154 -2.545579 c 0.211794 -0.282842 2.188547 -0.848526 2.541539 -1.272789 c 0.282393 -0.141421 2.89453 -3.464816 3.176923 -3.818369 c 0.352991 -0.424263 2.47094 -2.828421 2.541539 -3.181974 c 0.282393 -0.353552 0.423589 -2.828421 0.635384 -3.181974 c 0.070598 -0.353552 1.764957 -2.969842 1.906154 -3.181974 c 0.211794 -0.353552 1.270769 -2.474869 1.270769 -1.909184 c 0.141196 -0.212131 0 4.737606 0 5.091159 c 0 0.565684 -0.141196 2.828421 0 3.181974 c 0 0.353552 1.129572 2.757711 1.270769 3.181974 c 0.141196 0.353552 1.129572 3.323395 1.270769 3.818369 c 0.141196 0.424263 1.058974 4.030501 1.270769 4.454764 c 0.141196 0.494973 1.553162 3.323395 1.906154 3.818369 c 0.211794 0.424263 2.89453 4.171922 3.176923 4.454764 c 0.352991 0.494973 2.117949 2.404158 2.541539 2.545579 c 0.282393 0.282842 3.459317 1.060658 3.812308 1.272789 c 0.423589 0.141421 2.753333 1.909184 3.176923 1.909184 c 0.352991 0.212131 3.31812 0.212131 3.812308 0 c 0.423589 0 4.235898 -1.767763 4.447693 -1.909184 c 0.494188 -0.212131 1.411966 -0.919237 1.906154 -1.272789 c 0.211794 -0.141421 4.1653 -2.828421 4.447693 -3.181974 c 0.494188 -0.353552 1.976752 -2.687 2.541539 -3.181974 c 0.282393 -0.353552 4.800684 -4.101211 5.083078 -4.454764 c 0.564786 -0.494973 2.400342 -2.899132 2.541539 -3.181974 c 0.282393 -0.353552 1.058974 -2.262737 1.270769 -2.545579 c 0.141196 -0.282842 1.623761 -2.121316 1.906154 -2.545579 c 0.211794 -0.282842 2.259145 -3.323395 2.541539 -3.818369 c 0.282393 -0.424263 2.329744 -4.737606 2.541539 -4.454764 c 0.282393 -0.494973 1.835555 2.192026 1.906154 2.545579 c 0.211794 0.282842 0.564786 2.757711 0.635384 3.181974 c 0.070598 0.353552 0.494188 3.323395 0.635384 3.818369 c 0.070598 0.424263 1.129572 3.95979 1.270769 4.454764 c 0.141196 0.494973 1.058974 3.95979 1.270769 4.454764 c 0.141196 0.494973 1.553162 4.101211 1.906154 4.454764 c 0.211794 0.494973 3.035727 2.969842 3.176923 3.181974 c 0.352991 0.353552 0.776581 1.767763 1.270769 1.909184 c 0.141196 0.212131 3.953505 1.272789 4.447693 1.272789 c 0.494188 0.141421 4.094701 0 4.447693 0 c 0.494188 0 2.753333 0 3.176923 0 c 0.352991 0 3.388718 0.141421 3.812308 0 c 0.423589 0 3.388718 -1.060658 3.812308 -1.272789 c 0.423589 -0.141421 3.529915 -1.555631 3.812308 -1.909184 c 0.423589 -0.212131 2.259145 -2.899132 2.541539 -3.181974 c 0.282393 -0.353552 2.329744 -2.192026 2.541539 -2.545579 c 0.282393 -0.282842 1.764957 -2.828421 1.906154 -3.181974 c 0.211794 -0.353552 1.129572 -2.969842 1.270769 -3.181974 c 0.141196 -0.353552 0.988376 -1.555631 1.270769 -1.909184 c 0.141196 -0.212131 2.188547 -3.040553 2.541539 -3.181974 c 0.282393 -0.353552 3.106325 -1.767763 3.176923 -1.272789 c 0.352991 -0.141421 0.494188 3.95979 0.635384 4.454764 c 0.070598 0.494973 1.200171 4.030501 1.270769 4.454764 c 0.141196 0.494973 0.494188 3.252685 0.635384 3.818369 c 0.070598 0.424263 1.058974 4.666895 1.270769 5.091159 c 0.141196 0.565684 1.694359 3.394106 1.906154 3.818369 c 0.211794 0.424263 1.623761 3.464816 1.906154 3.818369 c 0.211794 0.424263 2.117949 2.899132 2.541539 3.181974 c 0.282393 0.353552 3.388718 2.474869 3.812308 2.545579 c 0.423589 0.282842 3.31812 0.636394 3.812308 0.636394 c 0.423589 0.07071 4.024103 0 4.447693 0 c 0.494188 0 3.31812 0 3.812308 0 c 0.423589 0 4.024103 0.07071 4.447693 0 c 0.494188 0 3.31812 -0.353552 3.812308 -0.636394 c 0.423589 -0.07071 4.024103 -2.262737 4.447693 -2.545579 c 0.494188 -0.282842 3.388718 -2.192026 3.812308 -2.545579 c 0.423589 -0.282842 3.600513 -2.899132 3.812308 -3.181974 c 0.423589 -0.353552 1.623761 -2.333447 1.906154 -2.545579 c 0.211794 -0.282842 2.400342 -1.555631 2.541539 -1.909184 c 0.282393 -0.212131 0.917777 -2.828421 1.270769 -3.181974 c 0.141196 -0.353552 3.035727 -2.757711 3.176923 -3.181974 c 0.352991 -0.353552 0.988376 -3.889079 1.270769 -3.818369 c 0.141196 -0.424263 2.47094 0.282842 2.541539 0.636394 c 0.282393 0.07071 0.635384 2.757711 0.635384 3.181974 c 0.070598 0.353552 -0.070598 3.464816 0 3.818369 c 0 0.424263 0.564786 2.61629 0.635384 3.181974 c 0.070598 0.353552 0.564786 4.666895 0.635384 5.091159 c 0.070598 0.565684 0.494188 3.464816 0.635384 3.818369 c 0.070598 0.424263 0.988376 2.757711 1.270769 3.181974 c 0.141196 0.353552 1.976752 3.818369 2.541539 3.818369 c 0.282393 0.424263 4.800684 0 5.083078 0 c 0.564786 0 2.04735 0 2.541539 0 c 0.282393 0 4.094701 0 4.447693 0 c 0.494188 0 2.753333 0 3.176923 0 c 0.352991 0 3.388718 0.212131 3.812308 0 c 0.423589 0 3.459317 -1.697053 3.812308 -1.909184 c 0.423589 -0.212131 2.823932 -1.555631 3.176923 -1.909184 c 0.352991 -0.212131 2.89453 -2.969842 3.176923 -3.181974 c 0.352991 -0.353552 2.259145 -1.555631 2.541539 -1.909184 c 0.282393 -0.212131 2.259145 -2.899132 2.541539 -3.181974 c 0.282393 -0.353552 2.188547 -2.192026 2.541539 -2.545579 c 0.282393 -0.282842 2.89453 -2.828421 3.176923 -3.181974 c 0.352991 -0.353552 2.47094 -2.899132 2.541539 -3.181974 c 0.282393 -0.353552 0.635384 -2.545579 0.635384 -2.545579 c 0.070598 -0.282842 0 0 0 0 "/>
</svg>
It is around 20KB if you play with tresholds you can lower the point count significantly. This is tweaked to suit my needs.
Here example of how the mouse follow feels during drawing (captured in realtime during drawing)
On the Parameterization of Catmull-Rom Curves
see the formula[2]
Online Demo
Related
Scraping multiple links with bs4 and request
I'm new to this please go easy on me. So i want to scrape name and number of multiple pages but only scraping first url. Also the code is scraping only one item either Name Or Phone Number. Name is in "h2" class "c411ListedName" and number is in 'span' class "c411Phone" import csv import requests from bs4 import BeautifulSoup urls = ['https://www.canada411.ca/search/si/1/kumar/Canada/?pgLen=100','https://www.canada411.ca/search/si/2/kumar/Canada/?pgLen=100'] for url in urls: response = requests.get(url) html = requests.get(url).text soup = BeautifulSoup(response.content, "html.parser") products = soup.findAll('span','h2', class_=['c411Phone', 'c411ListedName']) for div in products: print(div.text)
What happens Your requesting both urls, but process only the last one, cause your second loop is will not be executed after your first loop is finished. Solution Improve your indentation and put the secaonde loop in the first import csv import requests from bs4 import BeautifulSoup urls = ['https://www.canada411.ca/search/si/1/kumar/Canada/?pgLen=100','https://www.canada411.ca/search/si/2/kumar/Canada/?pgLen=100'] for url in urls: response = requests.get(url) html = requests.get(url).text soup = BeautifulSoup(response.content, "html.parser") products = soup.findAll('span','h2', class_=['c411Phone', 'c411ListedName']) for div in products: print(url,div.text) Additional solution Select and process the enclosing <div> import csv import requests from bs4 import BeautifulSoup urls = ['https://www.canada411.ca/search/si/1/kumar/Canada/?pgLen=100','https://www.canada411.ca/search/si/2/kumar/Canada/?pgLen=100'] data=[] for url in urls: response = requests.get(url) html = requests.get(url).text soup = BeautifulSoup(response.content, "html.parser") for row in soup.select('div.c411Listing.jsResultsList > div.listing__row:nth-of-type(1)'): data.append({ 'name':row.h2.a.text, 'number':row.span.text }) data
You should do two things: Put the products out of your for as an array to be able to store all urls' content Use findall separately for each h2 and span Here is the code: import requests from bs4 import BeautifulSoup urls = ['https://www.canada411.ca/search/si/1/kumar/Canada/?pgLen=100', 'https://www.canada411.ca/search/si/2/kumar/Canada/?pgLen=100'] products_h = [] products_span = [] for url in urls: response = requests.get(url) soup = BeautifulSoup(response.content, "html.parser") products_h.append(soup.findAll('span', class_=['c411Phone'])) products_span.append(soup.findAll('h2', class_=['c411ListedName'])) for i in range(len(urls)): for span, h in zip(products_span[i], products_h[i]): print(f'{span.text},{h.text}') Here is the result that I got: B Kumar,(416) 444-5781 V Roy Kumar,(613) 226-2668 C Kumar,(514) 388-4472 Ananth Kumar,(905) 389-2429 ASHOK KUMAR,(905) 575-7795 R Kumar,(905) 820-2447 A Kumar,(613) 736-1882 S R Kumar,(705) 426-9866 R Kumar,(519) 886-9588 S & H Kumar,(905) 303-6949 V KUMAR,(613) 834-1453 Ashwani Kumar,(867) 633-5854 S Kumar,(514) 620-1780 V Kumar,(514) 421-8659 B C M Kumar,(905) 335-4480 Vasant Kumar,(613) 723-3485 MICHAEL KUMAR,(519) 824-8555 M Kumar,(613) 747-3790 G Kumar,(905) 265-2017 T Kumar,(905) 824-8625 A Kumar,(905) 508-1561 U Kumar,(905) 433-2165 J Kumar,(905) 426-5249 Priya Kumar,(905) 827-0090 C Kumar,(905) 216-4078 M Kumar,(905) 456-6423 R Kumar,(647) 827-5029 N Kumar,(647) 350-2730 Sanjai Kumar,(416) 913-3648 R Kumar,(905) 916-2177 S Kumar,(289) 232-5477 J Kumar,(416) 238-9504 P Kumar,(905) 956-1699 R Kumar,(905) 793-9551 S Kumar,(905) 848-8282 Naresh Kumar,(905) 257-6640 K Kumar-Telang,(905) 450-1745 Poonam Kumar,(905) 937-6120 R Kumar,(416) 741-1314 A Kumar,(905) 454-4490 A Kumar,(905) 799-8742 Subodh Kumar,(416) 239-4590 R Kumar,(905) 888-0007 S Kumar,(416) 421-2311 R Kumar,(905) 654-8063 N Kumar,(905) 295-4343 R Kumar,(905) 303-4532 S Kumar,(519) 653-0474 Aneal Kumar,(905) 792-1051 Unesh Kumar,(905) 451-3614 Virender Kumar,(416) 483-9116 R Kumar,(905) 796-3413 M Kumar,(519) 691-1176 S SAMPATH-kUMAR,(416) 745-7911 S Kumar,(416) 724-5511 R KUMAR,(416) 256-7991 C Kumar,(905) 509-0211 A Kumar,(905) 455-2071 Ram Kumar,(905) 829-4686 D Kumar,(905) 608-1849 R Kumar,(416) 283-9395 M Kumar,(905) 456-0497 P Kumar,(416) 284-5028 M Kumar,(705) 724-3507 Pradeep Kumar,(613) 548-4619 R Kumar,(416) 481-6271 V Kumar,(905) 451-0797 Rakesh Kumar,(416) 626-8349 J Kumar,(416) 604-4806 A Kumar,(416) 759-7526 A Kumar,(905) 460-9268 Parapurath S Kumar,(905) 794-3673 N Kumar,(905) 642-9708 Praveen Kumar,(647) 827-1562 V Kumar,(905) 488-7531 A Kumar,(905) 901-0050 R Kumar,(905) 216-7945 Praveen Kumar,(416) 238-1247 J Kumar,(905) 265-7537 Praveen Kumar,(416) 855-3744 S Kumar,(905) 792-7671 Ragesh Kumar,(647) 727-5826 Goutham Kumar,(905) 670-9268 V Kumar,(519) 472-2394 Dharmana Kumar,(905) 908-2216 K Kumar,(905) 654-7177 J Kumar,(905) 554-2210 Praveen Kumar,(416) 855-3091 D Kumar,(416) 901-7977 Parmod Kumar,(905) 456-2286 S Kumar,(416) 674-5392 Suby Kumar,(905) 831-8886 A Kumar,(416) 282-0182 A Kumar,(905) 915-7124 Surinder Kumar,(905) 264-7743 Rajesh Kumar,(416) 855-1081 Selva Kumar,(905) 769-4456 Santhosh Kumar,(905) 769-4503 Praveen Kumar,(416) 855-1880 K Kumar,(416) 467-6727 J Kumar,(905) 453-9596 C Kumar,(905) 683-5983 k kumar,(416) 746-2705 A Kumar,(416) 667-9363 Praveen Kumar,(416) 855-0367 J Kumar,(905) 666-4988 Ashok N Kumar,(905) 877-2302 V Chandra Kumar,(416) 724-0156 D Kumar,(416) 332-8825 S Kumar,(905) 476-1995 Maria Kumar,(905) 499-4918 S KUMAR,(905) 814-0518 P Kumar,(905) 522-1386 SURESH KUMAR,(514) 693-0564 S Kumar,(514) 932-1504 Santosh Kumar,(416) 855-3747 p kumar,(905) 604-0670 V R Kumar,(416) 766-3335 Satish Kumar,(416) 406-2340 J Kumar,(905) 854-2337 Sam Kumar,(905) 854-2342 R Kumar,(416) 593-4306 M Kumar,(905) 338-7543 Nita Kumar,(905) 653-0474 Rajender Kumar,(705) 522-2213 R Kumar,(416) 438-3855 V KUMAR,(705) 522-6114 Raman Kumar,(905) 886-0558 B Kumar,(416) 445-4501 S Kumar,(416) 246-9104 S Kumar,(905) 792-7124 S Kumar,(905) 495-3315 D Kumar,(416) 742-8025 R Kumar,(905) 824-8170 Pj Kumar,(905) 785-3110 Rai Bal Kumar,(418) 522-8497 S Kumar,(514) 620-0626 S Kumar,(705) 352-0418 V KUMAR,(647) 345-3130 R Kumar,(416) 208-7965 R Kumar,(226) 663-3309 R Kumar,(905) 553-6099 K Kumar,(905) 566-5855 P Kumar Rudra,(905) 565-6553 Rashmi Kumar,(905) 363-7578 Anil Kumar,(905) 497-6514 Shiv Kumar,(416) 265-5763 Aprul Kumar,(416) 240-9379 A Kumar,(289) 752-7462 P Kumar,(416) 744-3493 T Melburn-Kumar,(905) 524-5529 V Kumar,(416) 724-7624 Poonam Kumar,(905) 430-1763 C Kumar,(905) 470-1296 V Kumar,(905) 237-8979 M KUMAR,(905) 458-1234 R Kumar,(416) 335-0731 A Kumar,(416) 213-9003 M Kumar,(905) 564-5779 S Kumar,(905) 890-3061 P & R Kumar,(905) 726-4444 L Kumar,(416) 438-3283 R Kumar,(613) 841-4638 R KUMAR,(416) 490-9860 K Kumar,(226) 647-1075 J Kumar,(905) 654-1532 S Kumar,(905) 472-4343 D Kumar,(905) 956-7503 Jagjit Kumar,(905) 915-8826 Vimala Krishna Kumar,(416) 551-3021 R Kumar,(647) 340-0236 A Kumar,(905) 791-8114 Santosh Kumar,(416) 431-2661 Vijay Kumar,(905) 487-9475 Dr Vinod Dr Uma Kumar,(613) 737-4113 S Kumar,(905) 281-8837 L KUMAR,(905) 860-2970 Mifan Kumar,(905) 201-0539 S Kumar,(416) 746-5671 Padin Kumar,(905) 881-3870 Shiue Kumar,(905) 499-0950 M Kumar,(905) 216-8303 P Kumar,(289) 752-6480 A Kumar,(613) 837-3511 R Kumar,(905) 846-7810 R Kumar,(416) 286-5743 E Kumar,(613) 440-2647 S Kumar,(905) 840-1426 V Kumar,(819) 681-6376 M Kumar,(416) 287-1812 D Kumar,(705) 352-2627 S Kumar,(905) 455-2242 Raj Kumar,(438) 288-3934 A Kumar,(289) 752-2619 S Kumar,(416) 284-0542 S Kumar,(705) 352-5001 V Kumar,(905) 820-6636 P KUMAR,(514) 342-4183 A Kumar,(519) 256-2012 P Kumar,(416) 412-7972 Hope it was helpful.
/snap/bin cutoff my /etc/environment path variable settings
I am using UBUNTU 16.04 and currently keeping my path variable settings in /etc/environment settings, it was all fine until my path setting reaches a specific length, /snap/bin would just cutoff in my $PATH variable, causing the necessary to source the /etc/environment everytime when I log in again... This is my /etc/environment path echo "$PATH" | tr ':' '\n' /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /opt/vcftools_0.1.13/bin /opt/PLINK_v1.90b6.5 /opt/FastQC /opt/GATK-4.0.6 /opt/samtools-1.9/bin /opt/samtools-1.9/htslib-1.9 /opt/bcftools-1.9/bin /opt/bedtools2/bin /opt/cmake-3.12.3/bin /opt/bamtools-final/usr/local/bin /opt/hmmer-3.2.1-final/bin /opt/Augustus/bin /opt/Augustus/scripts /opt/R-3.5.1-final/bin /opt/busco/scripts /opt/Platanus_v1.2.4 /opt/jemalloc-final/bin /opt/discovardenovo-52488-final/bin /opt/quast-5.0.1 /opt/gffread-0.9.12 /opt/hisat2-2.1.0 /opt/GapCloser-v1.12-r6/bin /opt/SOAPdenovo2-bin-LINUX-generic-r240 /opt/trf-4.09 /opt/rmblast-2.6.0/bin /opt/RECON-1.08/bin /opt/RepeatScout-1.0.5 /opt/RepeatMasker /opt/RepeatModeler-open-1.0.11 /opt/satsuma-code-0 /opt/minimap2 /opt/twoBitToFa-20181128 /opt/gt-1.5.10-Linux_x86_64-64bit-complete/bin /opt/supernova-2.1.1 /opt/gm_et_linux_64/gmes_petap /opt/gth-1.7.1-Linux_x86_64-64bit/bin /opt/exonerate-2.4.0/bin /opt/BRAKER/scripts /opt/bcl2fastq-final/bin /opt/longranger-2.2.2/longranger-cs/2.2.2/bin /opt/TransDecoder-TransDecoder-v5.5.0 /opt/blast-2.2.26/bin /opt/kraken2 /opt/inparanoid_4.1 /home/cch/.local/bin Like, up until bcl2fastq's pathway /snap/bin would attach correctly after the whole path variable stream (I tried to delete the string to make it shorter), but expansion upon that /snap/bin would just cut off the string in the middle: cch#ubuntu16:~$ echo "$PATH" | tr ':' '\n' /home/cch/bin /home/cch/.local/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /opt/vcftools_0.1.13/bin /opt/PLINK_v1.90b6.5 /opt/FastQC /opt/GATK-4.0.6 /opt/samtools-1.9/bin /opt/samtools-1.9/htslib-1.9 /opt/bcftools-1.9/bin /opt/bedtools2/bin /opt/cmake-3.12.3/bin /opt/bamtools-final/usr/local/bin /opt/hmmer-3.2.1-final/bin /opt/Augustus/bin /opt/Augustus/scripts /opt/R-3.5.1-final/bin /opt/busco/scripts /opt/Platanus_v1.2.4 /opt/jemalloc-final/bin /opt/discovardenovo-52488-final/bin /opt/quast-5.0.1 /opt/gffread-0.9.12 /opt/hisat2-2.1.0 /opt/GapCloser-v1.12-r6/bin /opt/SOAPdenovo2-bin-LINUX-generic-r240 /opt/trf-4.09 /opt/rmblast-2.6.0/bin /opt/RECON-1.08/bin /opt/RepeatScout-1.0.5 /opt/RepeatMasker /opt/RepeatModeler-open-1.0.11 /opt/satsuma-code-0 /opt/minimap2 /opt/twoBitToFa-20181128 /opt/gt-1.5.10-Linux_x86_64-64bit-complete/bin /opt/supernova-2.1.1 /opt/gm_et_linux_64/gmes_petap /opt/gth-1.7.1-Linux_x86_64-64bit/bin /opt/exonerate-2.4.0/bin /opt/BRAKER/scripts /opt/bcl2fastq-final/b /snap/bin This is my /etc/profile.d/apps-bin-path.sh which apparently has the code bits that append the /snap/bin to your path, but I'm not sure whether if I should alter it because it seems to be important # shellcheck shell=sh # Expand $PATH to include the directory where snappy applications go. snap_bin_path="/snap/bin" if [ -n "${PATH##*${snap_bin_path}}" -a -n "${PATH##*${snap_bin_path}:*}" ]; then export PATH=$PATH:${snap_bin_path} fi # Ensure base distro defaults xdg path are set if nothing filed up some # defaults yet. if [ -z "$XDG_DATA_DIRS" ]; then export XDG_DATA_DIRS="/usr/local/share:/usr/share" fi # Desktop files (used by desktop environments within both X11 and Wayland) are # looked for in XDG_DATA_DIRS; make sure it includes the relevant directory for # snappy applications' desktop files. snap_xdg_path="/var/lib/snapd/desktop" if [ -n "${XDG_DATA_DIRS##*${snap_xdg_path}}" -a -n "${XDG_DATA_DIRS##*${snap_xdg_path}:*}" ]; then export XDG_DATA_DIRS="${XDG_DATA_DIRS}:${snap_xdg_path}" fi This is my default setting from /etc/login.defs, but I think my /etc/environment also applies everytime I log in # *REQUIRED* The default PATH settings, for superuser and normal users. # # (they are minimal, add the rest in the shell startup files) ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games Do anyone has any idea on this??? Thanks in advance for your help I did echo -n "$PATH"|od -xc following the suggestiong from cdarke and tripleee this is the output when I re-login and the $PATH is interrupted by /snap/bin 0000000 682f 6d6f 2f65 6363 2f68 6962 3a6e 682f / h o m e / c c h / b i n : / h 0000020 6d6f 2f65 6363 2f68 6c2e 636f 6c61 622f o m e / c c h / . l o c a l / b 0000040 6e69 2f3a 7375 2f72 6f6c 6163 2f6c 6273 i n : / u s r / l o c a l / s b 0000060 6e69 2f3a 7375 2f72 6f6c 6163 2f6c 6962 i n : / u s r / l o c a l / b i 0000100 3a6e 752f 7273 732f 6962 3a6e 752f 7273 n : / u s r / s b i n : / u s r 0000120 622f 6e69 2f3a 6273 6e69 2f3a 6962 3a6e / b i n : / s b i n : / b i n : 0000140 752f 7273 672f 6d61 7365 2f3a 7375 2f72 / u s r / g a m e s : / u s r / 0000160 6f6c 6163 2f6c 6167 656d 3a73 6f2f 7470 l o c a l / g a m e s : / o p t 0000200 762f 6663 6f74 6c6f 5f73 2e30 2e31 3331 / v c f t o o l s _ 0 . 1 . 1 3 0000220 622f 6e69 2f3a 706f 2f74 4c50 4e49 5f4b / b i n : / o p t / P L I N K _ 0000240 3176 392e 6230 2e36 3a35 6f2f 7470 462f v 1 . 9 0 b 6 . 5 : / o p t / F 0000260 7361 5174 3a43 6f2f 7470 472f 5441 2d4b a s t Q C : / o p t / G A T K - 0000300 2e34 2e30 3a36 6f2f 7470 732f 6d61 6f74 4 . 0 . 6 : / o p t / s a m t o 0000320 6c6f 2d73 2e31 2f39 6962 3a6e 6f2f 7470 o l s - 1 . 9 / b i n : / o p t 0000340 732f 6d61 6f74 6c6f 2d73 2e31 2f39 7468 / s a m t o o l s - 1 . 9 / h t 0000360 6c73 6269 312d 392e 2f3a 706f 2f74 6362 s l i b - 1 . 9 : / o p t / b c 0000400 7466 6f6f 736c 312d 392e 622f 6e69 2f3a f t o o l s - 1 . 9 / b i n : / 0000420 706f 2f74 6562 7464 6f6f 736c 2f32 6962 o p t / b e d t o o l s 2 / b i 0000440 3a6e 6f2f 7470 632f 616d 656b 332d 312e n : / o p t / c m a k e - 3 . 1 0000460 2e32 2f33 6962 3a6e 6f2f 7470 622f 6d61 2 . 3 / b i n : / o p t / b a m 0000500 6f74 6c6f 2d73 6966 616e 2f6c 7375 2f72 t o o l s - f i n a l / u s r / 0000520 6f6c 6163 2f6c 6962 3a6e 6f2f 7470 682f l o c a l / b i n : / o p t / h 0000540 6d6d 7265 332d 322e 312e 662d 6e69 6c61 m m e r - 3 . 2 . 1 - f i n a l 0000560 622f 6e69 2f3a 706f 2f74 7541 7567 7473 / b i n : / o p t / A u g u s t 0000600 7375 622f 6e69 2f3a 706f 2f74 7541 7567 u s / b i n : / o p t / A u g u 0000620 7473 7375 732f 7263 7069 7374 2f3a 706f s t u s / s c r i p t s : / o p 0000640 2f74 2d52 2e33 2e35 2d31 6966 616e 2f6c t / R - 3 . 5 . 1 - f i n a l / 0000660 6962 3a6e 6f2f 7470 622f 7375 6f63 732f b i n : / o p t / b u s c o / s 0000700 7263 7069 7374 2f3a 706f 2f74 6c50 7461 c r i p t s : / o p t / P l a t 0000720 6e61 7375 765f 2e31 2e32 3a34 6f2f 7470 a n u s _ v 1 . 2 . 4 : / o p t 0000740 6a2f 6d65 6c61 6f6c 2d63 6966 616e 2f6c / j e m a l l o c - f i n a l / 0000760 6962 3a6e 6f2f 7470 642f 7369 6f63 6176 b i n : / o p t / d i s c o v a 0001000 6472 6e65 766f 2d6f 3235 3834 2d38 6966 r d e n o v o - 5 2 4 8 8 - f i 0001020 616e 2f6c 6962 3a6e 6f2f 7470 712f 6175 n a l / b i n : / o p t / q u a 0001040 7473 352d 302e 312e 2f3a 706f 2f74 6667 s t - 5 . 0 . 1 : / o p t / g f 0001060 7266 6165 2d64 2e30 2e39 3231 2f3a 706f f r e a d - 0 . 9 . 1 2 : / o p 0001100 2f74 6968 6173 3274 322d 312e 302e 2f3a t / h i s a t 2 - 2 . 1 . 0 : / 0001120 706f 2f74 6147 4370 6f6c 6573 2d72 3176 o p t / G a p C l o s e r - v 1 0001140 312e 2d32 3672 622f 6e69 3a2f 6f2f 7470 . 1 2 - r 6 / b i n / : / o p t 0001160 532f 414f 6450 6e65 766f 326f 622d 6e69 / S O A P d e n o v o 2 - b i n 0001200 4c2d 4e49 5855 672d 6e65 7265 6369 722d - L I N U X - g e n e r i c - r 0001220 3432 3a30 6f2f 7470 742f 6672 342d 302e 2 4 0 : / o p t / t r f - 4 . 0 0001240 3a39 6f2f 7470 722f 626d 616c 7473 322d 9 : / o p t / r m b l a s t - 2 0001260 362e 302e 622f 6e69 2f3a 706f 2f74 4552 . 6 . 0 / b i n : / o p t / R E 0001300 4f43 2d4e 2e31 3830 622f 6e69 2f3a 706f C O N - 1 . 0 8 / b i n : / o p 0001320 2f74 6552 6570 7461 6353 756f 2d74 2e31 t / R e p e a t S c o u t - 1 . 0001340 2e30 3a35 6f2f 7470 522f 7065 6165 4d74 0 . 5 : / o p t / R e p e a t M 0001360 7361 656b 3a72 6f2f 7470 522f 7065 6165 a s k e r : / o p t / R e p e a 0001400 4d74 646f 6c65 7265 6f2d 6570 2d6e 2e31 t M o d e l e r - o p e n - 1 . 0001420 2e30 3131 2f3a 706f 2f74 6173 7374 6d75 0 . 1 1 : / o p t / s a t s u m 0001440 2d61 6f63 6564 302d 2f3a 706f 2f74 696d a - c o d e - 0 : / o p t / m i 0001460 696e 616d 3270 2f3a 706f 2f74 7774 426f n i m a p 2 : / o p t / t w o B 0001500 7469 6f54 6146 322d 3130 3138 3231 3a38 i t T o F a - 2 0 1 8 1 1 2 8 : 0001520 6f2f 7470 672f 2d74 2e31 2e35 3031 4c2d / o p t / g t - 1 . 5 . 1 0 - L 0001540 6e69 7875 785f 3638 365f 2d34 3436 6962 i n u x _ x 8 6 _ 6 4 - 6 4 b i 0001560 2d74 6f63 706d 656c 6574 622f 6e69 2f3a t - c o m p l e t e / b i n : / 0001600 706f 2f74 7573 6570 6e72 766f 2d61 2e32 o p t / s u p e r n o v a - 2 . 0001620 2e31 3a31 6f2f 7470 672f 5f6d 7465 6c5f 1 . 1 : / o p t / g m _ e t _ l 0001640 6e69 7875 365f 2f34 6d67 7365 705f 7465 i n u x _ 6 4 / g m e s _ p e t 0001660 7061 2f3a 706f 2f74 7467 2d68 2e31 2e37 a p : / o p t / g t h - 1 . 7 . 0001700 2d31 694c 756e 5f78 3878 5f36 3436 362d 1 - L i n u x _ x 8 6 _ 6 4 - 6 0001720 6234 7469 622f 6e69 2f3a 706f 2f74 7865 4 b i t / b i n : / o p t / e x 0001740 6e6f 7265 7461 2d65 2e32 2e34 2f30 6962 o n e r a t e - 2 . 4 . 0 / b i 0001760 3a6e 6f2f 7470 422f 4152 454b 2f52 6373 n : / o p t / B R A K E R / s c 0002000 6972 7470 3a73 6f2f 7470 622f 6c63 6632 r i p t s : / o p t / b c l 2 f 0002020 7361 7174 662d 6e69 6c61 622f 2f3a 6e73 a s t q - f i n a l / b : / s n 0002040 7061 622f 6e69 a p / b i n 0002046 and I think it's the same for the original /etc/environment file
Parsing output of wmic in Inno Setup
I have recently used Inno Setup for my Java software. I am writing a function to check whether a printer driver exists by calling wmic printer get name /All and reading it output. But the problem is when I am reading the text file and check if it contains a specific substring by Pos(), it always returning 0, but when I tried to test with a character it returned the true value. I'm currently using version 5.6.1 Unicode. I have looked at Delphi Pos always returning 0 but I think it's not my case: Here is how I did it: function isContainedInFile(File, Substring: String): Boolean; var Lines: TArrayOfString; i: Integer; line: String; begin Substring := Uppercase(Substring); Result := False; if LoadStringsFromFile(File, Lines) then begin for i:= 0 to GetArrayLength(Lines) - 1 do begin line := Lines[i]; if (Length(line) = 0) then continue; line := Uppercase(Trim(line)); Log('Substring:' + Substring + ', Line:' + line + ', Pos:' + IntToStr(Pos(Substring, line))); if (Pos(Substring, line) <> 0) then begin Result:= True; break; end; end; end; end; This is how I called the isContainedInFile(): function IsBrotherDriverInstalled(): Boolean; var path, brotherPath, ListPrinterPath, ListPrinter: String; check, index: Integer; begin ListPrinterPath := ExpandConstant('{tmp}\printerlist.tdm'); { Save temporarily the list } Exec(ExpandConstant('{cmd}'), '/c wmic printer get name /All > "' + ListPrinterPath + '"', '', SW_HIDE, ewWaitUntilTerminated, check); { Check if the list has the printer } Result := isContainedInFile(ListPrinterPath, PrinterName); { Delete the file } DeleteFile(ListPrinterPath); end; Here is my output when the substring has length > 1: And when the substring has length = 1: Thanks in advance.
wmic uses UTF-16 encoding in its output. LoadStringsFromFile does not support UTF-16 encoding. See Inno Setup Pascal Script - Reading UTF-16 file. So the file is read incorrectly. You seem to be using Inno Script Studio IDE. Its Messages console does not print messages accurately, so it obfuscates the real problem. Had you used original Inno Setup Compiler IDE or checked a physical log file, you would see the problem straight away: 2018-08-26 10:44:35.783 Substring:BROTHER, Line:ÿþN A M E, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:S E N D T O O N E N O T E 2 0 1 6, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:S A M S U N G S C X - 3 4 0 0 S E R I E S ( U S B 0 0 1 ), Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:M S P U B L I S H E R C O L O R P R I N T E R, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:M I C R O S O F T X P S D O C U M E N T W R I T E R, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:M I C R O S O F T P R I N T T O P D F, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:H P E P R I N T + J E T A D V A N T A G E, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:F A X, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 2018-08-26 10:44:35.783 Substring:BROTHER, Line:, Pos:0 Solutions: Read UTF-16 file correctly. See Inno Setup Pascal Script - Reading UTF-16 file. Or make the file be in ASCII encoding. See Combine Batch/WMIC + ANSI/UNICODE Output formatting. Though the best solution is to use WMI classes, instead of the command-line tool. See Is there a way to read the system's information in Inno Setup.
Removing rows of excel file using MATLAB
I am going to remove row of excel file using Matlab Specifically I already removed some values which satisfy conditions. (In this case, I removed elements which is out of 2 sigma(statistical distribution)) But I meet undesired results, cause they only remove values and remain the location empty. So I am looking for methods for removing rows or move the elements to make no spaces. %**Open the file** fullFileName = [pwd '\Eurostoxx50_7월.xlsm']; excel = actxserver('Excel.Application'); file = excel.Workbooks.Open(fullFileName); sheet1=excel.Worksheets.get('Item', 'Inputsheet'); size_of_pd = size(PriceDifference2); size_of_pd = size_of_pd(1); %**Get the index where I want to remove** m = mean(PriceDifference2); s = std(PriceDifference2); v1=m+2*s v2=m-2*s TF1 = PriceDifference2(:) >= v1 ; TF2 = PriceDifference2(:) <= v2 ; % combine them TFall = TF1 | TF2; %remove the elements for i = 1:1:size_of_pd if TFall(i) > 0 first_cell = strcat('B',num2str(i+34)); last_cell = strcat('Q',num2str(i+34)); range1=get(sheet1,'Range', first_cell,last_cell); range1.Value=[]; end end file.Save; file.Close; delete(excel); More specifically, the results looks like below In a excel file 0.002678839 0 0.479452055 3204.381729 2850 41.1 P -1.472671354 0.002678839 0 0.479452055 3204.381729 2900 48.9 P -1.508805266 0.002678839 0 0.479452055 3204.381729 2925 53.3 P -1.341898247 0.002678839 0 0.479452055 3204.381729 3350 210.8 P 12.3246967 0.002678839 0 0.479452055 3204.381729 3375 226.5 P 11.98361578 0.002678839 0 0.479452055 3204.381729 3400 243.1 P 11.31755056 0.002678839 0 0.479452055 3204.381729 3425 260.4 P 10.86345463 0.002678839 0 0.479452055 3204.381729 3350 210.8 P 12.3246967 0.002678839 0 0.479452055 3204.381729 3375 226.5 P 11.98361578 0.002678839 0 0.479452055 3204.381729 3400 243.1 P 11.31755056 0.002678839 0 0.479452055 3204.381729 3425 260.4 P 10.86345463 But I want to remove all the spaces like below 0.002678839 0 0.479452055 3204.381729 2850 41.1 P -1.472671354 0.002678839 0 0.479452055 3204.381729 2900 48.9 P -1.508805266 0.002678839 0 0.479452055 3204.381729 2925 53.3 P -1.341898247 0.002678839 0 0.479452055 3204.381729 3350 210.8 P 12.3246967 0.002678839 0 0.479452055 3204.381729 3375 226.5 P 11.98361578 0.002678839 0 0.479452055 3204.381729 3400 243.1 P 11.31755056 0.002678839 0 0.479452055 3204.381729 3425 260.4 P 10.86345463 0.002678839 0 0.479452055 3204.381729 3350 210.8 P 12.3246967 0.002678839 0 0.479452055 3204.381729 3375 226.5 P 11.98361578 0.002678839 0 0.479452055 3204.381729 3400 243.1 P 11.31755056 0.002678839 0 0.479452055 3204.381729 3425 260.4 P 10.86345463
I solved it in stupid way. Just copy and paste many times fullFileName = [pwd '\Eurostoxx50_7월.xlsm']; if isempty(fullFileName) % User clicked Cancel. return; end excel = actxserver('Excel.Application'); sheet1=excel.Worksheets.get('Item', 'Inputsheet'); start_point = 34; size_of_pd = size(PriceDifference2); size_of_pd = size_of_pd(1); %last_cell = strcat('Q',num2str(size_of_pd )); first_cell = strcat('Q',num2str(start_point+1)); last_cell = strcat('Q',num2str(size_of_pd)); range1=get(sheet1,'Range', first_cell,last_cell); PD_EXCEL = range1.value; m = mean(PD_EXCEL); s = std(PD_EXCEL); v1 = m+2*s; v2 = m-2*s; TF1 = PD_EXCEL(:) >= v1 ; TF2 = PD_EXCEL(:) <= v2 ; % combine them TFall = TF1 | TF2; for i = 1:1:size_of_pd if TFall(i) > 0 first_cell = strcat('B',num2str(i+start_point)); last_cell = strcat('Q',num2str(i+start_point)); range1= get(sheet1,'Range', first_cell,last_cell); range1.Value = []; end end for i = size_of_pd:-1:1 if TFall(i)>0 copy_first_cell = strcat('B',num2str(i+start_point+1)); copy_last_cell = strcat('Q',num2str(size_of_pd+start_point)); first_cell = strcat('B',num2str(i+start_point)); last_cell = strcat('Q',num2str(size_of_pd+start_point-1)); range1=get(sheet1,'Range', copy_first_cell,copy_last_cell); range2 = get(sheet1,'Range',first_cell,last_cell); range2.Value=range1.value; end end first_cell = strcat('B',num2str(start_point + sum(TFall(:)==0))); last_cell = strcat('Q',num2str(start_point+size_of_pd)); range1 = get(sheet1,'Range', first_cell,last_cell); range1.Value = []; file.Save; file.Close; delete(excel);
Why STRACE shows EAGAIN (Resource temporarily unavailable)
Following is the sequence I am getting socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 7 setsockopt(7, SOL_TCP, TCP_NODELAY, [1], 4) = 0 setsockopt(7, SOL_SOCKET, SO_SNDBUF, [32120], 4) = 0 getsockopt(7, SOL_SOCKET, SO_SNDBUF, [30064835312], [4]) = 0 setsockopt(7, SOL_SOCKET, SO_SNDBUF, [64240], 4) = 0 getsockopt(7, SOL_SOCKET, SO_SNDBUF, [30064899552], [4]) = 0 stat("/etc/localtime", {st_dev=makedev(8, 1), st_ino=229001, st_mode=S_IFREG|0644, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=8, st_size=265, st_atime=2013/07/15-06:30:03, st_mtime=2012/06/25-23:46:43, st_ctime=2012/06/25-23:46:43}) = 0 write(1, "[info 2013/07/16 05:53:24.622210"..., 114) = 114 setsockopt(7, SOL_SOCKET, SO_RCVBUF, [32120], 4) = 0 getsockopt(7, SOL_SOCKET, SO_RCVBUF, [30064835312], [4]) = 0 setsockopt(7, SOL_SOCKET, SO_RCVBUF, [64240], 4) = 0 getsockopt(7, SOL_SOCKET, SO_RCVBUF, [30064899552], [4]) = 0 fcntl(7, F_GETFL) = 0x2 (flags O_RDWR) fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 rt_sigaction(SIGPIPE, {SIG_IGN, [PIPE], SA_RESTORER|SA_RESTART, 0x33b3632920}, {SIG_DFL, [], 0}, 8) = 0 fcntl(7, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK) fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 connect(7, {sa_family=AF_INET, sin_port=htons(50505), sin_addr=inet_addr("1.2.3.4")}, 16) = -1 EINPROGRESS (Operation now in progress) poll([{fd=7, events=POLLIN|POLLOUT}], 1, 59000) = 1 ([{fd=7, revents=POLLOUT}]) fcntl(7, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK) fcntl(7, F_SETFL, O_RDWR) = 0 getsockname(7, {sa_family=AF_INET, sin_port=htons(33220), sin_addr=inet_addr("10.112.204.215")}, [16]) = 0 fcntl(7, F_GETFL) = 0x2 (flags O_RDWR) fcntl(7, F_GETFL) = 0x2 (flags O_RDWR) fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 write(7, "d\23;\177\377\330\357\1&W\1\\\4\np\314\327\0\0\0\2W\0\rpnq-gst-"..., 103) = 103 fcntl(7, F_GETFL) = 0x802 (flags O_RDWR|O_NONBLOCK) fcntl(7, F_SETFL, O_RDWR) = 0 fcntl(7, F_GETFL) = 0x2 (flags O_RDWR) fcntl(7, F_GETFL) = 0x2 (flags O_RDWR) fcntl(7, F_SETFL, O_RDWR|O_NONBLOCK) = 0 read(7, 0x9d9f90, 1) = -1 EAGAIN (Resource temporarily unavailable) Why this read is getting called, I assume that poll should wake up only when there is data to read
poll woke up with revents = POLLOUT, which means that the socket is ready to write, not ready to read. The code is apparently not checking this flag, and trying to read anyway. This might be intentional. Even though poll didn't say the socket is ready to read, it might have become ready while it was writing. So it calls ready just in case something has shown up. If not, it will go back into poll to wait again. This allows it to process incoming data more quickly, since it can get it in one call rather than two.