Example #1
0
void CVMergeSplineSets(CharView *cv, SplinePoint *active, SplineSet *activess,
	SplinePoint *merge, SplineSet *mergess) {
    SplinePointList *spl;

    cv->joinvalid = true;
    cv->joinpos = *merge; cv->joinpos.selected = false;

    if ( active->prev==NULL )
	SplineSetReverse(activess);
    if ( merge->next==NULL )
	SplineSetReverse(mergess);
    active->nextcp = merge->nextcp;
    active->nonextcp = merge->nonextcp;
    active->nextcpdef = merge->nextcpdef;
    active->next = merge->next;
    if ( merge->next!= NULL ) {
	active->next->from = active;
	activess->last = mergess->last;
    }
    merge->next = NULL;
    if ( mergess==activess ) {
	activess->first = activess->last = active;
	SplinePointMDFree(cv->b.sc,merge);
	if ( activess->spiro_cnt!=0 ) {
	    activess->spiros[0].ty = activess->spiros[activess->spiro_cnt-2].ty;
	    activess->spiros[activess->spiro_cnt-2] = activess->spiros[activess->spiro_cnt-1];
	    --activess->spiro_cnt;
	}
    } else {
	mergess->last = merge;
	if ( mergess==cv->b.layerheads[cv->b.drawmode]->splines )
	    cv->b.layerheads[cv->b.drawmode]->splines = mergess->next;
	else {
	    for ( spl = cv->b.layerheads[cv->b.drawmode]->splines; spl->next!=mergess; spl=spl->next );
	    spl->next = mergess->next;
	}
	if ( activess->spiros && mergess->spiros ) {
	    if ( activess->spiro_cnt+mergess->spiro_cnt > activess->spiro_max )
		activess->spiros = realloc(activess->spiros,
			(activess->spiro_max = activess->spiro_cnt+mergess->spiro_cnt)*sizeof(spiro_cp));
	    memcpy(activess->spiros+activess->spiro_cnt-1,
		    mergess->spiros+1, (mergess->spiro_cnt-1)*sizeof(spiro_cp));
	    activess->spiro_cnt += mergess->spiro_cnt-2;
	} else
	    SplineSetSpirosClear(activess);
	SplinePointListMDFree(cv->b.sc,mergess);
    }
    if (( active->pointtype==pt_curve || active->pointtype==pt_hvcurve ) &&
	    !active->nonextcp && !active->noprevcp &&
	    !active->nextcpdef && !active->prevcpdef &&
	    !BpColinear(&active->prevcp,&active->me,&active->nextcp))
	active->nextcpdef = active->prevcpdef = true;
    SplineSetJoinCpFixup(active);
}
Example #2
0
static int RulerText(CharView *cv, unichar_t *ubuf, int line) {
    char buf[80];
    double len;
    double dx, dy;
    Spline *s;
    double t;
    BasePoint slope;
    real xoff = cv->info.x-cv->p.cx, yoff = cv->info.y-cv->p.cy;

    buf[0] = '\0';
    switch ( line ) {
      case 0: {
	real len = sqrt(xoff*xoff+yoff*yoff);

	if ( cv->autonomous_ruler_w ) {
	    xoff = last_ruler_offset[0].x;
	    yoff = last_ruler_offset[0].y;
	}

	if ( !cv->autonomous_ruler_w && !cv->p.pressed )
	    /* Give current location accurately */
	    sprintf( buf, "%f,%f", (double) cv->info.x, (double) cv->info.y);
	else
	    sprintf( buf, "%f %.0f° (%f,%f)", (double) len,
		    atan2(yoff,xoff)*180/3.1415926535897932,
		    (double) xoff,(double) yoff);
      break; }
      case 1:
	if ( cv->p.pressed ) {
	    if ( cv->p.spline!=NULL ||
		    (cv->p.sp!=NULL &&
		     ((cv->p.sp->next==NULL && cv->p.sp->prev!=NULL) ||
		      (cv->p.sp->prev==NULL && cv->p.sp->next!=NULL) ||
		      (cv->p.sp->next!=NULL && cv->p.sp->prev!=NULL &&
		        BpColinear(!cv->p.sp->noprevcp ? &cv->p.sp->prevcp : &cv->p.sp->prev->from->me,
				&cv->p.sp->me,
			        !cv->p.sp->nonextcp ? &cv->p.sp->nextcp : &cv->p.sp->next->to->me))) ) ) {
		Spline *spline;
		double t;

		if ( cv->p.spline!=NULL ) {
		    spline = cv->p.spline;
		    t = cv->p.t;
		} else if ( cv->p.sp->next == NULL ) {
		    spline = cv->p.sp->prev;
		    t = 1;
		} else {
		    spline = cv->p.sp->next;
		    t = 0;
		}
		slope.x = (3*spline->splines[0].a*t + 2*spline->splines[0].b)*t + spline->splines[0].c;
		slope.y = (3*spline->splines[1].a*t + 2*spline->splines[1].b)*t + spline->splines[1].c;
		len = sqrt(slope.x*slope.x + slope.y*slope.y);
		if ( len!=0 ) {
		    slope.x /= len; slope.y /= len;
		    sprintf( buf, _("Normal Distance: %.2f Along Spline: %.2f"),
			    fabs(slope.y*xoff - slope.x*yoff),
			    slope.x*xoff + slope.y*yoff );
		}
	    }
	} else if ( cv->dv!=NULL || cv->b.gridfit!=NULL ) {
	    double scalex = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent)/(rint(cv->ft_pointsizex*cv->ft_dpi/72.0));
	    double scaley = (cv->b.sc->parent->ascent+cv->b.sc->parent->descent)/(rint(cv->ft_pointsizey*cv->ft_dpi/72.0));
	    sprintf( buf, "%.2f,%.2f", (double) (cv->info.x/scalex), (double) (cv->info.y/scaley));
	} else if ( cv->p.spline!=NULL ) {
	    s = cv->p.spline;
	    t = cv->p.t;
	    sprintf( buf, _("Near (%f,%f)"),
		    (double) (((s->splines[0].a*t+s->splines[0].b)*t+s->splines[0].c)*t+s->splines[0].d),
		    (double) (((s->splines[1].a*t+s->splines[1].b)*t+s->splines[1].c)*t+s->splines[1].d) );
	} else if ( cv->p.sp!=NULL ) {
	    sprintf( buf, _("Near (%f,%f)"),(double) cv->p.sp->me.x,(double) cv->p.sp->me.y );
	} else
return( false );
      break;
      case 2:
	if ( cv->p.pressed ) {
	    if ( cv->p.sp!=NULL && cv->info_sp!=NULL &&
		    ((cv->p.sp->next!=NULL && cv->p.sp->next->to==cv->info_sp) ||
		     (cv->p.sp->prev!=NULL && cv->p.sp->prev->from==cv->info_sp)) ) {
		if ( cv->p.sp->next!=NULL && cv->p.sp->next->to==cv->info_sp )
		    len = SplineLength(cv->p.sp->next);
		else
		    len = SplineLength(cv->p.sp->prev);
	    } else if ( cv->p.spline == cv->info_spline && cv->info_spline!=NULL )
		len = SplineLengthRange(cv->info_spline,cv->p.t,cv->info_t);
	    else if ( cv->p.sp!=NULL && cv->info_spline!=NULL &&
		    cv->p.sp->next == cv->info_spline )
		len = SplineLengthRange(cv->info_spline,0,cv->info_t);
	    else if ( cv->p.sp!=NULL && cv->info_spline!=NULL &&
		    cv->p.sp->prev == cv->info_spline )
		len = SplineLengthRange(cv->info_spline,cv->info_t,1);
	    else if ( cv->info_sp!=NULL && cv->p.spline!=NULL &&
		    cv->info_sp->next == cv->p.spline )
		len = SplineLengthRange(cv->p.spline,0,cv->p.t);
	    else if ( cv->info_sp!=NULL && cv->p.spline!=NULL &&
		    cv->info_sp->prev == cv->p.spline )
		len = SplineLengthRange(cv->p.spline,cv->p.t,1);
	    else
return( false );
	    if ( len>1 )
		sprintf( buf, _("Spline Length=%.1f"), len);
	    else
		sprintf( buf, _("Spline Length=%g"), len);
	} else if ( cv->p.spline!=NULL ) {
	    s = cv->p.spline;
	    t = cv->p.t;
	    dx = (3*s->splines[0].a*t+2*s->splines[0].b)*t+s->splines[0].c;
	    dy = (3*s->splines[1].a*t+2*s->splines[1].b)*t+s->splines[1].c;
	    SlopeToBuf(buf,"",dx,dy);
	} else if ( cv->p.sp!=NULL ) {
	    if ( cv->p.sp->nonextcp )
		strcpy(buf,_("No Next Control Point"));
	    else
		sprintf(buf,_("Next CP: (%f,%f)"), (double) cv->p.sp->nextcp.x, (double) cv->p.sp->nextcp.y);
	} else
return( false );
      break;
      case 3:
	if ( cv->p.pressed )
return( false );
	else if ( cv->p.spline!=NULL ) {
	    CurveToBuf(buf,cv,cv->p.spline,cv->p.t);
	} else if ( cv->p.sp!=NULL && cv->p.sp->next!=NULL ) {
	    s = cv->p.sp->next;
	    dx = s->splines[0].c;
	    dy = s->splines[1].c;
	    SlopeToBuf(buf,_(" Next"),dx,dy);
	} else if ( cv->p.sp!=NULL ) {
	    if ( cv->p.sp->noprevcp )
		strcpy(buf,_("No Previous Control Point"));
	    else
		sprintf(buf,_("Prev CP: (%f,%f)"), (double) cv->p.sp->prevcp.x, (double) cv->p.sp->prevcp.y);
	} else
return( false );
      break;
      case 4:
	if ( cv->p.spline!=NULL )
return( false );
	else if ( cv->p.sp->next!=NULL ) {
	    CurveToBuf(buf,cv,cv->p.sp->next,0);
	} else if ( cv->p.sp->prev!=NULL ) {
	    s = cv->p.sp->prev;
	    dx = (3*s->splines[0].a*1+2*s->splines[0].b)*1+s->splines[0].c;
	    dy = (3*s->splines[1].a*1+2*s->splines[1].b)*1+s->splines[1].c;
	    SlopeToBuf(buf,_(" Prev"),dx,dy);
	} else
return( false );
      break;
      case 5:
	if ( cv->p.sp->next!=NULL ) {
	    if ( cv->p.sp->noprevcp )
		strcpy(buf,_("No Previous Control Point"));
	    else
		sprintf(buf,_("Prev CP: (%f,%f)"), (double) cv->p.sp->prevcp.x, (double) cv->p.sp->prevcp.y);
	} else {
	    CurveToBuf(buf,cv,cv->p.sp->prev,1);
	}
      break;
      case 6:
	if ( cv->p.sp->next!=NULL && cv->p.sp->prev!=NULL ) {
	    s = cv->p.sp->prev;
	    dx = (3*s->splines[0].a*1+2*s->splines[0].b)*1+s->splines[0].c;
	    dy = (3*s->splines[1].a*1+2*s->splines[1].b)*1+s->splines[1].c;
	    SlopeToBuf(buf,_(" Prev"),dx,dy);
	} else
return( false );
      break;
      case 7:
	if ( cv->p.sp->next!=NULL && cv->p.sp->prev!=NULL ) {
	    CurveToBuf(buf,cv,cv->p.sp->prev,1);
	} else
return( false );
      break;
      default:
return( false );
    }
    utf82u_strcpy(ubuf,buf);
return( true );
}