/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include namespace tools { double Line::GetLength() const { return hypot( maStart.X() - maEnd.X(), maStart.Y() - maEnd.Y() ); } bool Line::Intersection( const Line& rLine, Point& rIntersection ) const { double fX, fY; bool bRet; if( Intersection( rLine, fX, fY ) ) { rIntersection.setX( FRound( fX ) ); rIntersection.setY( FRound( fY ) ); bRet = true; } else bRet = false; return bRet; } bool Line::Intersection( const tools::Line& rLine, double& rIntersectionX, double& rIntersectionY ) const { const double fAx = static_cast(maEnd.X()) - maStart.X(); const double fAy = static_cast(maEnd.Y()) - maStart.Y(); const double fBx = static_cast(rLine.maStart.X()) - rLine.maEnd.X(); const double fBy = static_cast(rLine.maStart.Y()) - rLine.maEnd.Y(); const double fDen = fAy * fBx - fAx * fBy; bool bOk = false; if( fDen != 0. ) { const double fCx = static_cast(maStart.X()) - rLine.maStart.X(); const double fCy = static_cast(maStart.Y()) - rLine.maStart.Y(); const double fA = fBy * fCx - fBx * fCy; const bool bGreater = ( fDen > 0. ); bOk = true; if ( bGreater ) { if ( ( fA < 0. ) || ( fA > fDen ) ) bOk = false; } else if ( ( fA > 0. ) || ( fA < fDen ) ) bOk = false; if ( bOk ) { const double fB = fAx * fCy - fAy * fCx; if ( bGreater ) { if ( ( fB < 0. ) || ( fB > fDen ) ) bOk = false; } else if ( ( fB > 0. ) || ( fB < fDen ) ) bOk = false; if( bOk ) { const double fAlpha = fA / fDen; rIntersectionX = ( maStart.X() + fAlpha * fAx ); rIntersectionY = ( maStart.Y() + fAlpha * fAy ); } } } return bOk; } double Line::GetDistance( const double& rPtX, const double& rPtY ) const { double fDist; if( maStart != maEnd ) { const double fDistX = static_cast(maEnd.X()) - maStart.X(); const double fDistY = static_cast(maEnd.Y()) - maStart.Y(); const double fACX = static_cast(maStart.X()) - rPtX; const double fACY = static_cast(maStart.Y()) - rPtY; const double fL2 = fDistX * fDistX + fDistY * fDistY; const double fR = ( fACY * -fDistY - fACX * fDistX ) / fL2; const double fS = ( fACY * fDistX - fACX * fDistY ) / fL2; if( fR < 0.0 ) { fDist = hypot( maStart.X() - rPtX, maStart.Y() - rPtY ); if( fS < 0.0 ) fDist *= -1.0; } else if( fR <= 1.0 ) fDist = fS * sqrt( fL2 ); else { fDist = hypot( maEnd.X() - rPtX, maEnd.Y() - rPtY ); if( fS < 0.0 ) fDist *= -1.0; } } else fDist = hypot( maStart.X() - rPtX, maStart.Y() - rPtY ); return fDist; } } //namespace tools /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
d>Remove never-executed else-block
AgeCommit message (Expand)Author
Muhammet Kara
2020-02-16GBUILD_TRACE, support for finding out where the build time is spentLuboš Luňák
2020-02-04tdf#117331 Merge jurt and unoil into ridlSamuel Mehrbrodt
2020-01-31clang-tidy modernize-concat-nested-namespaceNoel Grandin
2020-01-13tdf#88205 Adapt uses of css::uno::Sequence to use initializer_list ctorMesut Çifci
2019-12-23sal_Char->char in test..testtoolsNoel Grandin
2019-12-10Fix IdentationError and mixture of spaces and tabsJens Carl
2019-11-22Extend loplugin:external to warn about classesStephan Bergmann
2019-08-20Fix typosAndrea Gelmini
2019-08-17tdf#88205 Adapt uses of css::uno::Sequence to use initializer_list ctorJulien Nabet
2019-08-12Fix typosAndrea Gelmini
2019-07-31Fix typosAndrea Gelmini
2019-07-31Improved loplugin:stringconstant (now that GCC 7 supports it): testtoolsStephan Bergmann
2019-07-30Fix typo in codeAndrea Gelmini
2019-05-02Use hasElements to check Sequence emptiness in [t-u]*Arkadiy Illarionov
2019-03-05re-land "new loplugin typedefparam""Noel Grandin
2018-11-19Fix typosAndrea Gelmini
2018-11-12Fix typosAndrea Gelmini
2018-11-02fix signatures of deleted copy/assign operatorsNoel Grandin
2018-10-24Simplify containers iterations in test..toolsArkadiy Illarionov
2018-10-22loplugin:staticvar in variousNoel Grandin
2018-10-09Extend loplugin:redundantinline to catch inline functions w/o external linkageStephan Bergmann
2018-10-03loplugin:constfields in swNoel Grandin
2018-09-17New loplugin:externalStephan Bergmann
2018-09-10tdf#42949 Fix IWYU warnings in include/cppuhelper/*Gabor Kelemen
2018-07-08tdf#84323 - sal - add sane sleep interface: cleanup osl_waitThreadKevin Dubrulle
2018-02-13Use PYTHON_FOR_BUILD instead of calling python directlyTomáš Chvátal
2018-01-19SAL_W32 is just an alias for _WIN32Stephan Bergmann
2018-01-16Fix typosAndrea Gelmini
2018-01-15More loplugin:cstylecast: testtoolsStephan Bergmann
2017-12-11loplugin:salcall fix functionsNoel Grandin
2017-10-23loplugin:includeform: testtoolsStephan Bergmann
2017-09-18Some more WIN32_LEAN_AND_MEANMike Kaganski
2017-06-27Fix typosAndrea Gelmini
2017-06-06One more test to suppressStephan Bergmann
2017-06-05Improved loplugin:cstylecast to reference types: testtoolsStephan Bergmann
2017-05-28remove unnecessary use of OString::getStrNoel Grandin
2017-04-28loplugin:salunicodeliteral: testtoolsStephan Bergmann
2017-04-03use actual UNO enums in test..vbahelperNoel Grandin
2017-03-25Fix typosAndrea Gelmini
2017-02-21remove some unnecessary OUStringBuffer usageNoel Grandin
2017-02-15Some simplifications, using UNO_QUERY_THROWStephan Bergmann
2017-02-06Add missing #includesStephan Bergmann
2017-01-26Remove dynamic exception specificationsStephan Bergmann
2016-12-09Remove irrelevant SAL_INFOsStephan Bergmann
2016-12-08OSL_TRACE -> SAL in sw..ucbNoel Grandin
2016-12-01loplugin:unnecessaryoverride (dtors) in testtoolsStephan Bergmann