//------------------------------------------------------------------------
 void vcgen_contour::add_vertex(double x, double y, unsigned cmd)
 {
     m_status = initial;
     if(is_move_to(cmd))
     {
         m_src_vertices.modify_last(vertex_dist(x, y));
     }
     else
     {
         if(is_vertex(cmd))
         {
             m_src_vertices.add(vertex_dist(x, y));
         }
         else
         {
             if(is_end_poly(cmd))
             {
                 m_closed = get_close_flag(cmd);
                 if(m_orientation == path_flags_none) 
                 {
                     m_orientation = get_orientation(cmd);
                 }
             }
         }
     }
 }
Example #2
0
void vcgen_dash::add_vertex(FX_FLOAT x, FX_FLOAT y, unsigned cmd)
{
    m_status = initial;
    if(is_move_to(cmd)) {
        m_src_vertices.modify_last(vertex_dist(x, y));
    } else {
        if(is_vertex(cmd)) {
            m_src_vertices.add(vertex_dist(x, y));
        } else {
            m_closed = get_close_flag(cmd);
        }
    }
}
Example #3
0
 //------------------------------------------------------------------------
 void vcgen_stroke::add_vertex(double x, double y, unsigned cmd)
 {
     m_status = initial;
     if(is_move_to(cmd))
     {
         m_src_vertices.modify_last(vertex_dist(x, y));
     }
     else
     {
         if(is_vertex(cmd))
         {
             m_src_vertices.add(vertex_dist(x, y));
         }
         else
         {
             m_closed = get_close_flag(cmd);
         }
     }
 }
Example #4
0
//------------------------------------------------------------------------
void phobos::system::agg::vcgen_smooth_poly1::add_vertex(double x, double y, unsigned cmd)
{
    m_status = initial;
    if(is_move_to(cmd))
    {
        m_src_vertices.modify_last(vertex_dist(x, y));
    }
    else
    {
        if(is_vertex(cmd))
        {
            m_src_vertices.add(vertex_dist(x, y));
        }
        else
        {
            m_closed = get_close_flag(cmd);
        }
    }
}
 //------------------------------------------------------------------------
 void vcgen_smooth_poly1::add_vertex(float x, float y, unsigned cmd)
 {
     m_status = initial;
     if(is_move_to(cmd))
     {
         m_src_vertices.modify_last(vertex_dist(x, y));
     }
     else
     {
         if(is_vertex(cmd))
         {
             m_src_vertices.add(vertex_dist(x, y));
         }
         else
         {
             m_closed = get_close_flag(cmd);
         }
     }
 }
