Exemple #1
0
bool LineSegment::containPointOpen(Point pt)// judge whether the point is no the line 
{
	double zero = a * pt.x + b * pt.y + c;

	double tmp = DOUBLE_EQUAL(zero, 0);
	return (DOUBLE_EQUAL(zero, 0));
}
Exemple #2
0
/**
 * image_view_set_zoom:
 * @view: An image view.
 * @zoomx: Horizontal zoom factor.
 * @zoomy: Vertical zoom factor.
 * @have_anchor: Whether the anchor point specified by (@anchorx, @anchory)
 * should be used.
 * @anchorx: Horizontal anchor point in pixels.
 * @anchory: Vertical anchor point in pixels.
 *
 * Sets the zoom factor for an image view.  The anchor point can be used to
 * specify the point that stays fixed when the image is zoomed.  If @have_anchor
 * is %TRUE, then (@anchorx, @anchory) specify the point relative to the image
 * view widget's allocation that will stay fixed when zooming.  If @have_anchor
 * is %FALSE, then the center point of the image view will be used.
 **/
void
image_view_set_zoom (ImageView *view, double zoomx, double zoomy,
		     gboolean have_anchor, int anchorx, int anchory)
{
	ImageViewPrivate *priv;

	g_return_if_fail (view != NULL);
	g_return_if_fail (IS_IMAGE_VIEW (view));
	g_return_if_fail (zoomx > 0.0);
	g_return_if_fail (zoomy > 0.0);

	priv = view->priv;

	if (zoomx > MAX_ZOOM_FACTOR)
		zoomx = MAX_ZOOM_FACTOR;
	else if (zoomx < MIN_ZOOM_FACTOR)
		zoomx = MIN_ZOOM_FACTOR;
	if (zoomy > MAX_ZOOM_FACTOR)
		zoomy = MAX_ZOOM_FACTOR;
	else if (zoomy < MIN_ZOOM_FACTOR)
		zoomy = MIN_ZOOM_FACTOR;

	if (DOUBLE_EQUAL (priv->zoomx, zoomx) &&
	    DOUBLE_EQUAL (priv->zoomy, zoomy))
		goto out;

	if (!priv->need_zoom_change) {
		priv->old_zoomx = priv->zoomx;
		priv->old_zoomy = priv->zoomy;
		priv->need_zoom_change = TRUE;
	}

	priv->zoomx = zoomx;
	priv->zoomy = zoomy;

	g_signal_emit (view, image_view_signals [ZOOM_CHANGED], 0);

	if (have_anchor) {
		anchorx = CLAMP (anchorx, 0, GTK_WIDGET (view)->allocation.width);
		anchory = CLAMP (anchory, 0, GTK_WIDGET (view)->allocation.height);
		set_zoom_anchor (view, anchorx, anchory);
	} else
		set_default_zoom_anchor (view);

 out:

	gtk_widget_queue_resize (GTK_WIDGET (view));
}
Exemple #3
0
bool LineSegment::containPointClose(Point pt)
{
	double minx = mymin(start.x, end.x);
	double maxx = mymax(start.x, end.x);
	double miny = mymin(start.y, end.y);
	double maxy = mymax(start.y, end.y);

	if (containPointOpen(pt) && 
		(pt.x > minx || DOUBLE_EQUAL(pt.x, minx)) && 
		(pt.x < maxx || DOUBLE_EQUAL(pt.x, maxx)) &&
		(pt.y > miny || DOUBLE_EQUAL(pt.y, miny)) && 
		(pt.y < maxy || DOUBLE_EQUAL(pt.y, maxy))) 
		return true;
	else
		return false;
}
Exemple #4
0
/**
 *add two poly
 *node: it modifies rhs, (rhs will own no items)
 *@return: added poly result is stored in lhs
 *    you need to set lhs to the new value
 */
void poly_add_inp(Poly** lhs, Poly* rhs)
{
    Poly odd;
    Poly *p1, *q1, *p2;
    if (NULL == lhs)
        return;
    if (*lhs == rhs)
        return poly_mul_cons_inp(lhs, 2);
    odd.next = *lhs;
    p1 = odd.next, q1 = &odd, p2 = rhs;
    for (; NULL != p2 && NULL != p1;) {
        if (p1->index == p2->index) {
            p1->coeff += p2->coeff;
            if (DOUBLE_EQUAL(p1->coeff, 0)) {
                destroy_poly_head(&p1); //destory node p1 and move forward
                q1->next = p1;
            }
            destroy_poly_head(&p2); //destory node p2 and move forward
        } else if (p1->index < p2->index) {
            Poly* tmp_next = p2->next;
            p2->next = p1;
            q1->next = p2;
            q1 = q1->next;
            p2 = tmp_next;
        } else {
            q1 = p1; 
            p1 = p1->next;
        }
    }
    if (NULL == p1)
        q1->next = p2;

    *lhs = odd.next;
}
Exemple #5
0
bool LineSegment::containPointExclusiveEnds(Point pt)
{
	double minx = mymin(start.x, end.x);
	double maxx = mymax(start.x, end.x);
	double miny = mymin(start.y, end.y);
	double maxy = mymax(start.y, end.y);

	if (containPointOpen(pt) && 
		(pt.x > minx || DOUBLE_EQUAL(pt.x, minx)) && 
		(pt.x < maxx || DOUBLE_EQUAL(pt.x, maxx)) && 
		(pt.y > miny || DOUBLE_EQUAL(pt.y, miny)) && 
		(pt.y < maxy || DOUBLE_EQUAL(pt.y, maxy)) && 
		pt.approxInequal(start) && 
		pt.approxInequal(end)) 
		return true;
	else
		return false;
}
Exemple #6
0
/**
 *negative index is not allowed
 *@return: stored quotient in plhs
 */
void poly_div_inp(Poly** plhs, const Poly* rhs)
{
    Poly* lhs = *plhs;
    Poly odd = {.next = lhs};
    Poly* res = NULL;
    if (NULL == lhs || NULL == rhs)
        return;
    if (*plhs == rhs) { //lhs and rhs are the same poly
        destroy_poly(plhs);
        *plhs = create_poly(1, 0);
        return;
    }
    for (; NULL != lhs && lhs->index >= rhs->index;) {
        Poly *p1, *q1;
        const Poly* p2;
        Poly* item = create_poly(lhs->coeff / rhs->coeff,
             lhs->index - rhs->index);
        poly_add_inp(&res, poly_copy(item));
        //printf("res: \n");
        //print_poly(res);
        for (p1 = lhs, q1 = &odd, p2 = rhs; NULL != p1 && NULL != p2;) {
            //print_poly(p2);
            if (p1->index - p2->index == item->index) {
                p1->coeff -= p2->coeff * item->coeff;   //coeff may be zero
                if (DOUBLE_EQUAL(p1->coeff, 0)) {
                    destroy_poly_head(&p1); //move forward
                    q1->next = p1;
                }
                p2 = p2->next;
            } else if (p1->index - p2->index > item->index) {
                q1 = p1;
                p1 = p1->next;
            } else
                p2 = p2->next;
        }
        lhs = odd.next;
        //printf("lhs: \n");
        //print_poly(lhs);
    }
    *plhs = odd.next;
    destroy_poly(plhs);
    *plhs = res;
}
Exemple #7
0
static gboolean
unity_zoom (ImageViewPrivate *priv)
{
	return (DOUBLE_EQUAL (priv->zoomx, 1.0) &&
		DOUBLE_EQUAL (priv->zoomy, 1.0));
}