Blame spiroentrypoints.c

rpm-build 8267b0
/*
rpm-build 8267b0
libspiro - conversion between spiro control points and bezier's
rpm-build 8267b0
Copyright (C) 2007 Raph Levien
rpm-build 8267b0
rpm-build 8267b0
This program is free software; you can redistribute it and/or
rpm-build 8267b0
modify it under the terms of the GNU General Public License
rpm-build 8267b0
as published by the Free Software Foundation; either version 3
rpm-build 8267b0
of the License, or (at your option) any later version.
rpm-build 8267b0
rpm-build 8267b0
This program is distributed in the hope that it will be useful,
rpm-build 8267b0
but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 8267b0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rpm-build 8267b0
GNU General Public License for more details.
rpm-build 8267b0
rpm-build 8267b0
You should have received a copy of the GNU General Public License
rpm-build 8267b0
along with this program; if not, write to the Free Software
rpm-build 8267b0
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
rpm-build 8267b0
02110-1301, USA.
rpm-build 8267b0
rpm-build 8267b0
*/
rpm-build 8267b0
/* Interface routines to Raph's spiro package. */
rpm-build 8267b0
rpm-build 8267b0
#include "spiroentrypoints.h"
rpm-build 8267b0
rpm-build 8267b0
/* These two functions are kept for backwards compatibility */
rpm-build 8267b0
void SpiroCPsToBezier(spiro_cp *spiros,int n,int isclosed,bezctx *bc) {
rpm-build 8267b0
    SpiroCPsToBezier0(spiros,n,isclosed,bc);
rpm-build 8267b0
}
rpm-build 8267b0
void TaggedSpiroCPsToBezier(spiro_cp *spiros,bezctx *bc) {
rpm-build 8267b0
    TaggedSpiroCPsToBezier0(spiros,bc);
rpm-build 8267b0
}
rpm-build 8267b0
rpm-build 8267b0
int
rpm-build 8267b0
SpiroCPsToBezier0(spiro_cp *spiros,int n,int isclosed,bezctx *bc)
rpm-build 8267b0
{
rpm-build 8267b0
    spiro_seg *s;
rpm-build 8267b0
rpm-build 8267b0
    if ( n<=0 )
rpm-build 8267b0
	return 0;
rpm-build 8267b0
    if ( isclosed )
rpm-build 8267b0
	s = run_spiro(spiros,n);
rpm-build 8267b0
    else {
rpm-build 8267b0
	char oldty_start = spiros[0].ty;
rpm-build 8267b0
	char oldty_end   = spiros[n-1].ty;
rpm-build 8267b0
	spiros[0].ty = '{';
rpm-build 8267b0
	spiros[n-1].ty = '}';
rpm-build 8267b0
	s = run_spiro(spiros,n);
rpm-build 8267b0
	spiros[n-1].ty = oldty_end;
rpm-build 8267b0
	spiros[0].ty = oldty_start;
rpm-build 8267b0
    }
rpm-build 8267b0
    if (s) {
rpm-build 8267b0
	spiro_to_bpath(s,n,bc);
rpm-build 8267b0
	free_spiro(s);
rpm-build 8267b0
	return 1; // success
rpm-build 8267b0
    }
rpm-build 8267b0
    return 0 ; // spiro did not converge or encountered non-finite values
rpm-build 8267b0
}
rpm-build 8267b0
rpm-build 8267b0
int
rpm-build 8267b0
TaggedSpiroCPsToBezier0(spiro_cp *spiros,bezctx *bc)
rpm-build 8267b0
{
rpm-build 8267b0
    spiro_seg *s;
rpm-build 8267b0
    int n;
rpm-build 8267b0
rpm-build 8267b0
    for ( n=0; spiros[n].ty!='z' && spiros[n].ty!='}'; ++n );
rpm-build 8267b0
    if ( spiros[n].ty == '}' ) ++n;
rpm-build 8267b0
rpm-build 8267b0
    if ( n<=0 ) return 0; // invalid input
rpm-build 8267b0
    s = run_spiro(spiros,n);
rpm-build 8267b0
    if (s) {
rpm-build 8267b0
	spiro_to_bpath(s,n,bc);
rpm-build 8267b0
	free_spiro(s);
rpm-build 8267b0
	return 1; // success
rpm-build 8267b0
    }
rpm-build 8267b0
    return 0 ; // spiro did not converge or encountered non-finite values
rpm-build 8267b0
}
rpm-build 8267b0
rpm-build 8267b0
void SpiroCPsToBezier1(spiro_cp *spiros,int n,int isclosed,bezctx *bc,int *done) {
rpm-build 8267b0
    *done = SpiroCPsToBezier0(spiros,n,isclosed,bc);
rpm-build 8267b0
}
rpm-build 8267b0
void TaggedSpiroCPsToBezier1(spiro_cp *spiros,bezctx *bc,int *done) {
rpm-build 8267b0
    *done = TaggedSpiroCPsToBezier0(spiros,bc);
rpm-build 8267b0
}