Example #6
0
void check_convergence(void)
{
    int i;
    double fval_err, size_max, avg_perf;
    static vertex_t *centroid;

    if (!centroid)
        centroid = vertex_alloc();

    if (simplex_collapsed(base) == 1)
        goto converged;

    simplex_centroid(base, centroid);
    avg_perf = hperf_unify(centroid->perf);

    fval_err = 0.0;
    for (i = 0; i < simplex_size; ++i) {
        double vert_perf = hperf_unify(base->vertex[i]->perf);
        fval_err += ((vert_perf - avg_perf) * (vert_perf - avg_perf));
    }
    fval_err /= simplex_size;

    size_max = 0.0;
    for (i = 0; i < simplex_size; ++i) {
        double dist = vertex_dist(base->vertex[i], centroid);
        if (size_max < dist)
            size_max = dist;
    }

    if (fval_err < fval_tol && size_max < size_tol)
        goto converged;

    return;

  converged:
    state = SIMPLEX_STATE_CONVERGED;
    session_setcfg(CFGKEY_STRATEGY_CONVERGED, "1");
}
Example #7
0
int strategy_cfg(hsignature_t *sig)
{
    const char *cfgval;
    char *endp;

    init_method = SIMPLEX_INIT_CENTER; /* Default value. */
    cfgval = session_getcfg(CFGKEY_INIT_METHOD);
    if (cfgval) {
        if (strcasecmp(cfgval, "center") == 0) {
            init_method = SIMPLEX_INIT_CENTER;
        }
        else if (strcasecmp(cfgval, "random") == 0) {
            init_method = SIMPLEX_INIT_RANDOM;
        }
        else if (strcasecmp(cfgval, "point") == 0) {
            init_method = SIMPLEX_INIT_POINT;
        }
        else {
            session_error("Invalid value for "
                          CFGKEY_INIT_METHOD " configuration key.");
            return -1;
        }
    }

    /* CFGKEY_INIT_POINT will override CFGKEY_INIT_METHOD if necessary. */
    cfgval = session_getcfg(CFGKEY_INIT_POINT);
    if (cfgval) {
        init_method = SIMPLEX_INIT_POINT;
    }

    cfgval = session_getcfg(CFGKEY_INIT_PERCENT);
    if (cfgval) {
        init_percent = strtod(cfgval, &endp);
        if (*endp != '\0') {
            session_error("Invalid value for " CFGKEY_INIT_PERCENT
                          " configuration key.");
            return -1;
        }
        if (init_percent <= 0 || init_percent > 1) {
            session_error("Configuration key " CFGKEY_INIT_PERCENT
                          " must be between 0.0 and 1.0 (exclusive).");
            return -1;
        }
    }

    cfgval = session_getcfg(CFGKEY_REJECT_METHOD);
    if (cfgval) {
        if (strcasecmp(cfgval, "penalty") == 0) {
            reject_type = REJECT_METHOD_PENALTY;
        }
        else if (strcasecmp(cfgval, "random") == 0) {
            reject_type = REJECT_METHOD_RANDOM;
        }
        else {
            session_error("Invalid value for "
                          CFGKEY_REJECT_METHOD " configuration key.");
            return -1;
        }
    }

    cfgval = session_getcfg(CFGKEY_REFLECT);
    if (cfgval) {
        reflect = strtod(cfgval, &endp);
        if (*endp != '\0') {
            session_error("Invalid value for " CFGKEY_REFLECT
                          " configuration key.");
            return -1;
        }
        if (reflect <= 0.0) {
            session_error("Configuration key " CFGKEY_REFLECT
                          " must be positive.");
            return -1;
        }
    }

    cfgval = session_getcfg(CFGKEY_EXPAND);
    if (cfgval) {
        expand = strtod(cfgval, &endp);
        if (*endp != '\0') {
            session_error("Invalid value for " CFGKEY_EXPAND
                          " configuration key.");
            return -1;
        }
        if (expand <= reflect) {
            session_error("Configuration key " CFGKEY_EXPAND
                          " must be greater than the reflect coefficient.");
            return -1;
        }
    }

    cfgval = session_getcfg(CFGKEY_SHRINK);
    if (cfgval) {
        shrink = strtod(cfgval, &endp);
        if (*endp != '\0') {
            session_error("Invalid value for " CFGKEY_SHRINK
                          " configuration key.");
            return -1;
        }
        if (shrink <= 0.0 || shrink >= 1.0) {
            session_error("Configuration key " CFGKEY_SHRINK
                          " must be between 0.0 and 1.0 (exclusive).");
            return -1;
        }
    }

    cfgval = session_getcfg(CFGKEY_FVAL_TOL);
    if (cfgval) {
        fval_tol = strtod(cfgval, &endp);
        if (*endp != '\0') {
            session_error("Invalid value for " CFGKEY_FVAL_TOL
                          " configuration key.");
            return -1;
        }
    }

    cfgval = session_getcfg(CFGKEY_SIZE_TOL);
    if (cfgval) {
        size_tol = strtod(cfgval, &endp);
        if (*endp != '\0') {
            session_error("Invalid value for " CFGKEY_SIZE_TOL
                          " configuration key.");
            return -1;
        }
    }
    else {
        /* Default stopping criteria: 0.5% of dist(vertex_min, vertex_max). */
        size_tol = vertex_dist(vertex_min(), vertex_max()) * 0.005;
    }
    return 0;
}
Example #8
0
int main() {
	mt19937 rng;
	uniform_int_distribution<int> size_dist(0, 40);
	
	for(int t = 0; t < 10000; ++t) {
		int n = size_dist(rng);
		
		uniform_int_distribution<int> edgecount_dist(0, 5 * n);
		int edgecount = edgecount_dist(rng);
		if(n < 2) edgecount = 0;
		uniform_int_distribution<int> weight_dist(0, 12);
		
		vector<pair<double, pair<int, int> > > edges;
		for(int i = 0; i < edgecount; ++i) {
			uniform_int_distribution<int> vertex_dist(0, n - 1);
			int v1 = vertex_dist(rng);
			int v2 = v1;
			while(v1 == v2) v2 = vertex_dist(rng);
			
			edges.push_back(pair<double, pair<int, int> >(
				weight_dist(rng),
				pair<int, int>(v1, v2)
			));
		}
		
		vector<vector<int> > graph(n);
		for(int i = 0; i < edgecount; ++i) {
			int v1 = edges[i].second.first;
			int v2 = edges[i].second.second;
			graph[v1].push_back(v2);
			graph[v2].push_back(v1);
		}
		
		pair<vector<vector<int> >, double> p = kruskal(n, edges);
		
		if(!sameComponents(graph, p.first)) fail();
		
		for(int v = 0; v < n; ++v) {
			failIfNotTreeComponent(p.first, v);
		}
		
		double weight = 0.0;
		for(int x = 0; x < n; ++x) {
			for(int i = 0; i < p.first[x].size(); ++i) {
				int y = p.first[x][i];
				
				double best = 1.0 / 0.0;
				for(int ei = 0; ei < edges.size(); ++ei) {
					if(
						(edges[ei].second.first == x && edges[ei].second.second == y) ||
						(edges[ei].second.first == y && edges[ei].second.second == x)
					) {
						best = min(best, edges[ei].first);
					}
				}
				weight += best;
			}
		}
		
		if(weight != 2.0 * p.second) fail();
	}
	
	return 0;
}