📄 ipoints.h
字号:
/********************************************************************** * File: ipoints.h (Formerly icoords.h) * Description: Inline functions for coords.h. * Author: Ray Smith * Created: Fri Jun 21 15:14:21 BST 1991 * * (C) Copyright 1991, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. * **********************************************************************/#ifndef IPOINTS_H#define IPOINTS_H#include <math.h>/********************************************************************** * operator! * * Rotate an ICOORD 90 degrees anticlockwise. **********************************************************************/inline ICOORDoperator! ( //rotate 90 deg anticonst ICOORD & src //thing to rotate) { ICOORD result; //output result.xcoord = -src.ycoord; result.ycoord = src.xcoord; return result;}/********************************************************************** * operator- * * Unary minus of an ICOORD. **********************************************************************/inline ICOORDoperator- ( //unary minusconst ICOORD & src //thing to minus) { ICOORD result; //output result.xcoord = -src.xcoord; result.ycoord = -src.ycoord; return result;}/********************************************************************** * operator+ * * Add 2 ICOORDS. **********************************************************************/inline ICOORDoperator+ ( //sum vectorsconst ICOORD & op1, //operandsconst ICOORD & op2) { ICOORD sum; //result sum.xcoord = op1.xcoord + op2.xcoord; sum.ycoord = op1.ycoord + op2.ycoord; return sum;}/********************************************************************** * operator+= * * Add 2 ICOORDS. **********************************************************************/inline ICOORD &operator+= ( //sum vectorsICOORD & op1, //operandsconst ICOORD & op2) { op1.xcoord += op2.xcoord; op1.ycoord += op2.ycoord; return op1;}/********************************************************************** * operator- * * Subtract 2 ICOORDS. **********************************************************************/inline ICOORDoperator- ( //subtract vectorsconst ICOORD & op1, //operandsconst ICOORD & op2) { ICOORD sum; //result sum.xcoord = op1.xcoord - op2.xcoord; sum.ycoord = op1.ycoord - op2.ycoord; return sum;}/********************************************************************** * operator-= * * Subtract 2 ICOORDS. **********************************************************************/inline ICOORD &operator-= ( //sum vectorsICOORD & op1, //operandsconst ICOORD & op2) { op1.xcoord -= op2.xcoord; op1.ycoord -= op2.ycoord; return op1;}/********************************************************************** * operator% * * Scalar product of 2 ICOORDS. **********************************************************************/inline INT32operator% ( //scalar productconst ICOORD & op1, //operandsconst ICOORD & op2) { return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;}/********************************************************************** * operator* * * Cross product of 2 ICOORDS. **********************************************************************/inline INT32 operator *( //cross product const ICOORD &op1, //operands const ICOORD &op2) { return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;}/********************************************************************** * operator* * * Scalar multiply of an ICOORD. **********************************************************************/inline ICOORD operator *( //scalar multiply const ICOORD &op1, //operands INT16 scale) { ICOORD result; //output result.xcoord = op1.xcoord * scale; result.ycoord = op1.ycoord * scale; return result;}inline ICOORD operator *( //scalar multiply INT16 scale, const ICOORD &op1 //operands ) { ICOORD result; //output result.xcoord = op1.xcoord * scale; result.ycoord = op1.ycoord * scale; return result;}/********************************************************************** * operator*= * * Scalar multiply of an ICOORD. **********************************************************************/inline ICOORD &operator*= ( //scalar multiplyICOORD & op1, //operandsINT16 scale) { op1.xcoord *= scale; op1.ycoord *= scale; return op1;}/********************************************************************** * operator/ * * Scalar divide of an ICOORD. **********************************************************************/inline ICOORDoperator/ ( //scalar divideconst ICOORD & op1, //operandsINT16 scale) { ICOORD result; //output result.xcoord = op1.xcoord / scale; result.ycoord = op1.ycoord / scale; return result;}/********************************************************************** * operator/= * * Scalar divide of an ICOORD. **********************************************************************/inline ICOORD &operator/= ( //scalar divideICOORD & op1, //operandsINT16 scale) { op1.xcoord /= scale; op1.ycoord /= scale; return op1;}/********************************************************************** * ICOORD::rotate * * Rotate an ICOORD by the given (normalized) (cos,sin) vector. **********************************************************************/inline void ICOORD::rotate( //rotate by vector const FCOORD& vec) { INT16 tmp; tmp = (INT16) floor (xcoord * vec.x () - ycoord * vec.y () + 0.5); ycoord = (INT16) floor (ycoord * vec.x () + xcoord * vec.y () + 0.5); xcoord = tmp;}/********************************************************************** * operator! * * Rotate an FCOORD 90 degrees anticlockwise. **********************************************************************/inline FCOORDoperator! ( //rotate 90 deg anticonst FCOORD & src //thing to rotate) { FCOORD result; //output result.xcoord = -src.ycoord; result.ycoord = src.xcoord; return result;}/********************************************************************** * operator- * * Unary minus of an FCOORD. **********************************************************************/inline FCOORDoperator- ( //unary minusconst FCOORD & src //thing to minus) { FCOORD result; //output result.xcoord = -src.xcoord; result.ycoord = -src.ycoord; return result;}/********************************************************************** * operator+ * * Add 2 FCOORDS. **********************************************************************/inline FCOORDoperator+ ( //sum vectorsconst FCOORD & op1, //operandsconst FCOORD & op2) { FCOORD sum; //result sum.xcoord = op1.xcoord + op2.xcoord; sum.ycoord = op1.ycoord + op2.ycoord; return sum;}/********************************************************************** * operator+= * * Add 2 FCOORDS. **********************************************************************/inline FCOORD &operator+= ( //sum vectorsFCOORD & op1, //operandsconst FCOORD & op2) { op1.xcoord += op2.xcoord; op1.ycoord += op2.ycoord; return op1;}/********************************************************************** * operator- * * Subtract 2 FCOORDS. **********************************************************************/inline FCOORDoperator- ( //subtract vectorsconst FCOORD & op1, //operandsconst FCOORD & op2) { FCOORD sum; //result sum.xcoord = op1.xcoord - op2.xcoord; sum.ycoord = op1.ycoord - op2.ycoord; return sum;}/********************************************************************** * operator-= * * Subtract 2 FCOORDS. **********************************************************************/inline FCOORD &operator-= ( //sum vectorsFCOORD & op1, //operandsconst FCOORD & op2) { op1.xcoord -= op2.xcoord; op1.ycoord -= op2.ycoord; return op1;}/********************************************************************** * operator% * * Scalar product of 2 FCOORDS. **********************************************************************/inline floatoperator% ( //scalar productconst FCOORD & op1, //operandsconst FCOORD & op2) { return op1.xcoord * op2.xcoord + op1.ycoord * op2.ycoord;}/********************************************************************** * operator* * * Cross product of 2 FCOORDS. **********************************************************************/inline float operator *( //cross product const FCOORD &op1, //operands const FCOORD &op2) { return op1.xcoord * op2.ycoord - op1.ycoord * op2.xcoord;}/********************************************************************** * operator* * * Scalar multiply of an FCOORD. **********************************************************************/inline FCOORD operator *( //scalar multiply const FCOORD &op1, //operands float scale) { FCOORD result; //output result.xcoord = op1.xcoord * scale; result.ycoord = op1.ycoord * scale; return result;}inline FCOORD operator *( //scalar multiply float scale, const FCOORD &op1 //operands ) { FCOORD result; //output result.xcoord = op1.xcoord * scale; result.ycoord = op1.ycoord * scale; return result;}/********************************************************************** * operator*= * * Scalar multiply of an FCOORD. **********************************************************************/inline FCOORD &operator*= ( //scalar multiplyFCOORD & op1, //operandsfloat scale) { op1.xcoord *= scale; op1.ycoord *= scale; return op1;}/********************************************************************** * operator/ * * Scalar divide of an FCOORD. **********************************************************************/inline FCOORDoperator/ ( //scalar divideconst FCOORD & op1, //operandsfloat scale) { FCOORD result; //output if (scale != 0) { result.xcoord = op1.xcoord / scale; result.ycoord = op1.ycoord / scale; } return result;}/********************************************************************** * operator/= * * Scalar divide of an FCOORD. **********************************************************************/inline FCOORD &operator/= ( //scalar divideFCOORD & op1, //operandsfloat scale) { if (scale != 0) { op1.xcoord /= scale; op1.ycoord /= scale; } return op1;}/********************************************************************** * rotate * * Rotate an FCOORD by the given (normalized) (cos,sin) vector. **********************************************************************/inline void FCOORD::rotate( //rotate by vector const FCOORD vec) { float tmp; tmp = xcoord * vec.x () - ycoord * vec.y (); ycoord = ycoord * vec.x () + xcoord * vec.y (); xcoord = tmp;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -