From a683a420a9e43705c972b5e74d55e319729e1a81 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 Jul 2010 19:53:02 +0000 Subject: SWORD25: Importing original sources svn-id: r53171 --- engines/sword25/math/line.h | 206 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100755 engines/sword25/math/line.h (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h new file mode 100755 index 0000000000..aaae3a0764 --- /dev/null +++ b/engines/sword25/math/line.h @@ -0,0 +1,206 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 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. +// +// Broken Sword 2.5 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 Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +/* + BS_Line + ------- + Diese Klasse enthält nur statische Methoden, die mit Geradensegmenten zu tun haben. + Es gibt keine wirkliche Geradensegment-Klasse, da diese Klasse vor allem zu + Berechnungen mit Polygonen herangezogen wird und es dabei wichtig ist, Start- und + Endpunkte der Linien dynamisch wählen zu können. Dieses würde sich verbieten, wenn + ein Polygon aus einer Menge von festen Geradensegmenten gebildet wäre. + + Autor: Malte Thiesen +*/ + +#ifndef _BS_LINE_H_ +#define _BS_LINE_H_ + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" + +// ----------------------------------------------------------------------------- + +class BS_Line +{ +public: + /** + @brief Bestimmt ob sich ein Punkt links von einer Linie befindet. + @param a der Startpunkt der Linie + @param b der Endpunkt der Linie + @param c der Testpunkt + @return Gibt true zurück, wenn sich der Punkt links von der Linie befindet.
+ Falls sich der Punkt rechts von der Linie oder auf der Linie befindet wird false zurückgegeben.
+ @remark Ein Punkt liegt links von einer Linie, wenn er vom Startpunkt aus betrachtet links neben der Linie liegt. + */ + static bool IsVertexLeft(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + return _TriangleArea2(a, b, c) > 0; + } + + static bool IsVertexLeftOn(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + return _TriangleArea2(a, b, c) >= 0; + } + + /** + @brief Bestimmt ob sich ein Punkt rechts von einer Linie befindet. + @param a der Startpunkt der Linie + @param b der Endpunkt der Linie + @param c der Testpunkt + @return Gibt true zurück, wenn sich der Punkt recht von der Linie befindet.
+ Falls sich der Punkt links von der Linie oder auf der Linie befindet wird false zurückgegeben.
+ @remark Ein Punkt liegt rechts von einer Linie, wenn er vom Startpunkt aus betrachtet rechts neben der Linie liegt. + */ + static bool IsVertexRight(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + return _TriangleArea2(a, b, c) < 0; + } + + static bool IsVertexRightOn(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + return _TriangleArea2(a, b, c) <= 0; + } + + /** + @brief Bestimmt ob sich ein Punkt auf einer Linie befindet. + @param a der Startpunkt der Linie + @param b der Endpunkt der Linie + @param c der Testpunkt + @return Gibt true zurück, wenn sich der Punkt auf der Linie befindet. + */ + static bool IsVertexOn(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + return _TriangleArea2(a, b, c) == 0; + } + + enum VERTEX_CLASSIFICATION + { + LEFT, + RIGHT, + ON, + }; + + /** + @brief Bestimmt wo sich ein Punkt relativ zu einer Linie befindet. + @param a der Startpunkt der Linie + @param b der Endpunkt der Linie + @param c der Testpunkt + @return Gibt LEFT zurück, wenn sich der Punkt links von der Line befindet.
+ Gibt RIGHT zurück, wenn sich der Punkt links von der Line befindet.
+ Gibt ON zurück, wenn sich der Punkt auf der Linie befindet. + */ + static VERTEX_CLASSIFICATION ClassifyVertexToLine(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + int Area = _TriangleArea2(a, b, c); + if (Area > 0) return LEFT; + if (Area < 0) return RIGHT; + return ON; + } + + /** + @brief Bestimmt ob sich zwei Linien schneiden. + @param a der Startpunkt der ersten Linie + @param b der Endpunkt der ersten Linie + @param c der Startpunkt der zweiten Linie + @param d der Endpunkt der zweiten Linie + @remark In den Fällen in denen eine Linie die andere nur berührt, wird false zurückgegeben (improper intersection). + */ + static bool DoesIntersectProperly(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c, const BS_Vertex & d) + { + VERTEX_CLASSIFICATION Class1 = ClassifyVertexToLine(a, b, c); + VERTEX_CLASSIFICATION Class2 = ClassifyVertexToLine(a, b, d); + VERTEX_CLASSIFICATION Class3 = ClassifyVertexToLine(c, d, a); + VERTEX_CLASSIFICATION Class4 = ClassifyVertexToLine(c, d, b); + + if (Class1 == ON || Class2 == ON || Class3 == ON || Class4 == ON) return false; + + return ((Class1 == LEFT) ^ (Class2 == LEFT)) && ((Class3 == LEFT) ^ (Class4 == LEFT)); + } + + /** + @brief Bestimmt ob sich ein Punkt auf einem Liniensegment befindet + @param a der Startpunkt der Liniensegmentes + @param b der Endpunkt der Liniensegmentes + @param c der Testpunkt + */ + static bool IsOnLine(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + // Die Punkte müssen alle Kollinear sein, sonst liegt der Testpunkt nicht auf dem Liniensegment + if (_TriangleArea2(a, b, c) != 0) return false; + + // Falls das Liniensegment nicht vertikal ist prüfe auf der X-Achse, ansonsten auf der Y-Achse + if (a.X != b.X) + { + return ((a.X <= c.X) && + (c.X <= b.X)) || + ((a.X >= c.X) && + (c.X >= b.X)); + } + else + { + return ((a.Y <= c.Y) && + (c.Y <= b.Y)) || + ((a.Y >= c.Y) && + (c.Y >= b.Y)); + } + } + + static bool IsOnLineStrict(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + // Die Punkte müssen alle Kollinear sein, sonst liegt der Testpunkt nicht auf dem Liniensegment + if (_TriangleArea2(a, b, c) != 0) return false; + + // Falls das Liniensegment nicht vertikal ist prüfe auf der X-Achse, ansonsten auf der Y-Achse + if (a.X != b.X) + { + return ((a.X < c.X) && + (c.X < b.X)) || + ((a.X > c.X) && + (c.X > b.X)); + } + else + { + return ((a.Y < c.Y) && + (c.Y < b.Y)) || + ((a.Y > c.Y) && + (c.Y > b.Y)); + } + } + +private: + + /** + @brief Gibt die doppelte Größe des durch a, b und c definierten Dreiecks zurück. + + Das Ergebnis ist positiv wenn die Punkte entgegen dem Uhrzeigersinn angeordnet sind und negativ wenn sie mit dem + Uhrzeigersinn angeordnet sind. + */ + static int _TriangleArea2(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) + { + return a.X * b.Y - a.Y * b.X + + a.Y * c.X - a.X * c.Y + + b.X * c.Y - c.X * b.Y; + } +}; + +#endif -- cgit v1.2.3 From 65da804f583460739aec3bfe35b70310af1ee5a9 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 Jul 2010 19:55:28 +0000 Subject: SWORD25: Path fixes for includes svn-id: r53180 --- engines/sword25/math/line.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h index aaae3a0764..7307efd380 100755 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -29,14 +29,14 @@ Autor: Malte Thiesen */ -#ifndef _BS_LINE_H_ -#define _BS_LINE_H_ +#ifndef SWORD25_LINE_H +#define SWORD25_LINE_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" +#include "sword25/kernel/common.h" // ----------------------------------------------------------------------------- -- cgit v1.2.3 From 69b618a8f5517c609a5e94d9609dc27aea2ad573 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 30 Jul 2010 12:19:13 +0000 Subject: SWORD25: Compilation fixes Majority of files now compile under Windoze. svn-id: r53182 --- engines/sword25/math/line.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h index 7307efd380..7da4a94db7 100755 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -97,7 +97,7 @@ public: { LEFT, RIGHT, - ON, + ON }; /** -- cgit v1.2.3 From 293bf95c01f76c8d812a300eb038854f1246ab3d Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 31 Jul 2010 09:53:02 +0000 Subject: SWORD25: Replacing headers with ScummVM ones plus original (C) svn-id: r53188 --- engines/sword25/math/line.h | 51 +++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) mode change 100755 => 100644 engines/sword25/math/line.h (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h old mode 100755 new mode 100644 index 7da4a94db7..3dd178adb5 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 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. -// -// Broken Sword 2.5 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 Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ /* BS_Line -- cgit v1.2.3 From 53a9d2d0a1dab1119dc1cc12886321fa72743061 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 1 Aug 2010 08:31:50 +0000 Subject: SWORD25: Converted the math folder files svn-id: r53197 --- engines/sword25/math/line.h | 165 ++++++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 91 deletions(-) (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h index 3dd178adb5..86bcbd6537 100644 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -35,11 +35,11 @@ /* BS_Line ------- - Diese Klasse enthält nur statische Methoden, die mit Geradensegmenten zu tun haben. - Es gibt keine wirkliche Geradensegment-Klasse, da diese Klasse vor allem zu - Berechnungen mit Polygonen herangezogen wird und es dabei wichtig ist, Start- und - Endpunkte der Linien dynamisch wählen zu können. Dieses würde sich verbieten, wenn - ein Polygon aus einer Menge von festen Geradensegmenten gebildet wäre. + This class contains only static methods, which have to do with straight line + segments. There is no real straight line segment class. Calculations will be + used with polygons, and it is important the process of starting and selecting + endpoints of lines is dynamic. This would prhobit a polygon from a set + being formed by fixed line segments Autor: Malte Thiesen */ @@ -55,77 +55,69 @@ // ----------------------------------------------------------------------------- -class BS_Line -{ +namespace Sword25 { + +class BS_Line { public: /** - @brief Bestimmt ob sich ein Punkt links von einer Linie befindet. - @param a der Startpunkt der Linie - @param b der Endpunkt der Linie - @param c der Testpunkt - @return Gibt true zurück, wenn sich der Punkt links von der Linie befindet.
- Falls sich der Punkt rechts von der Linie oder auf der Linie befindet wird false zurückgegeben.
- @remark Ein Punkt liegt links von einer Linie, wenn er vom Startpunkt aus betrachtet links neben der Linie liegt. - */ - static bool IsVertexLeft(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + * Determines whether a piont is left of a line + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return Returns true if the point is to the left of the line. + * If the point is to the right of the line or on the line, false is returned. + */ + static bool IsVertexLeft(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return _TriangleArea2(a, b, c) > 0; } - static bool IsVertexLeftOn(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + static bool IsVertexLeftOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return _TriangleArea2(a, b, c) >= 0; } /** - @brief Bestimmt ob sich ein Punkt rechts von einer Linie befindet. - @param a der Startpunkt der Linie - @param b der Endpunkt der Linie - @param c der Testpunkt - @return Gibt true zurück, wenn sich der Punkt recht von der Linie befindet.
- Falls sich der Punkt links von der Linie oder auf der Linie befindet wird false zurückgegeben.
- @remark Ein Punkt liegt rechts von einer Linie, wenn er vom Startpunkt aus betrachtet rechts neben der Linie liegt. - */ - static bool IsVertexRight(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + * Determines whether a piont is right of a line + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return Returns true if the point is to the right of the line. + * If the point is to the right of the line or on the line, false is returned. + */ + static bool IsVertexRight(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return _TriangleArea2(a, b, c) < 0; } - static bool IsVertexRightOn(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + static bool IsVertexRightOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return _TriangleArea2(a, b, c) <= 0; } /** - @brief Bestimmt ob sich ein Punkt auf einer Linie befindet. - @param a der Startpunkt der Linie - @param b der Endpunkt der Linie - @param c der Testpunkt - @return Gibt true zurück, wenn sich der Punkt auf der Linie befindet. - */ - static bool IsVertexOn(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + * Determines whether a piont is on a line + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return Returns true if the point is on the line, false otherwise. + */ + static bool IsVertexOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return _TriangleArea2(a, b, c) == 0; } - enum VERTEX_CLASSIFICATION - { + enum VERTEX_CLASSIFICATION { LEFT, RIGHT, ON }; /** - @brief Bestimmt wo sich ein Punkt relativ zu einer Linie befindet. - @param a der Startpunkt der Linie - @param b der Endpunkt der Linie - @param c der Testpunkt - @return Gibt LEFT zurück, wenn sich der Punkt links von der Line befindet.
- Gibt RIGHT zurück, wenn sich der Punkt links von der Line befindet.
- Gibt ON zurück, wenn sich der Punkt auf der Linie befindet. - */ - static VERTEX_CLASSIFICATION ClassifyVertexToLine(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + * Determines where a point is relative to a line. + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return LEFT is returned if the point is to the left of the line. + * RIGHT is returned if the point is to the right of the line. + * ON is returned if the point is on the line. + */ + static VERTEX_CLASSIFICATION ClassifyVertexToLine(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { int Area = _TriangleArea2(a, b, c); if (Area > 0) return LEFT; if (Area < 0) return RIGHT; @@ -133,15 +125,14 @@ public: } /** - @brief Bestimmt ob sich zwei Linien schneiden. - @param a der Startpunkt der ersten Linie - @param b der Endpunkt der ersten Linie - @param c der Startpunkt der zweiten Linie - @param d der Endpunkt der zweiten Linie - @remark In den Fällen in denen eine Linie die andere nur berührt, wird false zurückgegeben (improper intersection). - */ - static bool DoesIntersectProperly(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c, const BS_Vertex & d) - { + * Determines whether two lines intersect + * @param a The start point of the first line + * @param b The end point of the first line + * @param c The start point of the second line + * @param d The end point of the second line + * @remark In cases where a line only touches the other, false is returned (improper intersection) + */ + static bool DoesIntersectProperly(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c, const BS_Vertex &d) { VERTEX_CLASSIFICATION Class1 = ClassifyVertexToLine(a, b, c); VERTEX_CLASSIFICATION Class2 = ClassifyVertexToLine(a, b, d); VERTEX_CLASSIFICATION Class3 = ClassifyVertexToLine(c, d, a); @@ -153,26 +144,22 @@ public: } /** - @brief Bestimmt ob sich ein Punkt auf einem Liniensegment befindet - @param a der Startpunkt der Liniensegmentes - @param b der Endpunkt der Liniensegmentes - @param c der Testpunkt - */ - static bool IsOnLine(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { - // Die Punkte müssen alle Kollinear sein, sonst liegt der Testpunkt nicht auf dem Liniensegment + * Determines whether a point is on a line segment + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + */ + static bool IsOnLine(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + // The items must all be Collinear, otherwise don't bothering testing the point if (_TriangleArea2(a, b, c) != 0) return false; - // Falls das Liniensegment nicht vertikal ist prüfe auf der X-Achse, ansonsten auf der Y-Achse - if (a.X != b.X) - { + // If the line segment is not vertical, check on the x-axis, otherwise the y-axis + if (a.X != b.X) { return ((a.X <= c.X) && (c.X <= b.X)) || ((a.X >= c.X) && (c.X >= b.X)); - } - else - { + } else { return ((a.Y <= c.Y) && (c.Y <= b.Y)) || ((a.Y >= c.Y) && @@ -180,21 +167,17 @@ public: } } - static bool IsOnLineStrict(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { - // Die Punkte müssen alle Kollinear sein, sonst liegt der Testpunkt nicht auf dem Liniensegment + static bool IsOnLineStrict(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + // The items must all be Collinear, otherwise don't bothering testing the point if (_TriangleArea2(a, b, c) != 0) return false; - // Falls das Liniensegment nicht vertikal ist prüfe auf der X-Achse, ansonsten auf der Y-Achse - if (a.X != b.X) - { + // If the line segment is not vertical, check on the x-axis, otherwise the y-axis + if (a.X != b.X) { return ((a.X < c.X) && (c.X < b.X)) || ((a.X > c.X) && (c.X > b.X)); - } - else - { + } else { return ((a.Y < c.Y) && (c.Y < b.Y)) || ((a.Y > c.Y) && @@ -203,19 +186,19 @@ public: } private: - /** - @brief Gibt die doppelte Größe des durch a, b und c definierten Dreiecks zurück. - - Das Ergebnis ist positiv wenn die Punkte entgegen dem Uhrzeigersinn angeordnet sind und negativ wenn sie mit dem - Uhrzeigersinn angeordnet sind. - */ - static int _TriangleArea2(const BS_Vertex & a, const BS_Vertex & b, const BS_Vertex & c) - { + * Return double the size of the triangle defined by the three passed points. + * + * The result is positive if the points are arrange counterclockwise, + * and negative if they are arranged counter-clockwise. + */ + static int _TriangleArea2(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return a.X * b.Y - a.Y * b.X + a.Y * c.X - a.X * c.Y + b.X * c.Y - c.X * b.Y; } }; +} // End of namespace Sword25 + #endif -- cgit v1.2.3 From 47904bc7b2992189bb554833f00a79ff0fea9fb8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 6 Aug 2010 13:13:25 +0000 Subject: SWORD25: Mass-astyle. svn-id: r53222 --- engines/sword25/math/line.h | 100 ++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h index 86bcbd6537..5e442045f1 100644 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -33,15 +33,15 @@ */ /* - BS_Line - ------- - This class contains only static methods, which have to do with straight line - segments. There is no real straight line segment class. Calculations will be - used with polygons, and it is important the process of starting and selecting - endpoints of lines is dynamic. This would prhobit a polygon from a set - being formed by fixed line segments - - Autor: Malte Thiesen + BS_Line + ------- + This class contains only static methods, which have to do with straight line + segments. There is no real straight line segment class. Calculations will be + used with polygons, and it is important the process of starting and selecting + endpoints of lines is dynamic. This would prhobit a polygon from a set + being formed by fixed line segments + + Autor: Malte Thiesen */ #ifndef SWORD25_LINE_H @@ -61,10 +61,10 @@ class BS_Line { public: /** * Determines whether a piont is left of a line - * @param a The start point of a line - * @param b The end point of a line - * @param c The test point - * @return Returns true if the point is to the left of the line. + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return Returns true if the point is to the left of the line. * If the point is to the right of the line or on the line, false is returned. */ static bool IsVertexLeft(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { @@ -77,10 +77,10 @@ public: /** * Determines whether a piont is right of a line - * @param a The start point of a line - * @param b The end point of a line - * @param c The test point - * @return Returns true if the point is to the right of the line. + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return Returns true if the point is to the right of the line. * If the point is to the right of the line or on the line, false is returned. */ static bool IsVertexRight(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { @@ -93,10 +93,10 @@ public: /** * Determines whether a piont is on a line - * @param a The start point of a line - * @param b The end point of a line - * @param c The test point - * @return Returns true if the point is on the line, false otherwise. + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return Returns true if the point is on the line, false otherwise. */ static bool IsVertexOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return _TriangleArea2(a, b, c) == 0; @@ -110,10 +110,10 @@ public: /** * Determines where a point is relative to a line. - * @param a The start point of a line - * @param b The end point of a line - * @param c The test point - * @return LEFT is returned if the point is to the left of the line. + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point + * @return LEFT is returned if the point is to the left of the line. * RIGHT is returned if the point is to the right of the line. * ON is returned if the point is on the line. */ @@ -126,11 +126,11 @@ public: /** * Determines whether two lines intersect - * @param a The start point of the first line - * @param b The end point of the first line - * @param c The start point of the second line - * @param d The end point of the second line - * @remark In cases where a line only touches the other, false is returned (improper intersection) + * @param a The start point of the first line + * @param b The end point of the first line + * @param c The start point of the second line + * @param d The end point of the second line + * @remark In cases where a line only touches the other, false is returned (improper intersection) */ static bool DoesIntersectProperly(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c, const BS_Vertex &d) { VERTEX_CLASSIFICATION Class1 = ClassifyVertexToLine(a, b, c); @@ -140,14 +140,14 @@ public: if (Class1 == ON || Class2 == ON || Class3 == ON || Class4 == ON) return false; - return ((Class1 == LEFT) ^ (Class2 == LEFT)) && ((Class3 == LEFT) ^ (Class4 == LEFT)); + return ((Class1 == LEFT) ^(Class2 == LEFT)) && ((Class3 == LEFT) ^(Class4 == LEFT)); } /** * Determines whether a point is on a line segment - * @param a The start point of a line - * @param b The end point of a line - * @param c The test point + * @param a The start point of a line + * @param b The end point of a line + * @param c The test point */ static bool IsOnLine(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { // The items must all be Collinear, otherwise don't bothering testing the point @@ -156,14 +156,14 @@ public: // If the line segment is not vertical, check on the x-axis, otherwise the y-axis if (a.X != b.X) { return ((a.X <= c.X) && - (c.X <= b.X)) || - ((a.X >= c.X) && - (c.X >= b.X)); + (c.X <= b.X)) || + ((a.X >= c.X) && + (c.X >= b.X)); } else { return ((a.Y <= c.Y) && - (c.Y <= b.Y)) || - ((a.Y >= c.Y) && - (c.Y >= b.Y)); + (c.Y <= b.Y)) || + ((a.Y >= c.Y) && + (c.Y >= b.Y)); } } @@ -174,14 +174,14 @@ public: // If the line segment is not vertical, check on the x-axis, otherwise the y-axis if (a.X != b.X) { return ((a.X < c.X) && - (c.X < b.X)) || - ((a.X > c.X) && - (c.X > b.X)); + (c.X < b.X)) || + ((a.X > c.X) && + (c.X > b.X)); } else { return ((a.Y < c.Y) && - (c.Y < b.Y)) || - ((a.Y > c.Y) && - (c.Y > b.Y)); + (c.Y < b.Y)) || + ((a.Y > c.Y) && + (c.Y > b.Y)); } } @@ -189,13 +189,13 @@ private: /** * Return double the size of the triangle defined by the three passed points. * - * The result is positive if the points are arrange counterclockwise, + * The result is positive if the points are arrange counterclockwise, * and negative if they are arranged counter-clockwise. */ static int _TriangleArea2(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { return a.X * b.Y - a.Y * b.X + - a.Y * c.X - a.X * c.Y + - b.X * c.Y - c.X * b.Y; + a.Y * c.X - a.X * c.Y + + b.X * c.Y - c.X * b.Y; } }; -- cgit v1.2.3 From be44216e5c1d74879d7843215ce1cd3f488b4db8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 18 Aug 2010 12:57:47 +0000 Subject: SWORD25: eliminated BS_ prefix in all but kernel/ svn-id: r53259 --- engines/sword25/math/line.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h index 5e442045f1..f2f0607251 100644 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -57,7 +57,7 @@ namespace Sword25 { -class BS_Line { +class Line { public: /** * Determines whether a piont is left of a line @@ -67,11 +67,11 @@ public: * @return Returns true if the point is to the left of the line. * If the point is to the right of the line or on the line, false is returned. */ - static bool IsVertexLeft(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsVertexLeft(const Vertex &a, const Vertex &b, const Vertex &c) { return _TriangleArea2(a, b, c) > 0; } - static bool IsVertexLeftOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsVertexLeftOn(const Vertex &a, const Vertex &b, const Vertex &c) { return _TriangleArea2(a, b, c) >= 0; } @@ -83,11 +83,11 @@ public: * @return Returns true if the point is to the right of the line. * If the point is to the right of the line or on the line, false is returned. */ - static bool IsVertexRight(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsVertexRight(const Vertex &a, const Vertex &b, const Vertex &c) { return _TriangleArea2(a, b, c) < 0; } - static bool IsVertexRightOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsVertexRightOn(const Vertex &a, const Vertex &b, const Vertex &c) { return _TriangleArea2(a, b, c) <= 0; } @@ -98,7 +98,7 @@ public: * @param c The test point * @return Returns true if the point is on the line, false otherwise. */ - static bool IsVertexOn(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsVertexOn(const Vertex &a, const Vertex &b, const Vertex &c) { return _TriangleArea2(a, b, c) == 0; } @@ -117,7 +117,7 @@ public: * RIGHT is returned if the point is to the right of the line. * ON is returned if the point is on the line. */ - static VERTEX_CLASSIFICATION ClassifyVertexToLine(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static VERTEX_CLASSIFICATION ClassifyVertexToLine(const Vertex &a, const Vertex &b, const Vertex &c) { int Area = _TriangleArea2(a, b, c); if (Area > 0) return LEFT; if (Area < 0) return RIGHT; @@ -132,7 +132,7 @@ public: * @param d The end point of the second line * @remark In cases where a line only touches the other, false is returned (improper intersection) */ - static bool DoesIntersectProperly(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c, const BS_Vertex &d) { + static bool DoesIntersectProperly(const Vertex &a, const Vertex &b, const Vertex &c, const Vertex &d) { VERTEX_CLASSIFICATION Class1 = ClassifyVertexToLine(a, b, c); VERTEX_CLASSIFICATION Class2 = ClassifyVertexToLine(a, b, d); VERTEX_CLASSIFICATION Class3 = ClassifyVertexToLine(c, d, a); @@ -149,7 +149,7 @@ public: * @param b The end point of a line * @param c The test point */ - static bool IsOnLine(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsOnLine(const Vertex &a, const Vertex &b, const Vertex &c) { // The items must all be Collinear, otherwise don't bothering testing the point if (_TriangleArea2(a, b, c) != 0) return false; @@ -167,7 +167,7 @@ public: } } - static bool IsOnLineStrict(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static bool IsOnLineStrict(const Vertex &a, const Vertex &b, const Vertex &c) { // The items must all be Collinear, otherwise don't bothering testing the point if (_TriangleArea2(a, b, c) != 0) return false; @@ -192,7 +192,7 @@ private: * The result is positive if the points are arrange counterclockwise, * and negative if they are arranged counter-clockwise. */ - static int _TriangleArea2(const BS_Vertex &a, const BS_Vertex &b, const BS_Vertex &c) { + static int _TriangleArea2(const Vertex &a, const Vertex &b, const Vertex &c) { return a.X * b.Y - a.Y * b.X + a.Y * c.X - a.X * c.Y + b.X * c.Y - c.X * b.Y; -- cgit v1.2.3 From 063cb5d84ca5846ac0eff9388759a9b6662e764f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 3 Oct 2010 13:25:36 +0000 Subject: SWORD25: Enforced code naming conventions in math/* svn-id: r53392 --- engines/sword25/math/line.h | 100 +++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 53 deletions(-) (limited to 'engines/sword25/math/line.h') diff --git a/engines/sword25/math/line.h b/engines/sword25/math/line.h index f2f0607251..d57fce68f7 100644 --- a/engines/sword25/math/line.h +++ b/engines/sword25/math/line.h @@ -47,14 +47,8 @@ #ifndef SWORD25_LINE_H #define SWORD25_LINE_H -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "sword25/kernel/common.h" -// ----------------------------------------------------------------------------- - namespace Sword25 { class Line { @@ -67,12 +61,12 @@ public: * @return Returns true if the point is to the left of the line. * If the point is to the right of the line or on the line, false is returned. */ - static bool IsVertexLeft(const Vertex &a, const Vertex &b, const Vertex &c) { - return _TriangleArea2(a, b, c) > 0; + static bool isVertexLeft(const Vertex &a, const Vertex &b, const Vertex &c) { + return triangleArea2(a, b, c) > 0; } - static bool IsVertexLeftOn(const Vertex &a, const Vertex &b, const Vertex &c) { - return _TriangleArea2(a, b, c) >= 0; + static bool isVertexLeftOn(const Vertex &a, const Vertex &b, const Vertex &c) { + return triangleArea2(a, b, c) >= 0; } /** @@ -83,12 +77,12 @@ public: * @return Returns true if the point is to the right of the line. * If the point is to the right of the line or on the line, false is returned. */ - static bool IsVertexRight(const Vertex &a, const Vertex &b, const Vertex &c) { - return _TriangleArea2(a, b, c) < 0; + static bool isVertexRight(const Vertex &a, const Vertex &b, const Vertex &c) { + return triangleArea2(a, b, c) < 0; } - static bool IsVertexRightOn(const Vertex &a, const Vertex &b, const Vertex &c) { - return _TriangleArea2(a, b, c) <= 0; + static bool isVertexRightOn(const Vertex &a, const Vertex &b, const Vertex &c) { + return triangleArea2(a, b, c) <= 0; } /** @@ -98,8 +92,8 @@ public: * @param c The test point * @return Returns true if the point is on the line, false otherwise. */ - static bool IsVertexOn(const Vertex &a, const Vertex &b, const Vertex &c) { - return _TriangleArea2(a, b, c) == 0; + static bool isVertexOn(const Vertex &a, const Vertex &b, const Vertex &c) { + return triangleArea2(a, b, c) == 0; } enum VERTEX_CLASSIFICATION { @@ -117,10 +111,10 @@ public: * RIGHT is returned if the point is to the right of the line. * ON is returned if the point is on the line. */ - static VERTEX_CLASSIFICATION ClassifyVertexToLine(const Vertex &a, const Vertex &b, const Vertex &c) { - int Area = _TriangleArea2(a, b, c); - if (Area > 0) return LEFT; - if (Area < 0) return RIGHT; + static VERTEX_CLASSIFICATION classifyVertexToLine(const Vertex &a, const Vertex &b, const Vertex &c) { + int area = triangleArea2(a, b, c); + if (area > 0) return LEFT; + if (area < 0) return RIGHT; return ON; } @@ -132,15 +126,15 @@ public: * @param d The end point of the second line * @remark In cases where a line only touches the other, false is returned (improper intersection) */ - static bool DoesIntersectProperly(const Vertex &a, const Vertex &b, const Vertex &c, const Vertex &d) { - VERTEX_CLASSIFICATION Class1 = ClassifyVertexToLine(a, b, c); - VERTEX_CLASSIFICATION Class2 = ClassifyVertexToLine(a, b, d); - VERTEX_CLASSIFICATION Class3 = ClassifyVertexToLine(c, d, a); - VERTEX_CLASSIFICATION Class4 = ClassifyVertexToLine(c, d, b); + static bool doesIntersectProperly(const Vertex &a, const Vertex &b, const Vertex &c, const Vertex &d) { + VERTEX_CLASSIFICATION class1 = classifyVertexToLine(a, b, c); + VERTEX_CLASSIFICATION class2 = classifyVertexToLine(a, b, d); + VERTEX_CLASSIFICATION class3 = classifyVertexToLine(c, d, a); + VERTEX_CLASSIFICATION class4 = classifyVertexToLine(c, d, b); - if (Class1 == ON || Class2 == ON || Class3 == ON || Class4 == ON) return false; + if (class1 == ON || class2 == ON || class3 == ON || class4 == ON) return false; - return ((Class1 == LEFT) ^(Class2 == LEFT)) && ((Class3 == LEFT) ^(Class4 == LEFT)); + return ((class1 == LEFT) ^(class2 == LEFT)) && ((class3 == LEFT) ^(class4 == LEFT)); } /** @@ -149,39 +143,39 @@ public: * @param b The end point of a line * @param c The test point */ - static bool IsOnLine(const Vertex &a, const Vertex &b, const Vertex &c) { + static bool isOnLine(const Vertex &a, const Vertex &b, const Vertex &c) { // The items must all be Collinear, otherwise don't bothering testing the point - if (_TriangleArea2(a, b, c) != 0) return false; + if (triangleArea2(a, b, c) != 0) return false; // If the line segment is not vertical, check on the x-axis, otherwise the y-axis - if (a.X != b.X) { - return ((a.X <= c.X) && - (c.X <= b.X)) || - ((a.X >= c.X) && - (c.X >= b.X)); + if (a.x != b.x) { + return ((a.x <= c.x) && + (c.x <= b.x)) || + ((a.x >= c.x) && + (c.x >= b.x)); } else { - return ((a.Y <= c.Y) && - (c.Y <= b.Y)) || - ((a.Y >= c.Y) && - (c.Y >= b.Y)); + return ((a.y <= c.y) && + (c.y <= b.y)) || + ((a.y >= c.y) && + (c.y >= b.y)); } } - static bool IsOnLineStrict(const Vertex &a, const Vertex &b, const Vertex &c) { + static bool isOnLineStrict(const Vertex &a, const Vertex &b, const Vertex &c) { // The items must all be Collinear, otherwise don't bothering testing the point - if (_TriangleArea2(a, b, c) != 0) return false; + if (triangleArea2(a, b, c) != 0) return false; // If the line segment is not vertical, check on the x-axis, otherwise the y-axis - if (a.X != b.X) { - return ((a.X < c.X) && - (c.X < b.X)) || - ((a.X > c.X) && - (c.X > b.X)); + if (a.x != b.x) { + return ((a.x < c.x) && + (c.x < b.x)) || + ((a.x > c.x) && + (c.x > b.x)); } else { - return ((a.Y < c.Y) && - (c.Y < b.Y)) || - ((a.Y > c.Y) && - (c.Y > b.Y)); + return ((a.y < c.y) && + (c.y < b.y)) || + ((a.y > c.y) && + (c.y > b.y)); } } @@ -192,10 +186,10 @@ private: * The result is positive if the points are arrange counterclockwise, * and negative if they are arranged counter-clockwise. */ - static int _TriangleArea2(const Vertex &a, const Vertex &b, const Vertex &c) { - return a.X * b.Y - a.Y * b.X + - a.Y * c.X - a.X * c.Y + - b.X * c.Y - c.X * b.Y; + static int triangleArea2(const Vertex &a, const Vertex &b, const Vertex &c) { + return a.x * b.y - a.y * b.x + + a.y * c.x - a.x * c.y + + b.x * c.y - c.x * b.y; } }; -- cgit v1.2.3