summaryrefslogtreecommitdiffhomepage
path: root/third-party/Opcode/Ice/IceSegment.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-03-12 22:07:03 +0100
committerAki <please@ignore.pl>2024-03-12 22:07:36 +0100
commit81bb6873f1c0291fecbf6e429ad15ac3db66a4c0 (patch)
treefd7552ecabeeffb45a1fbe3730ab62bc7a64dd85 /third-party/Opcode/Ice/IceSegment.cpp
parentf43d32d6d2cc7ecd04f4f06f20d5a6fc2c87c9ae (diff)
downloadstarshatter-81bb6873f1c0291fecbf6e429ad15ac3db66a4c0.zip
starshatter-81bb6873f1c0291fecbf6e429ad15ac3db66a4c0.tar.gz
starshatter-81bb6873f1c0291fecbf6e429ad15ac3db66a4c0.tar.bz2
Legal notices updated
Rename contrib -> third-party intendes to express the origin and purpose of that part of the code better. I plan to readd contrib/ again but with more in-project things like bash-completions, dev workflow scripts etc.
Diffstat (limited to 'third-party/Opcode/Ice/IceSegment.cpp')
-rw-r--r--third-party/Opcode/Ice/IceSegment.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/third-party/Opcode/Ice/IceSegment.cpp b/third-party/Opcode/Ice/IceSegment.cpp
new file mode 100644
index 0000000..b45d04b
--- /dev/null
+++ b/third-party/Opcode/Ice/IceSegment.cpp
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Contains code for segments.
+ * \file IceSegment.cpp
+ * \author Pierre Terdiman
+ * \date April, 4, 2000
+ */
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * IceSegment class.
+ * A segment is defined by S(t) = mP0 * (1 - t) + mP1 * t, with 0 <= t <= 1
+ * Alternatively, a segment is S(t) = Origin + t * Direction for 0 <= t <= 1.
+ * Direction is not necessarily unit length. The end points are Origin = mP0 and Origin + Direction = mP1.
+ *
+ * \class IceSegment
+ * \author Pierre Terdiman
+ * \version 1.0
+ */
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Precompiled Header
+#include "StdAfx.h"
+
+using namespace IceMaths;
+
+float IceSegment::SquareDistance(const IcePoint& Point, float* t) const
+{
+ IcePoint Diff = Point - mP0;
+ IcePoint Dir = mP1 - mP0;
+ float fT = Diff | Dir;
+
+ if(fT<=0.0f)
+ {
+ fT = 0.0f;
+ }
+ else
+ {
+ float SqrLen= Dir.SquareMagnitude();
+ if(fT>=SqrLen)
+ {
+ fT = 1.0f;
+ Diff -= Dir;
+ }
+ else
+ {
+ fT /= SqrLen;
+ Diff -= fT*Dir;
+ }
+ }
+
+ if(t) *t = fT;
+
+ return Diff.SquareMagnitude();
+}