⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bezr9.c

📁 nucleus 文件系统,内核和彩色图形系统,在小系统上非常好用
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/*         Copyright (c) 1997 - 1999 Accelerated Technology, Inc.        */
/*                                                                       */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the      */
/* subject matter of this material.  All manufacturing, reproduction,    */
/* use, and sales rights pertaining to this subject matter are governed  */
/* by the license agreement.  The recipient of this software implicitly  */
/* accepts the terms of the license.                                     */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                            VERSION          */
/*                                                                       */
/*      BEZR9.c                                          1.9             */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      All                                                              */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the mwBezDepth function.                      */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Robert G. Burrill, Accelerated Technology, Inc.                  */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*                                                                       */
/*************************************************************************/

#include "meta_wnd.h"
#include "metconst.h"    /* MetaWINDOW Constant & Stucture Definitions */
#include "metports.h"    /* MetaWINDOW Port & Bitmap Definitions */
#include "grafdata.h"
#include "metmacs3.h"
#include <stdlib.h>

/* Check for __max function */
#ifndef __max
int __max(int val1, int val2)
{
	if (val1 > val2) return val1;
	return val2;
}
#endif

/* Function mwBezDepth returns the recursion "depth" for
de'Casteljau approximation of a Bezier curve.  The number
of points generated for a given depth is:

      numBezPts = 2^bezDepth (+ 1, for starting point)

mwBezDepth returns zero (0) if the control and handle points
are equal (the curve is a straight line). */

int mwBezDepth(point *PTS)
{
	point C1;	/* temporary control points */
	point C2;
	point H1;
	point H2;
	int maxDltC12;	/* max delta between ctrl1 & ctrl2 */
	int maxDltCH1;	/* max delta between ctrl1 & hand1 */
	int maxDltCH2;	/* max delta between ctrl2 & hand2 */
	int maxDelta;	/* max delta of deltas */
	int depth;	/* depth to return */

	/* get input data */
	C1 = *PTS++;
	H1 = *PTS++;
	H2 = *PTS++;
	C2 = *PTS;

	/* Compute deltas between control points and handles */
	maxDltC12 = __max(abs(C1.X - C2.X), abs(C1.Y - C2.Y));
	maxDltCH1 = __max(abs(C1.X - H1.X), abs(C1.Y - H1.Y));
	maxDltCH2 = __max(abs(C2.X - H2.X), abs(C2.Y - H2.Y)); 

	/* If the handles are equal (or close) to the control points,
	treat the bezier as a straight line. */
	if ((maxDltCH1 < 4 ) && (maxDltCH2 < 4 )) return(0);

	/* determine the maximum delta */
	maxDelta = __max(maxDltC12, maxDltCH1);
	maxDelta = __max(maxDelta,  maxDltCH2);

	if (maxDelta < 8)  depth = 1;			/* 2 segments,  3 points */
	else if (maxDelta < 16)  depth = 2;		/* 4 segments,  5 points */
	else if (maxDelta < 32)  depth = 3;		/* 8 segmests,  9 points */
	else if (maxDelta < 128)  depth = 4;	/* 16 segments, 17 points */
	else if (maxDelta < 512)  depth = 5;	/* 32 segments, 33 points */
	else depth = 6;							/* 64 segments, 65 points */

	return(depth);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -