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

📄 mathutils.cpp

📁 虚拟打印机
💻 CPP
字号:
/* * mathutils.cpp *   Copyright (C) 2006 Michael H. Overlin   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      Contact at poster_printer@yahoo.com */#include "mathutils.h"#include "utils.h"void AddToPoint(IN OUT POINTD& ptd, IN const POINTD& ptdSrc) {	ptd.x += ptdSrc.x;	ptd.y += ptdSrc.y;}VOID CenterInRect(OUT POINTD& ptd, IN const RECTD& rd) {	ptd.x = rd.left + RW(rd)/2;	ptd.y = rd.top + RH(rd)/2;}VOID CenterInRect(OUT POINT& pt, IN CONST RECT& r) {	pt.x = r.left + RW(r) / 2;	pt.y = r.top + RH(r) / 2;}void CenterInRect(OUT RECT& rOut, IN const RECT& rSrc) {	SIZE szOut = { RW(rOut), RH(rOut) };	SIZE szIn = { RW(rSrc), RH(rSrc) };	OffsetRect(&rOut, 		-rOut.left + rSrc.left + (szIn.cx - szOut.cx) / 2 , -rOut.top + rSrc.top + (szIn.cy - szOut.cy) / 2 );}BOOL EqualPt(const POINT& pt1, const POINT& pt2) {	BOOL b = pt1.x == pt2.x && pt1.y == pt2.y;	return b;}BOOL EqualRect(IN const RECTD& rd1, IN const RECTD& rd2) {	return rd1.left == rd2.left && rd1.top == rd2.top && rd1.right == rd2.right && rd1.bottom == rd2.bottom;}BOOL EqualSz(const SIZE& sz1, const SIZE& sz2) {	BOOL b = sz1.cx == sz2.cx && sz1.cy == sz2.cy;	return b;}double GetMaxIsoScale(const SIZED &szdFrame, const SIZED& szdImage) {	double dRetValue = 1;	if (szdImage.cx * szdFrame.cy < szdImage.cy * szdFrame.cx) {		dRetValue = szdFrame.cy / szdImage.cy;	} else {		dRetValue = szdFrame.cx / szdImage.cx;	}	return dRetValue;}BOOL IsRectEmpty(IN const RECTD& rd) {	BOOL bRetValue = rd.right <= rd.left || rd.bottom <= rd.top;	return bRetValue;}BOOL IntersectRect(OUT RECTD& rd, IN const RECTD& rd2, IN const RECTD& rd3) {	rd.left = max(rd2.left, rd3.left);	rd.top = max(rd2.top, rd3.top);	rd.right = min(rd2.right, rd3.right);	rd.bottom = min(rd2.bottom, rd3.bottom);	BOOL bRetValue = rd.right > rd.left && rd.bottom > rd.top;	return bRetValue;}::LandscapeRot::LandscapeRot LandscapeRotateBack(::LandscapeRot::LandscapeRot rotDir) {	::LandscapeRot::LandscapeRot retValue = ::LandscapeRot::eNone;	switch(rotDir) {		case ::LandscapeRot::eNone:	retValue = ::LandscapeRot::eNone;	break;		case ::LandscapeRot::e90:	retValue = ::LandscapeRot::e270;	break;		case ::LandscapeRot::e270:	retValue = ::LandscapeRot::e90;		break;		default:			ASSERTFAIL();			break;	}	return retValue;}void LandscapeRotate(OUT RECT& rDest, IN const RECT& rSrc, IN LandscapeRot::LandscapeRot rotDir) {	RECT rTemp = rSrc;	switch(rotDir) {		case ::LandscapeRot::eNone:			break;		case ::LandscapeRot::e90:			rDest.left		= rTemp.bottom;			rDest.top		= rTemp.left;			rDest.right		= rTemp.top;			rDest.bottom	= rTemp.right;			break;		case ::LandscapeRot::e270:			rDest.left		= rTemp.top;			rDest.top		= rTemp.right;			rDest.right	= rTemp.bottom;			rDest.bottom	= rTemp.left;			break;		default:			ASSERTFAIL();			break;	}}void LandscapeRotate(OUT RECTD& rdDest, IN const RECTD& rdSrc, IN LandscapeRot::LandscapeRot rotDir) {	RECTD rdTemp = rdSrc;	switch(rotDir) {		case ::LandscapeRot::eNone:			break;		case ::LandscapeRot::e90:			rdDest.left		= rdTemp.bottom;			rdDest.top		= rdTemp.left;			rdDest.right	= rdTemp.top;			rdDest.bottom	= rdTemp.right;			break;		case ::LandscapeRot::e270:			rdDest.left		= rdTemp.top;			rdDest.top		= rdTemp.right;			rdDest.right	= rdTemp.bottom;			rdDest.bottom	= rdTemp.left;			break;		default:			ASSERTFAIL();			break;	}}BOOL OffsetRect(OUT RECTD& rd, IN double dx, IN double dy) {	rd.left += dx;	rd.right += dx;	rd.top += dy;	rd.bottom += dy;	return TRUE;}BOOL PtInRect(IN const RECTD& rd, IN const POINTD& ptd) {	BOOL bRetValue =		rd.left <= ptd.x && ptd.x < rd.right && rd.top <= ptd.y && ptd.y < rd.bottom;	return bRetValue;}void SetRect(OUT RECTD& rdDest, IN const POINTD& ptdSrc, IN const SIZED& szdSrc) {	rdDest.left = ptdSrc.x;	rdDest.right = ptdSrc.x + szdSrc.cx;	rdDest.top = ptdSrc.y;	rdDest.bottom = ptdSrc.y + szdSrc.cy;}void SetRect(OUT RECT& rDest, IN const POINT& ptTopLeft, IN const SIZE& sz) {	rDest.left = ptTopLeft.x;	rDest.right = ptTopLeft.x + sz.cx;	rDest.top = ptTopLeft.y;	rDest.bottom = ptTopLeft.y + sz.cy;}void SetRect(OUT RECTD& rdDest, IN double dLeft, double dTop, double dRight, double dBottom) {	rdDest.left = dLeft;	rdDest.top = dTop;	rdDest.right = dRight;	rdDest.bottom = dBottom;}void UnionRect(OUT RECTD& rdDest, IN const RECTD& rdSrc1, IN const RECTD& rdSrc2) { // DEST AND A SRC CAN BE SAME	rdDest.left = min(rdSrc1.left, rdSrc2.left);	rdDest.top = min(rdSrc1.top, rdSrc2.top);	rdDest.right = max(rdSrc1.right, rdSrc2.right);	rdDest.bottom = max(rdSrc1.bottom, rdSrc2.bottom);}void Reflect(OUT RECT& rDest, IN const RECT& in_rSrc) {	RECT rSrc = in_rSrc;	rDest.left		= rSrc.top;	rDest.top		= rSrc.left;	rDest.right		= rSrc.bottom;	rDest.bottom	= rSrc.right;}void Reflect(OUT RECTD& rdDest, IN const RECTD& in_rdSrc) {	RECTD rdSrc = in_rdSrc;	rdDest.left		= rdSrc.top;	rdDest.top		= rdSrc.left;	rdDest.right	= rdSrc.bottom;	rdDest.bottom	= rdSrc.right;}void Reflect(OUT POINT& ptDest, IN const POINT& in_ptSrc) {	POINT ptSrc = in_ptSrc;	ptDest.x = ptSrc.y;	ptDest.y = ptSrc.x;}void Reflect(OUT POINTD& ptdDest, IN const POINTD& in_ptdSrc) {	POINTD ptdSrc = in_ptdSrc;	ptdDest.x = ptdSrc.y;	ptdDest.y = ptdSrc.x;}VOID RoundMult(OUT POINT& pt, IN const POINTD& pt1, IN const POINTD& pt2) {	pt.x = RoundToLong(pt1.x * pt2.x);	pt.y = RoundToLong(pt1.y * pt2.y);}VOID RoundMult(OUT RECT& rl, IN const RECTD& rd, IN const POINTD& ptd) {	rl.left = RoundToLong(rd.left * ptd.x);	rl.top = RoundToLong(rd.top * ptd.y);	rl.right = RoundToLong(rd.right * ptd.x);	rl.bottom = RoundToLong(rd.bottom * ptd.y);}LONG RoundUp(double d) {	LONG l = (LONG) d;	if (l < d) ++l;	return l;}

⌨️ 快捷键说明

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