c# - How to know a StreamGeometry is a Line -


i have collection of streamgeometrys. each streamgeometry shape. want pick streamgeometrys lines. how can know streamgeometry line.

background: collection of streamgeometrys interface. interface given other team , doesn't return information geometry is. (i may discuss them make update, involve architecture change.) have function group geometrys , outline of group. originally, add them geometrygroup, use geometry.getoutlinedpathgeometry outline of geometrygroup. behavior good.

problem:but when geometrys number increases more 200, getoutlinedpathgeometry becomes extremely slow.

current solution:then have make compromise outline not accurate. instead of getoutlinedpathgeometry, use geometry.combine combine geometrys. geometry.combine used closed geometry. when geometry not closed, find nearest points make closed. behavior somehow reduce complexity of overall outline getoutlinedpathgeometry can result quicker.

how question:but 1 problem geometry.combine omit line shapes. after combine geometrys, lines not in group. want find lines , use getoutlinedpathgeometry outlines first. use outlines combine others.

also, have geometry type information, not much. because geometry.combine omit line shapes can made of geometry type. line, path rectangle can make line shape.

other attempts:i tried use getoutlinedpathgeometry outline each geometry first, combine. performance improves little bit still slow.

just drop code in , can use streamgeometry.isline() check lines.

public static class streamgeometryextensions {     public static bool isline(this streamgeometry sg, double samplerate = 0.2, decimal tolerance = 0     {         pathgeometry g = sg.getflattenedpathgeometry();         if (g.mayhavecurves())         {             return false;         }          point origin, origintangent;         point end, endtangent;         g.getpointatfractionlength(0, out origin, out origintangent);         g.getpointatfractionlength(1, out end, out endtangent);          vector origintoend = end - origin;          (double = 0; < 1; += samplerate)         {             point current, currenttangent;             g.getpointatfractionlength(i, out current, out currenttangent);              vector currenttoend = end - current;             vector origintocurrent = current - origin;              decimal l1 = (decimal)(origintocurrent.length + currenttoend.length);             decimal l2 = (decimal)origintoend.length;              if (math.abs(l2 - l1) > (l2 * tolerance))             {                 return false;             }         }         return true;     } } 

the code "samples" path every x% (example 0.2 = 20%) , checks if origin, end , current sample point on line.

the code general solution problem , can definetly optimized specific scenarios performance important.

i measured performance following paths: (samplerate = 0.2, tolerance = 0)

    <path data="m 217,172 l 10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300"></path>     <path data="m 217,172 l 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20"></path>     <path data="m 217,172 l 10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300"></path>     <path data="m 217,172 l 10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300"></path>     <path data="m 217,172 l 10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300,  10 50, 50 30, 70 40, 100 300 10 50, 50 30, 70 40, 100 300"></path>     <path data="m 217,172 l 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20, 20 20"></path> 

on i7 4790 got these times:

80µs - false 390µs - true 86µs - false 82µs - false 69µs - false 355µs - true 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -