Loading...
Searching...
No Matches
lineSeg2d.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_LINE_SEG2D_H
25#define PXR_BASE_GF_LINE_SEG2D_H
26
29
30#include "pxr/pxr.h"
31#include "pxr/base/gf/line2d.h"
32#include "pxr/base/gf/vec2d.h"
33#include "pxr/base/gf/api.h"
34
35#include <float.h>
36
37PXR_NAMESPACE_OPEN_SCOPE
38
47
48 public:
49
52 }
53
55 GfLineSeg2d(const GfVec2d &p0, const GfVec2d &p1 ) {
56 _length = _line.Set( p0, p1 - p0 );
57 }
58
61 GfVec2d GetPoint( double t ) const {return _line.GetPoint( t * _length );}
62
64 const GfVec2d &GetDirection() const { return _line.GetDirection(); }
65
67 double GetLength() const { return _length; }
68
72 GF_API
73 GfVec2d FindClosestPoint(const GfVec2d &point, double *t = NULL) const;
74
77 bool operator ==(const GfLineSeg2d &l) const {
78 return (_line == l._line && _length == l._length);
79 }
80
84 bool operator !=(const GfLineSeg2d &r) const {
85 return ! (*this == r);
86 }
87
88 private:
89 GF_API
90 friend bool GfFindClosestPoints( const GfLine2d &, const GfLineSeg2d &,
91 GfVec2d *, GfVec2d *,
92 double *t1, double *t2 );
93 GF_API
94 friend bool GfFindClosestPoints( const GfLineSeg2d &, const GfLineSeg2d &,
95 GfVec2d *, GfVec2d *,
96 double *, double * );
97
98 GfLine2d _line;
99 double _length; // distance from p0 to p1
100};
101
111GF_API
112bool GfFindClosestPoints( const GfLine2d &line, const GfLineSeg2d &seg,
113 GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
114 double *t1 = nullptr, double *t2 = nullptr );
115
124GF_API
125bool GfFindClosestPoints( const GfLineSeg2d &seg1, const GfLineSeg2d &seg2,
126 GfVec2d *p1 = nullptr, GfVec2d *p2 = nullptr,
127 double *t1 = nullptr, double *t2 = nullptr );
128
129PXR_NAMESPACE_CLOSE_SCOPE
130
131#endif // PXR_BASE_GF_LINE_SEG2D_H
Basic type: 2D line.
Definition: line2d.h:49
const GfVec2d & GetDirection() const
Return the normalized direction of the line.
Definition: line2d.h:73
GfVec2d GetPoint(double t) const
Return the point on the line at ( p0 + t * dir ).
Definition: line2d.h:70
Basic type: 2D line segment.
Definition: lineSeg2d.h:46
const GfVec2d & GetDirection() const
Return the normalized direction of the line.
Definition: lineSeg2d.h:64
bool operator!=(const GfLineSeg2d &r) const
Component-wise inequality test.
Definition: lineSeg2d.h:84
GF_API friend bool GfFindClosestPoints(const GfLineSeg2d &, const GfLineSeg2d &, GfVec2d *, GfVec2d *, double *, double *)
Computes the closets points on two line segments, seg1 and seg2.
GfLineSeg2d()
The default constructor leaves line parameters undefined.
Definition: lineSeg2d.h:51
GfVec2d GetPoint(double t) const
Return the point on the segment specified by the parameter t.
Definition: lineSeg2d.h:61
GF_API friend bool GfFindClosestPoints(const GfLine2d &, const GfLineSeg2d &, GfVec2d *, GfVec2d *, double *t1, double *t2)
Computes the closets points on line and seg.
double GetLength() const
Return the length of the line.
Definition: lineSeg2d.h:67
bool operator==(const GfLineSeg2d &l) const
Component-wise equality test.
Definition: lineSeg2d.h:77
GF_API GfVec2d FindClosestPoint(const GfVec2d &point, double *t=NULL) const
Returns the point on the line that is closest to point.
GfLineSeg2d(const GfVec2d &p0, const GfVec2d &p1)
Construct a line segment that spans two points.
Definition: lineSeg2d.h:55
Basic type for a vector of 2 double components.
Definition: vec2d.h:63
GF_API bool GfFindClosestPoints(const GfLine2d &line, const GfLineSeg2d &seg, GfVec2d *p1=nullptr, GfVec2d *p2=nullptr, double *t1=nullptr, double *t2=nullptr)
Computes the closets points on line and seg.