#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library 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 IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GEOMETRY_LINES_SEGMENT3_H #define NUCLEX_GEOMETRY_LINES_SEGMENT3_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Point3.h" #include "Nuclex/Geometry/Vector3.h" #include #include namespace Nuclex { namespace Geometry { namespace Lines { // ------------------------------------------------------------------------------------------- // /// 3D line segment defined by a start and an end point template struct Segment3 { /// Initializes a line segment using the specified coordinates /// Position at which the line segment begins /// Position at which the line segment ends public: Segment3(const Point3 &start, const Point3 &end) : Start(start), End(end) {} /// Returns the squared length of the line segment /// The squared length of the line segment public: TScalar GetSquaredLength() const { TScalar distanceX = this->End.X - this->Start.X; TScalar distanceY = this->End.Y - this->Start.Y; TScalar distanceZ = this->End.Z - this->Start.Z; return (distanceX * distanceX) + (distanceY * distanceY) + (distanceZ * distanceZ); } /// Returns the length of the line segment /// The length of the line segment public: TScalar GetLength() const { return Math::SquareRoot(GetSquaredLength()); } /// Offsets the entire line segment by the specified amount /// Amount the line segment will be offset on the X axis /// Amount the line segment will be offset on the Y axis /// Amount the line segment will be offset on the Y axis public: void ShiftBy(TScalar offsetX, TScalar offsetY, TScalar offsetZ) { this->Start.X += offsetX; this->Start.Y += offsetY; this->Start.Z += offsetZ; this->End.X += offsetX; this->End.Y += offsetY; this->End.Z += offsetZ; } /// Offsets the entire line segment by the specified amount /// Amount the line segment will be offset public: void ShiftBy(const Vector3 &offset) { this->Start += offset; this->End += offset; } /// Coordinates at which the line segment begins public: Point3 Start; /// Coordinates at which the line segment ends public: Point3 End; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Lines #endif // NUCLEX_GEOMETRY_LINES_SEGMENT3_H