source: src/LinearAlgebra/LineSegment.cpp@ 5d4b73

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 5d4b73 was 6c438f, checked in by Frederik Heber <heber@…>, 14 years ago

Merge branch 'StructureRefactoring' into Shapes

Conflicts:

src/Box.cpp
src/Box.hpp
src/Descriptors/AtomShapeDescriptor.cpp
src/Descriptors/AtomShapeDescriptor.hpp
src/Descriptors/AtomShapeDescriptor_impl.hpp
src/LinearAlgebra/Line.cpp
src/LinearAlgebra/Line.hpp
src/LinearAlgebra/Matrix.cpp
src/LinearAlgebra/Matrix.hpp
src/Makefile.am
src/Shapes/BaseShapes.cpp
src/Shapes/BaseShapes_impl.hpp
src/Shapes/Shape.cpp
src/Shapes/Shape.hpp
src/Shapes/ShapeOps_impl.hpp
src/Shapes/Shape_impl.hpp
src/unittests/ShapeUnittest.cpp

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * LineSegment.cpp
3 *
4 * Created on: Jul 22, 2010
5 * Author: crueger
6 */
7
8#include "LinearAlgebra/LineSegment.hpp"
9#include "Helpers/Assert.hpp"
10
11#include "Line.hpp"
12#include "LinearAlgebra/Vector.hpp"
13
14using namespace std;
15
16LineSegment::LineSegment(const Vector &point1,const Vector &point2){
17 line.reset(new Line(point1,point1-point2));
18 begin.reset(new LinePoint(line->getLinePoint(point1)));
19 end.reset(new LinePoint(line->getLinePoint(point2)));
20}
21
22LineSegment::LineSegment(const LinePoint &lp1,const LinePoint &lp2){
23 ASSERT(lp1.getLine()==lp2.getLine(),"Cannot make a lineSegment with two different lines");
24 line.reset(new Line(lp1.getLine()));
25 begin.reset(new LinePoint(lp1));
26 end.reset(new LinePoint(lp2));
27}
28LineSegment::LineSegment(const LineSegment &src)
29{
30 line.reset(new Line(*src.line));
31 begin.reset(new LinePoint(*src.begin));
32 end.reset(new LinePoint(*src.end));
33}
34LineSegment::~LineSegment(){
35}
36LineSegment &LineSegment::operator=(const LineSegment &src){
37 if(this!=&src){
38 lineptr _line(new Line(*src.line));
39 pointptr _begin(new LinePoint(*src.begin));
40 pointptr _end(new LinePoint(*src.end));
41 line = _line;
42 begin = _begin;
43 end = _end;
44 }
45 return *this;
46}
47
48bool LineSegment::isContained(const Vector &point) const{
49 if(!line->isContained(point)){
50 return false;
51 }
52 LinePoint lp = line->getLinePoint(point);
53 return *begin <= lp && lp <= *end;
54}
55
56bool LineSegment::isContained(const LinePoint &lp) const{
57 ASSERT(lp.getLine()==*line,"Cannot compare Linepoints from different Lines");
58 return *begin <= lp && lp <= *end;
59}
60
61bool LineSegment::overlaps(const LineSegment &lineSeg) const{
62 ASSERT(*lineSeg.line == *line,"Cannot compare Linesegments from different Lines");
63 // mutual comparison of endpoints
64 return lineSeg.isContained(*end) || isContained(*lineSeg.end);
65}
66
67bool LineSegment::hasZeroLength() const{
68 return *begin==*end;
69}
70
71LinePoint LineSegment::getBegin() const{
72 return *begin;
73}
74
75LinePoint LineSegment::getEnd() const{
76 return *end;
77}
78
79Line LineSegment::getLine() const{
80 return *line;
81}
82
83bool operator==(const LineSegment &x,const LineSegment &y){
84 ASSERT(*x.line==*y.line,"Comparison of Linesegments from different lines");
85 return *x.begin == *y.begin && *x.end == *y.end;
86}
87bool operator<(const LineSegment &x,const LineSegment &y){
88 ASSERT(*x.line==*y.line,"Comparison of Linesegments from different lines");
89 return (*x.begin != *y.begin) ? *x.begin<*y.begin:*x.end<*y.end;
90}
Note: See TracBrowser for help on using the repository browser.