- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我遇到了一个奇怪的性能问题,如果能对我所遇到的行为做出解释,那就太好了。
我正在使用System.Drawing.Region.IsVisible(PointF)确定某个点是否在多边形内。这通常效果很好,但是昨天我注意到,如果多边形很复杂并且包含较大的x和y值,则IsVisible方法的性能会变得非常慢。
下面是一些重现问题的代码(以及显示多边形形状的图像),对于较大的数组大小,感到抱歉,但是在问题出现之前,多边形必须非常复杂。
在原始点上调用IsVisible时,我的机器需要460 651毫秒才能完成,而当我首先将所有点除以1000,然后调用该方法时,则需要1毫秒。为什么我看到时间有如此大的差异?我认为 float 的实际值不会影响性能。
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
namespace PerformanceTest
{
class Program
{
static void Main(string[] args)
{
// Create complex polygon with large x and y values
float[] xValues = {1.014498E+07f, 1.016254E+07f, 1.019764E+07f, 1.021519E+07f, 1.023274E+07f, 1.026785E+07f, 1.026785E+07f, 1.02854E+07f, 1.02854E+07f, 1.030295E+07f, 1.03205E+07f, 1.033805E+07f, 1.035561E+07f, 1.037316E+07f, 1.039071E+07f, 1.040826E+07f, 1.042581E+07f, 1.044337E+07f, 1.046092E+07f, 1.047847E+07f, 1.049602E+07f, 1.051357E+07f, 1.054868E+07f, 1.056623E+07f, 1.058378E+07f, 1.060133E+07f, 1.061888E+07f, 1.061888E+07f, 1.063644E+07f, 1.065399E+07f, 1.068909E+07f, 1.068909E+07f, 1.070664E+07f, 1.07242E+07f, 1.074175E+07f, 1.074175E+07f, 1.07593E+07f, 1.07593E+07f, 1.077685E+07f, 1.07944E+07f, 1.07944E+07f, 1.081196E+07f, 1.081196E+07f, 1.081196E+07f, 1.082951E+07f, 1.084706E+07f, 1.084706E+07f, 1.086461E+07f, 1.086461E+07f, 1.088216E+07f, 1.089971E+07f, 1.091727E+07f, 1.093482E+07f, 1.098747E+07f, 1.100503E+07f, 1.102258E+07f, 1.104013E+07f, 1.105768E+07f, 1.107523E+07f, 1.107523E+07f, 1.109279E+07f, 1.109279E+07f, 1.109279E+07f, 1.109279E+07f, 1.109279E+07f, 1.111034E+07f, 1.111034E+07f, 1.111034E+07f, 1.111034E+07f, 1.111034E+07f, 1.112789E+07f, 1.112789E+07f, 1.112789E+07f, 1.114544E+07f, 1.116299E+07f, 1.118054E+07f, 1.11981E+07f, 1.12332E+07f, 1.125075E+07f, 1.12683E+07f, 1.128586E+07f, 1.130341E+07f, 1.135606E+07f, 1.137361E+07f, 1.139117E+07f, 1.140872E+07f, 1.144382E+07f, 1.146137E+07f, 1.147893E+07f, 1.149648E+07f, 1.151403E+07f, 1.153158E+07f, 1.154913E+07f, 1.156669E+07f, 1.156669E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.158424E+07f, 1.156669E+07f, 1.156669E+07f, 1.151403E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.149648E+07f, 1.153158E+07f, 1.154913E+07f, 1.156669E+07f, 1.156669E+07f, 1.158424E+07f, 1.160179E+07f, 1.160179E+07f, 1.161934E+07f, 1.165444E+07f, 1.1672E+07f, 1.168955E+07f, 1.17071E+07f, 1.172465E+07f, 1.17422E+07f, 1.175976E+07f, 1.177731E+07f, 1.179486E+07f, 1.181241E+07f, 1.182996E+07f, 1.184752E+07f, 1.186507E+07f, 1.188262E+07f, 1.190017E+07f, 1.190017E+07f, 1.191772E+07f, 1.191772E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.193528E+07f, 1.195283E+07f, 1.197038E+07f, 1.198793E+07f, 1.200548E+07f, 1.202303E+07f, 1.204059E+07f, 1.205814E+07f, 1.207569E+07f, 1.209324E+07f, 1.211079E+07f, 1.212835E+07f, 1.21459E+07f, 1.216345E+07f, 1.2181E+07f, 1.219855E+07f, 1.221611E+07f, 1.221611E+07f, 1.223366E+07f, 1.225121E+07f, 1.226876E+07f, 1.226876E+07f, 1.228631E+07f, 1.230386E+07f, 1.230386E+07f, 1.230386E+07f, 1.232142E+07f, 1.232142E+07f, 1.232142E+07f, 1.232142E+07f, 1.232142E+07f, 1.232142E+07f, 1.232142E+07f, 1.232142E+07f, 1.235652E+07f, 1.235652E+07f, 1.237407E+07f, 1.237407E+07f, 1.239162E+07f, 1.239162E+07f, 1.240918E+07f, 1.242673E+07f, 1.242673E+07f, 1.244428E+07f, 1.247938E+07f, 1.249694E+07f, 1.251449E+07f, 1.253204E+07f, 1.254959E+07f, 1.256714E+07f, 1.258469E+07f, 1.260225E+07f, 1.263735E+07f, 1.26549E+07f, 1.267245E+07f, 1.269001E+07f, 1.270756E+07f, 1.272511E+07f, 1.272511E+07f, 1.274266E+07f, 1.274266E+07f, 1.276021E+07f, 1.276021E+07f, 1.277776E+07f, 1.277776E+07f, 1.277776E+07f, 1.277776E+07f, 1.279532E+07f, 1.279532E+07f, 1.279532E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.281287E+07f, 1.279532E+07f, 1.277776E+07f, 1.276021E+07f, 1.276021E+07f, 1.274266E+07f, 1.274266E+07f, 1.272511E+07f, 1.272511E+07f, 1.272511E+07f, 1.274266E+07f, 1.276021E+07f, 1.279532E+07f, 1.281287E+07f, 1.283042E+07f, 1.284797E+07f, 1.286552E+07f, 1.288308E+07f, 1.290063E+07f, 1.291818E+07f, 1.293573E+07f, 1.295328E+07f, 1.295328E+07f, 1.297084E+07f, 1.297084E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.298839E+07f, 1.300594E+07f, 1.300594E+07f, 1.302349E+07f, 1.304104E+07f, 1.305859E+07f, 1.30937E+07f, 1.311125E+07f, 1.31288E+07f, 1.314635E+07f, 1.316391E+07f, 1.318146E+07f, 1.319901E+07f, 1.321656E+07f, 1.323411E+07f, 1.325167E+07f, 1.325167E+07f, 1.326922E+07f, 1.326922E+07f, 1.328677E+07f, 1.330432E+07f, 1.330432E+07f, 1.330432E+07f, 1.332187E+07f, 1.333943E+07f, 1.335698E+07f, 1.335698E+07f, 1.337453E+07f, 1.339208E+07f, 1.340963E+07f, 1.340963E+07f, 1.342718E+07f, 1.344474E+07f, 1.346229E+07f, 1.347984E+07f, 1.349739E+07f, 1.351494E+07f, 1.355005E+07f, 1.35676E+07f, 1.36027E+07f, 1.363781E+07f, 1.367291E+07f, 1.367291E+07f, 1.370801E+07f, 1.372557E+07f, 1.376067E+07f, 1.377822E+07f, 1.381333E+07f, 1.383088E+07f, 1.384843E+07f, 1.386598E+07f, 1.390109E+07f, 1.391864E+07f, 1.391864E+07f, 1.393619E+07f, 1.395374E+07f, 1.397129E+07f, 1.398884E+07f, 1.40064E+07f, 1.402395E+07f, 1.405905E+07f, 1.409416E+07f, 1.412926E+07f, 1.414681E+07f, 1.418191E+07f, 1.419947E+07f, 1.421702E+07f, 1.423457E+07f, 1.426967E+07f, 1.430478E+07f, 1.433988E+07f, 1.435743E+07f, 1.437499E+07f, 1.439254E+07f, 1.439254E+07f, 1.442764E+07f, 1.442764E+07f, 1.444519E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.446274E+07f, 1.444519E+07f, 1.442764E+07f, 1.441009E+07f, 1.439254E+07f, 1.437499E+07f, 1.435743E+07f, 1.433988E+07f, 1.432233E+07f, 1.430478E+07f, 1.430478E+07f, 1.426967E+07f, 1.426967E+07f, 1.423457E+07f, 1.421702E+07f, 1.418191E+07f, 1.414681E+07f, 1.412926E+07f, 1.409416E+07f, 1.405905E+07f, 1.402395E+07f, 1.40064E+07f, 1.395374E+07f, 1.393619E+07f, 1.391864E+07f, 1.390109E+07f, 1.390109E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.388353E+07f, 1.390109E+07f, 1.391864E+07f, 1.393619E+07f, 1.395374E+07f, 1.398884E+07f, 1.398884E+07f, 1.40064E+07f, 1.402395E+07f, 1.402395E+07f, 1.40415E+07f, 1.405905E+07f, 1.40766E+07f, 1.412926E+07f, 1.414681E+07f, 1.416436E+07f, 1.418191E+07f, 1.419947E+07f, 1.421702E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.423457E+07f, 1.421702E+07f, 1.419947E+07f, 1.418191E+07f, 1.416436E+07f, 1.416436E+07f, 1.412926E+07f, 1.411171E+07f, 1.409416E+07f, 1.40766E+07f, 1.405905E+07f, 1.40415E+07f, 1.402395E+07f, 1.40064E+07f, 1.397129E+07f, 1.397129E+07f, 1.395374E+07f, 1.393619E+07f, 1.393619E+07f, 1.391864E+07f, 1.391864E+07f, 1.390109E+07f, 1.388353E+07f, 1.388353E+07f, 1.386598E+07f, 1.384843E+07f, 1.383088E+07f, 1.379577E+07f, 1.376067E+07f, 1.372557E+07f, 1.370801E+07f, 1.369046E+07f, 1.365536E+07f, 1.363781E+07f, 1.362026E+07f, 1.36027E+07f, 1.358515E+07f, 1.35676E+07f, 1.35325E+07f, 1.351494E+07f, 1.349739E+07f, 1.347984E+07f, 1.346229E+07f, 1.344474E+07f, 1.339208E+07f, 1.337453E+07f, 1.335698E+07f, 1.333943E+07f, 1.332187E+07f, 1.332187E+07f, 1.330432E+07f, 1.326922E+07f, 1.325167E+07f, 1.323411E+07f, 1.321656E+07f, 1.319901E+07f, 1.316391E+07f, 1.314635E+07f, 1.31288E+07f, 1.311125E+07f, 1.307615E+07f, 1.304104E+07f, 1.302349E+07f, 1.300594E+07f, 1.300594E+07f, 1.300594E+07f, 1.300594E+07f, 1.300594E+07f, 1.300594E+07f, 1.300594E+07f, 1.302349E+07f, 1.304104E+07f, 1.307615E+07f, 1.30937E+07f, 1.311125E+07f, 1.314635E+07f, 1.316391E+07f, 1.318146E+07f, 1.319901E+07f, 1.321656E+07f, 1.323411E+07f, 1.323411E+07f, 1.323411E+07f, 1.323411E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.325167E+07f, 1.323411E+07f, 1.323411E+07f, 1.321656E+07f, 1.319901E+07f, 1.318146E+07f, 1.316391E+07f, 1.314635E+07f, 1.31288E+07f, 1.305859E+07f, 1.304104E+07f, 1.298839E+07f, 1.295328E+07f, 1.291818E+07f, 1.288308E+07f, 1.286552E+07f, 1.284797E+07f, 1.283042E+07f, 1.279532E+07f, 1.277776E+07f, 1.276021E+07f, 1.272511E+07f, 1.270756E+07f, 1.269001E+07f, 1.26549E+07f, 1.263735E+07f, 1.260225E+07f, 1.258469E+07f, 1.256714E+07f, 1.256714E+07f, 1.254959E+07f, 1.253204E+07f, 1.253204E+07f, 1.253204E+07f, 1.251449E+07f, 1.251449E+07f, 1.251449E+07f, 1.251449E+07f, 1.251449E+07f, 1.249694E+07f, 1.249694E+07f, 1.249694E+07f, 1.249694E+07f, 1.247938E+07f, 1.247938E+07f, 1.246183E+07f, 1.244428E+07f, 1.240918E+07f, 1.239162E+07f, 1.235652E+07f, 1.233897E+07f, 1.230386E+07f, 1.226876E+07f, 1.225121E+07f, 1.221611E+07f, 1.219855E+07f, 1.219855E+07f, 1.2181E+07f, 1.216345E+07f, 1.216345E+07f, 1.21459E+07f, 1.21459E+07f, 1.212835E+07f, 1.212835E+07f, 1.212835E+07f, 1.212835E+07f, 1.212835E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.211079E+07f, 1.209324E+07f, 1.207569E+07f, 1.207569E+07f, 1.204059E+07f, 1.202303E+07f, 1.200548E+07f, 1.198793E+07f, 1.197038E+07f, 1.195283E+07f, 1.193528E+07f, 1.191772E+07f, 1.190017E+07f, 1.188262E+07f, 1.186507E+07f, 1.181241E+07f, 1.181241E+07f, 1.179486E+07f, 1.177731E+07f, 1.177731E+07f, 1.177731E+07f, 1.175976E+07f, 1.175976E+07f, 1.17422E+07f, 1.17422E+07f, 1.17422E+07f, 1.17422E+07f, 1.17422E+07f, 1.17422E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.172465E+07f, 1.17071E+07f, 1.168955E+07f, 1.1672E+07f, 1.163689E+07f, 1.161934E+07f, 1.160179E+07f, 1.156669E+07f, 1.154913E+07f, 1.151403E+07f, 1.149648E+07f, 1.147893E+07f, 1.146137E+07f, 1.144382E+07f, 1.144382E+07f, 1.139117E+07f, 1.139117E+07f, 1.137361E+07f, 1.137361E+07f, 1.137361E+07f, 1.137361E+07f, 1.137361E+07f, 1.137361E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.135606E+07f, 1.133851E+07f, 1.133851E+07f, 1.133851E+07f, 1.133851E+07f, 1.133851E+07f, 1.130341E+07f, 1.130341E+07f, 1.128586E+07f, 1.12683E+07f, 1.125075E+07f, 1.121565E+07f, 1.116299E+07f, 1.112789E+07f, 1.107523E+07f, 1.105768E+07f, 1.102258E+07f, 1.098747E+07f, 1.095237E+07f, 1.091727E+07f, 1.089971E+07f, 1.088216E+07f, 1.086461E+07f, 1.082951E+07f, 1.081196E+07f, 1.081196E+07f, 1.07944E+07f, 1.07944E+07f, 1.077685E+07f, 1.07593E+07f, 1.07593E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.074175E+07f, 1.07593E+07f, 1.07593E+07f, 1.077685E+07f, 1.07944E+07f, 1.07944E+07f, 1.081196E+07f, 1.082951E+07f, 1.082951E+07f, 1.086461E+07f, 1.088216E+07f, 1.089971E+07f, 1.089971E+07f, 1.091727E+07f, 1.091727E+07f, 1.091727E+07f, 1.091727E+07f, 1.091727E+07f, 1.091727E+07f, 1.089971E+07f, 1.088216E+07f, 1.082951E+07f, 1.07944E+07f, 1.07593E+07f, 1.070664E+07f, 1.068909E+07f, 1.067154E+07f, 1.065399E+07f, 1.063644E+07f, 1.061888E+07f, 1.060133E+07f, 1.058378E+07f, 1.056623E+07f, 1.054868E+07f, 1.051357E+07f, 1.049602E+07f, 1.047847E+07f, 1.046092E+07f, 1.042581E+07f, 1.039071E+07f, 1.030295E+07f, 1.026785E+07f, 1.023274E+07f, 1.019764E+07f, 1.018009E+07f, 1.016254E+07f, 1.014498E+07f, 1.010988E+07f, 1.009233E+07f, 1.007478E+07f, 1.005722E+07f, 1.003967E+07f, 1.002212E+07f, 9969464f, 9916809f, 9881705f, 9864154f, 9846602f, 9829050f, 9811497f, 9793945f, 9776394f, 9741290f, 9723738f, 9688635f, 9653531f, 9653531f, 9618427f, 9618427f, 9600875f, 9600875f, 9600875f, 9583323f, 9565771f, 9565771f, 9530667f, 9530667f, 9530667f, 9530667f, 9530667f, 9530667f, 9530667f, 9530667f, 9548219f, 9565771f, 9583323f, 9618427f, 9653531f, 9671083f, 9688635f, 9706186f, 9741290f, 9758842f, 9811497f, 9829050f, 9864154f, 9881705f, 9916809f, 9934361f, 9951913f, 9987016f, 1.000457E+07f, 1.003967E+07f, 1.005722E+07f, 1.007478E+07f, 1.010988E+07f, 1.014498E+07f, 1.016254E+07f, 1.016254E+07f, 1.018009E+07f, 1.019764E+07f, 1.021519E+07f, 1.023274E+07f, 1.023274E+07f, 1.023274E+07f, 1.023274E+07f, 1.023274E+07f, 1.023274E+07f, 1.023274E+07f, 1.023274E+07f, 1.021519E+07f, 1.019764E+07f, 1.016254E+07f, 1.014498E+07f, 1.012743E+07f, 1.009233E+07f, 1.003967E+07f, 1.000457E+07f, 9951913f, 9934361f, 9899257f, 9881705f, 9864154f, 9846602f, 9829050f, 9793945f, 9758842f, 9723738f, 9688635f, 9653531f, 9635979f, 9618427f, 9583323f, 9565771f, 9530667f, 9513116f, 9495564f, 9478012f, 9460460f, 9460460f, 9442908f, 9425357f, 9425357f, 9407805f, 9390253f, 9390253f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9372701f, 9390253f, 9407805f, 9425357f, 9460460f, 9495564f, 9513116f, 9583323f, 9600875f, 9635979f, 9653531f, 9688635f, 9706186f, 9723738f, 9758842f, 9793945f, 9811497f, 9846602f};
float[] yValues = { 7286825f, 7286825f, 7269351f, 7269351f, 7269351f, 7269351f, 7251876f, 7251876f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7234401f, 7216927f, 7199453f, 7181979f, 7181979f, 7164504f, 7164504f, 7147029f, 7129555f, 7112081f, 7077132f, 7042183f, 7024709f, 7007235f, 6972285f, 6954811f, 6937337f, 6919863f, 6902388f, 6884913f, 6867439f, 6867439f, 6832491f, 6815016f, 6797541f, 6780067f, 6762593f, 6762593f, 6745119f, 6745119f, 6727644f, 6727644f, 6710169f, 6710169f, 6710169f, 6710169f, 6710169f, 6710169f, 6710169f, 6727644f, 6762593f, 6780067f, 6832491f, 6849965f, 6867439f, 6902388f, 6937337f, 6954811f, 6972285f, 6989760f, 7024709f, 7042183f, 7077132f, 7094607f, 7112081f, 7129555f, 7129555f, 7129555f, 7129555f, 7129555f, 7129555f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7147029f, 7129555f, 7112081f, 7077132f, 7059657f, 7007235f, 6972285f, 6954811f, 6937337f, 6902388f, 6867439f, 6832491f, 6815016f, 6797541f, 6780067f, 6710169f, 6710169f, 6692695f, 6675221f, 6640272f, 6622797f, 6605323f, 6587849f, 6570375f, 6535425f, 6517951f, 6500477f, 6483003f, 6465528f, 6448053f, 6448053f, 6430579f, 6430579f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6413105f, 6430579f, 6448053f, 6483003f, 6500477f, 6552900f, 6570375f, 6622797f, 6640272f, 6657747f, 6675221f, 6692695f, 6710169f, 6745119f, 6762593f, 6780067f, 6797541f, 6849965f, 6867439f, 6902388f, 6954811f, 6972285f, 6989760f, 7007235f, 7042183f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7059657f, 7042183f, 7042183f, 7024709f, 7007235f, 6989760f, 6989760f, 6972285f, 6954811f, 6937337f, 6919863f, 6902388f, 6867439f, 6832491f, 6815016f, 6797541f, 6780067f, 6762593f, 6745119f, 6727644f, 6710169f, 6692695f, 6675221f, 6657747f, 6657747f, 6640272f, 6622797f, 6622797f, 6622797f, 6622797f, 6622797f, 6622797f, 6622797f, 6622797f, 6622797f, 6622797f, 6640272f, 6657747f, 6692695f, 6692695f, 6710169f, 6727644f, 6745119f, 6762593f, 6780067f, 6780067f, 6797541f, 6815016f, 6832491f, 6849965f, 6867439f, 6884913f, 6902388f, 6919863f, 6937337f, 6954811f, 6972285f, 6989760f, 7007235f, 7024709f, 7042183f, 7059657f, 7077132f, 7094607f, 7112081f, 7129555f, 7147029f, 7164504f, 7181979f, 7199453f, 7234401f, 7234401f, 7251876f, 7251876f, 7269351f, 7286825f, 7304299f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7321773f, 7304299f, 7286825f, 7269351f, 7251876f, 7234401f, 7216927f, 7199453f, 7181979f, 7164504f, 7147029f, 7129555f, 7112081f, 7094607f, 7077132f, 7042183f, 7024709f, 7007235f, 6989760f, 6954811f, 6937337f, 6919863f, 6902388f, 6849965f, 6832491f, 6815016f, 6797541f, 6780067f, 6780067f, 6762593f, 6762593f, 6762593f, 6745119f, 6745119f, 6745119f, 6745119f, 6745119f, 6745119f, 6762593f, 6762593f, 6797541f, 6832491f, 6867439f, 6884913f, 6884913f, 6919863f, 6954811f, 6954811f, 6972285f, 6989760f, 7007235f, 7042183f, 7042183f, 7059657f, 7077132f, 7094607f, 7094607f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7112081f, 7094607f, 7077132f, 7042183f, 7024709f, 7024709f, 7007235f, 6989760f, 6989760f, 6972285f, 6954811f, 6937337f, 6937337f, 6919863f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6902388f, 6919863f, 6919863f, 6954811f, 6972285f, 6972285f, 6989760f, 7024709f, 7042183f, 7059657f, 7094607f, 7112081f, 7129555f, 7164504f, 7181979f, 7199453f, 7234401f, 7251876f, 7269351f, 7286825f, 7321773f, 7321773f, 7339248f, 7339248f, 7356723f, 7374197f, 7374197f, 7374197f, 7374197f, 7374197f, 7391671f, 7391671f, 7409145f, 7409145f, 7426620f, 7426620f, 7426620f, 7444095f, 7444095f, 7461569f, 7479043f, 7496517f, 7513992f, 7513992f, 7513992f, 7531467f, 7548941f, 7548941f, 7566415f, 7601364f, 7618839f, 7636313f, 7653787f, 7671261f, 7688736f, 7706211f, 7741159f, 7793583f, 7828531f, 7846005f, 7880955f, 7880955f, 7898429f, 7898429f, 7915903f, 7933377f, 7933377f, 7950852f, 7950852f, 7950852f, 7950852f, 7950852f, 7950852f, 7950852f, 7968327f, 7985801f, 8003275f, 8020749f, 8038224f, 8055699f, 8073173f, 8090647f, 8108121f, 8125596f, 8160545f, 8178019f, 8195493f, 8212968f, 8212968f, 8230443f, 8247917f, 8265391f, 8282865f, 8282865f, 8282865f, 8282865f, 8282865f, 8282865f, 8282865f, 8282865f, 8265391f, 8230443f, 8212968f, 8195493f, 8178019f, 8160545f, 8160545f, 8143071f, 8143071f, 8125596f, 8108121f, 8108121f, 8090647f, 8090647f, 8073173f, 8038224f, 8038224f, 8020749f, 8020749f, 8003275f, 7985801f, 7985801f, 7968327f, 7950852f, 7950852f, 7933377f, 7933377f, 7933377f, 7933377f, 7915903f, 7898429f, 7898429f, 7898429f, 7898429f, 7898429f, 7898429f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7880955f, 7898429f, 7898429f, 7933377f, 7968327f, 7985801f, 8003275f, 8020749f, 8055699f, 8073173f, 8108121f, 8108121f, 8143071f, 8178019f, 8178019f, 8212968f, 8212968f, 8230443f, 8247917f, 8265391f, 8282865f, 8282865f, 8317815f, 8335289f, 8352763f, 8387712f, 8405186f, 8422661f, 8440134f, 8457609f, 8475084f, 8510033f, 8527506f, 8544981f, 8562456f, 8614878f, 8632353f, 8667302f, 8684777f, 8737200f, 8772149f, 8789622f, 8824572f, 8842046f, 8859521f, 8876994f, 8894469f, 8929418f, 8929418f, 8946893f, 8946893f, 8946893f, 8946893f, 8946893f, 8946893f, 8946893f, 8946893f, 8946893f, 8946893f, 8911944f, 8894469f, 8859521f, 8824572f, 8789622f, 8772149f, 8702250f, 8684777f, 8667302f, 8632353f, 8614878f, 8597405f, 8562456f, 8544981f, 8510033f, 8492558f, 8475084f, 8457609f, 8440134f, 8422661f, 8405186f, 8387712f, 8370237f, 8352763f, 8352763f, 8352763f, 8352763f, 8352763f, 8352763f, 8352763f, 8352763f, 8352763f, 8352763f, 8370237f, 8370237f, 8387712f, 8387712f, 8405186f, 8422661f, 8422661f, 8440134f, 8457609f, 8492558f, 8527506f, 8544981f, 8562456f, 8579930f, 8597405f, 8614878f, 8632353f, 8649828f, 8667302f, 8702250f, 8719725f, 8737200f, 8772149f, 8789622f, 8807097f, 8824572f, 8842046f, 8876994f, 8894469f, 8911944f, 8929418f, 8946893f, 8964366f, 8964366f, 8981841f, 8999316f, 9016790f, 9034265f, 9034265f, 9051738f, 9051738f, 9051738f, 9051738f, 9051738f, 9051738f, 9051738f, 9016790f, 8999316f, 8964366f, 8946893f, 8929418f, 8911944f, 8876994f, 8859521f, 8842046f, 8824572f, 8807097f, 8789622f, 8772149f, 8754674f, 8702250f, 8667302f, 8649828f, 8632353f, 8614878f, 8597405f, 8579930f, 8562456f, 8544981f, 8510033f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8492558f, 8510033f, 8544981f, 8544981f, 8562456f, 8562456f, 8597405f, 8614878f, 8632353f, 8667302f, 8702250f, 8719725f, 8754674f, 8789622f, 8824572f, 8842046f, 8859521f, 8876994f, 8911944f, 8929418f, 8964366f, 8964366f, 8999316f, 9016790f, 9034265f, 9086688f, 9104162f, 9139110f, 9156585f, 9174060f, 9209009f, 9243957f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9261432f, 9243957f, 9226482f, 9191534f, 9174060f, 9156585f, 9086688f, 9051738f, 9034265f, 8999316f, 8981841f, 8964366f, 8929418f, 8894469f, 8876994f, 8842046f, 8824572f, 8807097f, 8789622f, 8772149f, 8754674f, 8702250f, 8684777f, 8667302f, 8667302f, 8649828f, 8614878f, 8597405f, 8579930f, 8562456f, 8562456f, 8527506f, 8510033f, 8492558f, 8475084f, 8440134f, 8422661f, 8422661f, 8387712f, 8370237f, 8370237f, 8370237f, 8370237f, 8370237f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8335289f, 8352763f, 8370237f, 8405186f, 8440134f, 8457609f, 8492558f, 8510033f, 8527506f, 8562456f, 8579930f, 8597405f, 8597405f, 8632353f, 8632353f, 8667302f, 8702250f, 8719725f, 8754674f, 8754674f, 8754674f, 8754674f, 8754674f, 8754674f, 8754674f, 8754674f, 8737200f, 8719725f, 8702250f, 8684777f, 8667302f, 8649828f, 8632353f, 8614878f, 8562456f, 8527506f, 8440134f, 8422661f, 8387712f, 8352763f, 8317815f, 8300340f, 8282865f, 8265391f, 8247917f, 8212968f, 8212968f, 8160545f, 8143071f, 8125596f, 8108121f, 8108121f, 8090647f, 8090647f, 8073173f, 8073173f, 8055699f, 8055699f, 8055699f, 8038224f, 8038224f, 8038224f, 8038224f, 8038224f, 8020749f, 8020749f, 8003275f, 8003275f, 7985801f, 7950852f, 7933377f, 7915903f, 7915903f, 7880955f, 7863480f, 7846005f, 7828531f, 7793583f, 7776108f, 7758633f, 7741159f, 7723685f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7706211f, 7723685f, 7723685f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7741159f, 7723685f, 7723685f, 7688736f, 7671261f, 7653787f, 7583889f, 7566415f, 7513992f, 7461569f, 7444095f, 7409145f, 7374197f, 7356723f, 7321773f, 7304299f, 7286825f, 7269351f, 7251876f, 7234401f, 7199453f, 7181979f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7164504f, 7181979f, 7199453f };
PointF[] points = xValues.Zip(yValues, (x, y) => new PointF(x, y)).ToArray();
// Create a region with the original values
GraphicsPath pathWithOriginalPoints = new GraphicsPath();
pathWithOriginalPoints.AddPolygon(points);
Region regionFromOriginalPoints = new Region(pathWithOriginalPoints);
// Create a region with the values divided by 1000
GraphicsPath pathDividedBy1000 = new GraphicsPath();
pathDividedBy1000.AddPolygon(points.Select(p => new PointF(p.X/1000f, p.Y/1000f)).ToArray());
Region regionDividedby1000 = new Region(pathDividedBy1000);
// Time call to Region.IsVisible(PointF)
var stopwatch = Stopwatch.StartNew();
Console.WriteLine("Computing region.IsVisible for points divided by 1000:");
regionDividedby1000.IsVisible(new PointF(0f, 0f));
var dividedBy1000Timing = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"Elapsed time: {dividedBy1000Timing} ms");
stopwatch.Restart();
Console.WriteLine("Computing region.IsVisible for original points");
regionFromOriginalPoints.IsVisible(new PointF(0f, 0f));
var originalTiming = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"Elapsed time: {originalTiming} ms");
}
}
}
最佳答案
TLTR
进行一次Region.IsVisible(Point)
调用所需的时间根本不取决于点数。取而代之的是,它取决于矩形的数目,该数目足以完全准确地覆盖区域。这取决于..:
Region
不是我所说的“有据可查”的类。
RegionData
,可以通过调用
var RData = your Region.GetRegionData()
来访问它。
PathPoints&PathTypes
中的
GraphicsPath
。在您的示例中为924 + 1个点和1 + 2 * 4个字节组成了8325个字节;另外还有27个字节; 8个可以保持缩放比例。)
RegionData
,您的Regions
的都可以轻松地看到它们的
的大小相同。这表明
8352
在额外的时间中并不直接相关。
RegionData
。 MSDN对此表示:
Returns an array of RectangleF structures that approximate this Region after the specified matrix transformation is applied.
Matrix M = new Matrix();
var scans1 = regionFromOriginalPoints.GetRegionScans(M);
var scans2 = regionDividedby1000.GetRegionScans(M);
scans1.Length = 5.960.690
scans2.Length = 5.956
GetRegionScans
,并且瞧瞧这样做也要花费很多时间。.:Region
,也不需要任何边小于1像素的矩形。RectangleF
调用内部需要创建这些近似矩形,并且需要足够的矩形才能覆盖区域内每个完整像素。 (请注意IsVisible
不支持部分/抗锯齿像素!)区域的边界越大,适合的像素就越多,扫描过程所需的时间也越长。Region
也应该非常快。让我们来看看;当我测量这个:int hits = 0;
PointF pt = new PointF(123.456f, 789.012f);
foreach (RectangleF r in scans1) if (r.Contains(pt)) hits++;
RectangleF.Contains(Point)
。因此,一旦缓存了扫描矩形,您就可以轻松地对它们进行很多 HitTest 而不是来进行单独的42ms
调用。Your original path:
number of polygon points = 924
regionData1.Length = 8.352
scans1.Length = 5.960.690
Elapsed time1: 453.187 msThe path scaled down by 1000:
number of polygon points = 924
regionData2.Length = 8.352
scans2.Length= 5.956
Elapsed time2: 2 msElapsed time for full set of scans: 41 ms
for (int i = 0; i < scans.Length; i++)
g.FillRectangle(i%2 == 0 ? Brushes.ForestGreen : Brushes.Salmon, scans[i]);
IsVisible
和222x111
)都用111x222
水平条纹近似。由于曲率不同,该值小于圆。85
;但可以通过按比例放大或缩小数据来修改结果。 该圆的Matrix
为Height
像素,并且需要222
扫描矩形才能对其进行近似。 如果我们按比例放大135
(即用于表示Matrix
的Graphics
对象):Region
,则需要m.Scale(10,10);
扫描矩形覆盖放大的圆。1315
缩放的矩阵来代替缩放数据点。但它只会测试按比例缩小的版本,并且可能会丢失边框周围的像素或包含错误的像素。因此,最好只使用您实际需要的正确比例。0.001f
确实具有 13 GraphicsPath
;但是这些实际上只是四个实点(再加上第一个实点来关闭图形),以及,每对点之间有两个控制点;因此5 + 4 * 2 =13。另外请注意,PathPoints
中的任何线
均为直线或贝塞尔曲线的。 这包括弧,椭圆和圆!
关于c# - Region.IsVisible(PointF)对于大浮点值的性能非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43139118/
这个问题已经有答案了: Invalid types 'double [100][double]' for array subscript (3 个回答) 已关闭 6 年前。 我已复制下面的整个代码并在
您有 2 个功能; f(x)= x(((x+1)^(1/2))-(x^(1/2))) g(x)= x/(((x+1)^(1/2))+(x^(1/2))) 哪个更准确? 旁注:如果你能解释为什么,
我正在从事一个关于java的研究项目,其中必须完成一些艰难的计算。然而,我已经完成了大部分工作,但停留在某个点上。我必须计算以下内容: (2.1-2.3) raised to power 0.3. 但
int main() { float x = 50; float y = 1/x; float result = y * x; float test = 41;
有没有安全的方法来可靠地确定整数类型 T可以存储浮点整数值 f (所以 f == floor(f) )没有任何溢出? 请记住,不能保证浮点类型 F与 IEC 559 (IEEE 754) 兼容,并且有
// value will always be in the range of [0.0 - maximum] float obtainRatio(float value, float maximum
就在今天,我遇到了我们正在使用的第三方软件,在他们的示例代码中,有以下内容: // Defined in somewhere.h static const double BAR = 3.14; //
是否有推荐的方法来清除 jQuery Flot 图表?我在 API 引用中找不到任何内容。 最佳答案 “清除”是指“破坏整个图表”还是只是清除数据? 要核对整个图表:$('#canvas_id').e
我正在学习单精度并想了解错误传播。根据this nice website ,加法是一个危险的操作。 所以我编写了一个小的 C 程序来测试错误累积的速度。我不完全确定这是否是一种有效的测试方法。如果是,
我正在尝试查询数据库,我需要获取权重等于 60.5 的客户列表。问题是 60.5 是一个实数,我以前从未在 where 子句中使用实数查询过数据库。 我已经尝试过这个: SELECT Name FRO
这是我的“ProjectEntity”类中的代码部分(我在其中使用 hibernate 进行 SQL 调用) @Column(name = "BUDGET") private float budget
我用 Haskell 编写了一个应用程序,它调用 Z3 求解器来解决一些复杂公式的约束。感谢 Haskell,我可以快速切换正在使用的数据类型。 当使用 SBV 的 AlgReal 类型进行计算时,我
在 C 中 double/float 有一个集合类型说明符:%f %F %g %G %e %E .有什么区别吗 %f和 %F , %g和 %G , %e和 %E ? 根据 printf和 scanf输
我正在开发一个适用于 Android 的可视化应用程序(包括运行 Android 2.2 的旧设备)。 我的应用程序的输入模型包含一个区域,该区域通常由数万个顶点组成。典型模型有 50000-1000
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我被要求编写一个程序来查找我大学中两个输入的总和,因此我应该首先检查输入是否有效。 例如,如果我输入 2534.11s35,程序应该检测到它不是该程序的有效输入,因为输入中存在 s。 最佳答案 to
我正在尝试降低 FPGA 的逻辑利用率,但在网上找不到任何好的 float fastpow。我所说的“好”是指充分减少所使用的逻辑。如果我使用双版本我几乎没有什么改进。如果我使用其他依赖日志的 flo
我有一个 128 字节的内存位置。我尝试用从 1...127 开始的数据填充内存。 我需要编写一个代码来获取两个参数,如偏移量、数据类型。根据参数,我需要将内存中的数据转换为提到的特定数据类型。 举个
我希望能够做到以下几点: float func() { if( error ) return InvalidFloatingPointValue; else return 0.0f;
假设我有两个 float ,我想比较它们。如果一个大于另一个,程序应该采用一个 fork。如果情况正好相反,它应该走另一条路。并且它应该做同样的事情,如果被比较的值在一个仍然应该使它比较真实的方向上被
我是一名优秀的程序员,十分优秀!