Exemple #1
0
        public Polygon3D Vs_polygon_clip_2d(Polygon3D poly)
        {
            Polygon3D s     = new Polygon3D();
            Polygon3D r     = new Polygon3D();
            double    vxmin = vp_xmin - 0.40000000000000002D;
            double    vymin = vp_ymin - 0.40000000000000002D;
            double    vxmax = vp_xmax + 0.40000000000000002D;
            double    vymax = vp_ymax + 0.40000000000000002D;

            s.SetPol(poly);
            double xmin = poly.XMin();
            double xmax = poly.XMax();
            double ymin = poly.YMin();
            double ymax = poly.YMax();

            if (xmax < vxmin || xmin > vxmax || ymax < vymin || ymin > vymax)
            {
                return(r);
            }
            if (xmin >= vxmin && xmax <= vxmax && ymin >= vymin && ymax <= vymax)
            {
                r.SetPol(poly);
                return(r);
            }
            if (xmin >= vxmin)
            {
                r.SetPol(s);
            }
            else
            {
                for (int i = 0; i < s.NVertex(); i++)
                {
                    int j;
                    if (i == s.NVertex() - 1)
                    {
                        j = 0;
                    }
                    else
                    {
                        j = i + 1;
                    }
                    double xi = s.GetVertex(i).x;
                    double yi = s.GetVertex(i).y;
                    double xj = s.GetVertex(j).x;
                    double yj = s.GetVertex(j).y;
                    if (xi >= vxmin)
                    {
                        r.AddVertex(new Vector3D(xi, yi, 0.0D));
                        if (xj < vxmin)
                        {
                            r.AddVertex(new Vector3D(vxmin, yi
                                                     + ((yj - yi) * (vxmin - xi)) / (xj - xi), 0.0D));
                        }
                    }
                    else if (xj >= vxmin)
                    {
                        r.AddVertex(new Vector3D(vxmin, yi
                                                 + ((yj - yi) * (vxmin - xi)) / (xj - xi), 0.0D));
                    }
                }
            }
            s = new Polygon3D();
            if (ymin >= vymin)
            {
                s.SetPol(r);
            }
            else
            {
                for (int i_0 = 0; i_0 < r.NVertex(); i_0++)
                {
                    int j_1;
                    if (i_0 == r.NVertex() - 1)
                    {
                        j_1 = 0;
                    }
                    else
                    {
                        j_1 = i_0 + 1;
                    }
                    double xi_2 = r.GetVertex(i_0).x;
                    double yi_3 = r.GetVertex(i_0).y;
                    double xj_4 = r.GetVertex(j_1).x;
                    double yj_5 = r.GetVertex(j_1).y;
                    if (yi_3 >= vymin)
                    {
                        s.AddVertex(new Vector3D(xi_2, yi_3, 0.0D));
                        if (yj_5 < vymin)
                        {
                            s.AddVertex(new Vector3D(xi_2 + ((xj_4 - xi_2) * (vymin - yi_3)) / (yj_5 - yi_3), vymin, 0.0D));
                        }
                    }
                    else if (yj_5 >= vymin)
                    {
                        s.AddVertex(new Vector3D(xi_2 + ((xj_4 - xi_2) * (vymin - yi_3)) / (yj_5 - yi_3), vymin, 0.0D));
                    }
                }
            }
            r = new Polygon3D();
            if (xmax <= vxmax)
            {
                r.SetPol(s);
            }
            else
            {
                for (int i_6 = 0; i_6 < s.NVertex(); i_6++)
                {
                    int j_7;
                    if (i_6 == s.NVertex() - 1)
                    {
                        j_7 = 0;
                    }
                    else
                    {
                        j_7 = i_6 + 1;
                    }
                    double xi_8  = s.GetVertex(i_6).x;
                    double yi_9  = s.GetVertex(i_6).y;
                    double xj_10 = s.GetVertex(j_7).x;
                    double yj_11 = s.GetVertex(j_7).y;
                    if (xi_8 <= vxmax)
                    {
                        r.AddVertex(new Vector3D(xi_8, yi_9, 0.0D));
                        if (xj_10 > vxmax)
                        {
                            r.AddVertex(new Vector3D(vxmax, yi_9 + ((yj_11 - yi_9) * (vxmax - xi_8)) / (xj_10 - xi_8), 0.0D));
                        }
                    }
                    else if (xj_10 <= vxmax)
                    {
                        r.AddVertex(new Vector3D(vxmax, yi_9 + ((yj_11 - yi_9) * (vxmax - xi_8)) / (xj_10 - xi_8), 0.0D));
                    }
                }
            }
            s = new Polygon3D();
            if (ymax <= vymax)
            {
                s.SetPol(r);
            }
            else
            {
                for (int i_12 = 0; i_12 < r.NVertex(); i_12++)
                {
                    int j_13;
                    if (i_12 == r.NVertex() - 1)
                    {
                        j_13 = 0;
                    }
                    else
                    {
                        j_13 = i_12 + 1;
                    }
                    double xi_14 = r.GetVertex(i_12).x;
                    double yi_15 = r.GetVertex(i_12).y;
                    double xj_16 = r.GetVertex(j_13).x;
                    double yj_17 = r.GetVertex(j_13).y;
                    if (yi_15 <= vymax)
                    {
                        s.AddVertex(new Vector3D(xi_14, yi_15, 0.0D));
                        if (yj_17 > vymax)
                        {
                            s.AddVertex(new Vector3D(xi_14 + ((xj_16 - xi_14) * (vymax - yi_15)) / (yj_17 - yi_15),
                                                     vymax, 0.0D));
                        }
                    }
                    else if (yj_17 <= vymax)
                    {
                        s.AddVertex(new Vector3D(xi_14 + ((xj_16 - xi_14) * (vymax - yi_15)) / (yj_17 - yi_15), vymax, 0.0D));
                    }
                }
            }
            return(s);
        }