English 中文(简体)
提炼Algorithm
原标题:Line Drawing Algorithm

我用武技术写了一条线图算法。 它发挥作用,但存在问题。 见下文。

我不禁要问的是,是否有任何人解决了划定反恐怖线的问题? 简言之,单角搜索结果没有令人满意的算法。 脱离图形图书馆,但并非完全可靠的算法。

如果有人想为以下职能制定样本代码,我就知道。 我希望用更强有力的职能来取代这一职能,但我尚未发现。 我确信,我的算法可以改进,但可以改进。

struct xya
{
    int x;
    int y; 
    uint8_t a;
    xya(int x=0, int y=0, uint8_t a=0) : x(x), y(y), a(a) {}
};

inline void wuline(xya*& out, int x0, int y0, int x1, int y1)
{
    short DeltaX, DeltaY, XDir;
    static const int intensity = 8;

    if (y0 > y1)
    {
        short Temp = y0; 
        y0 = y1; 
        y1 = Temp;
        Temp = x0; 
        x0 = x1; 
        x1 = Temp;
    }

    *out++ = xya(x0,y0,255);

    if ((DeltaX = x1 - x0) >= 0)
    {
        XDir = 1;
    } 
    else 
    {
        XDir = -1;
        DeltaX = -DeltaX; 
    }

    if ((DeltaY = y1 - y0) == 0)
    {
        while (DeltaX-- != 0) 
        {
            x0 += XDir;
            *out++ = xya(x0,y0,255);            
        }

        return;
    }

    if (DeltaX == 0) 
    {
        do 
        {
            y0++;
            *out++ = xya(x0,y0,255);            
        } 
        while (--DeltaY != 0);

        return;
    }

    if (DeltaX == DeltaY) 
    {
        do 
        {
            x0 += XDir;
            y0++;
            *out++ = xya(x0,y0,255);            
        } 
        while (--DeltaY != 0);

        return;
    }

    if (DeltaY > DeltaX) 
    {
        unsigned short ErrorAcc = 0;  
        unsigned short ErrorAdj = ((unsigned long) DeltaX > intensity;
            *out++ = xya(x0,y0,Weighting ^ 255);
            *out++ = xya(x0+XDir,y0,Weighting);
        }

        *out++ = xya(x1,y1,255);            
    }
    else
    {
        unsigned short ErrorAcc = 0;  
        unsigned short ErrorAdj = ((unsigned long) DeltaY > intensity;
            *out++ = xya(x0,y0,Weighting ^ 255);            
            *out++ = xya(x0,y0+1,Weighting);
        }

        *out++ = xya(x1,y1,255);
    }
}

问题回答

我曾被赋予了制定各种复杂和重叠的形状的任务,这些形形形形形形状需要反恐怖。 我的解决办法是,在一项更高的决议(2x)中,把所有东西引出记忆? 与需要展示的形象相比,情况是3x? 之后,作为最后一步,将R、G和B分别转换为低脂肪,将高脂肪中的每一块混凝土改成一个显示图像中的单浆。

它可能不是最高效的做事方式,但其死去容易成形,视觉效果很好。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签