예제 #1
0
        public static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex *verts)
        {
            int    i    = 0;
            float *orig = stackalloc float[2];
            float *ray  = stackalloc float[2];

            ray[0] = 1;
            ray[1] = 0;

            float y_frac  = 0;
            int   winding = 0;

            orig[0] = x;
            orig[1] = y;
            y_frac  = ((float)(CRuntime.Fmod(y, 1.0f)));
            if ((y_frac) < (0.01f))
            {
                y += 0.01f;
            }
            else if ((y_frac) > (0.99f))
            {
                y -= 0.01f;
            }
            orig[1] = y;
            for (i = 0; (i) < (nverts); ++i)
            {
                if ((verts[i].type) == (STBTT_vline))
                {
                    int x0 = verts[i - 1].x;
                    int y0 = verts[i - 1].y;
                    int x1 = verts[i].x;
                    int y1 = verts[i].y;
                    if ((((y) > ((y0) < (y1) ? (y0) : (y1))) && ((y) < ((y0) < (y1) ? (y1) : (y0)))) && ((x) > ((x0) < (x1) ? (x0) : (x1))))
                    {
                        float x_inter = (y - y0) / (y1 - y0) * (x1 - x0) + x0;
                        if ((x_inter) < (x))
                        {
                            winding += ((y0) < (y1)) ? 1 : -1;
                        }
                    }
                }
                if ((verts[i].type) == (STBTT_vcurve))
                {
                    int x0 = verts[i - 1].x;
                    int y0 = verts[i - 1].y;
                    int x1 = verts[i].cx;
                    int y1 = verts[i].cy;
                    int x2 = verts[i].x;
                    int y2 = verts[i].y;
                    int ax = (x0) < ((x1) < (x2) ? (x1) : (x2)) ? (x0) : ((x1) < (x2) ? (x1) : (x2));
                    int ay = (y0) < ((y1) < (y2) ? (y1) : (y2)) ? (y0) : ((y1) < (y2) ? (y1) : (y2));
                    int by = (y0) < ((y1) < (y2) ? (y2) : (y1)) ? ((y1) < (y2) ? (y2) : (y1)) : (y0);
                    if ((((y) > (ay)) && ((y) < (by))) && ((x) > (ax)))
                    {
                        float *q0   = stackalloc float[2];
                        float *q1   = stackalloc float[2];
                        float *q2   = stackalloc float[2];
                        float *hits = stackalloc float[4];
                        q0[0] = x0;
                        q0[1] = y0;
                        q1[0] = x1;
                        q1[1] = y1;
                        q2[0] = x2;
                        q2[1] = y2;
                        if (((equal(q0, q1)) != 0) || ((equal(q1, q2)) != 0))
                        {
                            x0 = verts[i - 1].x;
                            y0 = verts[i - 1].y;
                            x1 = verts[i].x;
                            y1 = verts[i].y;
                            if ((((y) > ((y0) < (y1) ? (y0) : (y1))) && ((y) < ((y0) < (y1) ? (y1) : (y0)))) && ((x) > ((x0) < (x1) ? (x0) : (x1))))
                            {
                                float x_inter = (y - y0) / (y1 - y0) * (x1 - x0) + x0;
                                if ((x_inter) < (x))
                                {
                                    winding += ((y0) < (y1)) ? 1 : -1;
                                }
                            }
                        }
                        else
                        {
                            int num_hits = stbtt__ray_intersect_bezier(orig, ray, q0, q1, q2, hits);
                            if ((num_hits) >= (1))
                            {
                                if ((hits[0]) < (0))
                                {
                                    winding += (hits[1]) < (0) ? -1 : 1;
                                }
                            }
                            if ((num_hits) >= (2))
                            {
                                if ((hits[2]) < (0))
                                {
                                    winding += (hits[3]) < (0) ? -1 : 1;
                                }
                            }
                        }
                    }
                }
            }
            return(winding);
        }