Loading...
Searching...
No Matches
line2d.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_BASE_GF_LINE2D_H
25#define PXR_BASE_GF_LINE2D_H
26
29
30#include "pxr/pxr.h"
31#include "pxr/base/gf/vec2d.h"
32#include "pxr/base/gf/api.h"
33
34#include <float.h>
35
36PXR_NAMESPACE_OPEN_SCOPE
37
49class GfLine2d {
50
51 public:
52
55 }
56
58 GfLine2d(const GfVec2d &p0, const GfVec2d &dir ) {
59 Set( p0, dir );
60 }
61
62 double Set(const GfVec2d &p0, const GfVec2d &dir ) {
63 _p0 = p0;
64 _dir = dir;
65 return _dir.Normalize();
66 }
67
70 GfVec2d GetPoint( double t ) const { return _p0 + _dir * t; }
71
73 const GfVec2d &GetDirection() const { return _dir; }
74
78 GF_API
79 GfVec2d FindClosestPoint(const GfVec2d &point, double *t = NULL) const;
80
83 bool operator ==(const GfLine2d &l) const {
84 return _p0 == l._p0 && _dir == l._dir;
85 }
86
89 bool operator !=(const GfLine2d &r) const {
90 return ! (*this == r);
91 }
92
93 private:
94 GF_API
95 friend bool GfFindClosestPoints( const GfLine2d &, const GfLine2d &,
96 GfVec2d *, GfVec2d *,
97 double *, double *);
98
99 // Parametric description:
100 // l(t) = _p0 + t * _length * _dir;
101 GfVec2d _p0;
102 GfVec2d _dir;
103};
104
113GF_API
114bool GfFindClosestPoints(const GfLine2d &l1, const GfLine2d &l2,
115 GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
116 double *t1 = nullptr, double *t2 = nullptr);
117
118PXR_NAMESPACE_CLOSE_SCOPE
119
120#endif // PXR_BASE_GF_LINE2D_H
Basic type: 2D line.
Definition: line2d.h:49
bool operator==(const GfLine2d &l) const
Component-wise equality test.
Definition: line2d.h:83
const GfVec2d & GetDirection() const
Return the normalized direction of the line.
Definition: line2d.h:73
GfLine2d(const GfVec2d &p0, const GfVec2d &dir)
Construct a line from a point and a direction.
Definition: line2d.h:58
GfLine2d()
The default constructor leaves line parameters undefined.
Definition: line2d.h:54
bool operator!=(const GfLine2d &r) const
Component-wise inequality test.
Definition: line2d.h:89
GfVec2d GetPoint(double t) const
Return the point on the line at ( p0 + t * dir ).
Definition: line2d.h:70
GF_API friend bool GfFindClosestPoints(const GfLine2d &, const GfLine2d &, GfVec2d *, GfVec2d *, double *, double *)
Computes the closets points between two lines.
GF_API GfVec2d FindClosestPoint(const GfVec2d &point, double *t=NULL) const
Returns the point on the line that is closest to point.
Basic type for a vector of 2 double components.
Definition: vec2d.h:63
double Normalize(double eps=GF_MIN_VECTOR_LENGTH)
Normalizes the vector in place to unit length, returning the length before normalization.
Definition: vec2d.h:258
GF_API bool GfFindClosestPoints(const GfLine2d &l1, const GfLine2d &l2, GfVec2d *p1=nullptr, GfVec2d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
Computes the closets points between two lines.