source: src/LinearAlgebra/LineSegment.cpp@ 111387

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 111387 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

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