init
This commit is contained in:
148
lib/information/rs_infoarea.cpp
Normal file
148
lib/information/rs_infoarea.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** This file is part of the LibreCAD project, a 2D CAD program
|
||||
**
|
||||
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
|
||||
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
|
||||
**
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file gpl-2.0.txt included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**
|
||||
** This copyright notice MUST APPEAR in all copies of the script!
|
||||
**
|
||||
**********************************************************************/
|
||||
#include<cmath>
|
||||
#include <QPolygon>
|
||||
#include "rs_infoarea.h"
|
||||
|
||||
#include "rs_math.h"
|
||||
#include "rs_debug.h"
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
RS_InfoArea::RS_InfoArea():
|
||||
calculationNeeded(true)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a point to the internal list
|
||||
*
|
||||
* @param p coordinate of the point
|
||||
*/
|
||||
void RS_InfoArea::push_back(const RS_Vector& p) {
|
||||
if (thePoints.empty()) {
|
||||
baseY = p.y;
|
||||
}
|
||||
|
||||
thePoints.push_back(p);
|
||||
calculationNeeded=true;
|
||||
}
|
||||
|
||||
//remove the last point
|
||||
void RS_InfoArea::pop_back() {
|
||||
thePoints.pop_back();
|
||||
calculationNeeded=true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the points.
|
||||
*/
|
||||
void RS_InfoArea::reset() {
|
||||
thePoints.clear();
|
||||
area = 0.0;
|
||||
circumference = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether a point is already in contour
|
||||
*@return true if the point is a duplicate
|
||||
*@return false if the point is not in contour
|
||||
**/
|
||||
bool RS_InfoArea::duplicated(const RS_Vector& p){
|
||||
if(thePoints.size()<1) return false;
|
||||
for(const RS_Vector& v: thePoints){
|
||||
if((v-p).squared()<RS_TOLERANCE2) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the area and the circumference of the area.
|
||||
*/
|
||||
void RS_InfoArea::calculate() {
|
||||
area = 0.0;
|
||||
circumference = 0.0;
|
||||
if(thePoints.size()<3) return;
|
||||
|
||||
RS_Vector p1=thePoints.front();
|
||||
for(size_t i=0;i<thePoints.size();++i){
|
||||
// std::cout<<"RS_InfoArea::calculate(): "<<i<<" , "<<p1<<std::endl;
|
||||
RS_Vector p2=thePoints.at( (i+1)%thePoints.size());
|
||||
area += calcSubArea(p1, p2);
|
||||
circumference += p1.distanceTo(p2);
|
||||
p1=p2;
|
||||
}
|
||||
|
||||
area = 0.5*fabs(area);
|
||||
calculationNeeded=false;
|
||||
}
|
||||
|
||||
double RS_InfoArea::getArea(const QPolygon& polygon)
|
||||
{
|
||||
double ret= 0.0;
|
||||
if(polygon.size()<3) return ret;
|
||||
|
||||
for(int i=0;i<polygon.size(); ++i){
|
||||
const QPoint& p0=polygon.at(i);
|
||||
const QPoint& p1=polygon.at((i+1)%polygon.size());
|
||||
ret += p0.x()*p1.y()-p0.y()*p1.x();
|
||||
}
|
||||
return 0.5*fabs(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a sub area.
|
||||
*
|
||||
* @param p1 first point
|
||||
* @param p2 second point
|
||||
*/
|
||||
double RS_InfoArea::calcSubArea(const RS_Vector& p1, const RS_Vector& p2) {
|
||||
double width = p2.x - p1.x;
|
||||
double height = (p1.y - baseY) + (p2.y - baseY);
|
||||
|
||||
return width * height ; //moved a factor of 0.5 to calculate()
|
||||
}
|
||||
|
||||
|
||||
double RS_InfoArea::getArea() const{
|
||||
return area;
|
||||
}
|
||||
double RS_InfoArea::getCircumference() {
|
||||
if(calculationNeeded) calculate();
|
||||
return circumference;
|
||||
}
|
||||
int RS_InfoArea::size() {
|
||||
if(calculationNeeded) calculate();
|
||||
return thePoints.size();
|
||||
}
|
||||
const RS_Vector& RS_InfoArea::at(int i) const{
|
||||
return thePoints.at(i);
|
||||
}
|
||||
|
||||
// EOF
|
||||
70
lib/information/rs_infoarea.h
Normal file
70
lib/information/rs_infoarea.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** This file is part of the LibreCAD project, a 2D CAD program
|
||||
**
|
||||
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
|
||||
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
|
||||
**
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file gpl-2.0.txt included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**
|
||||
** This copyright notice MUST APPEAR in all copies of the script!
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RS_INFOAREA_H
|
||||
#define RS_INFOAREA_H
|
||||
|
||||
#include <vector>
|
||||
#include "rs_vector.h"
|
||||
|
||||
class QPolygon;
|
||||
/**
|
||||
* Class for getting information about an area.
|
||||
*
|
||||
* @author Andrew Mustun
|
||||
*/
|
||||
class RS_InfoArea {
|
||||
public:
|
||||
RS_InfoArea();
|
||||
|
||||
void reset();
|
||||
void push_back(const RS_Vector& p);
|
||||
//whether the point p is already in contour
|
||||
bool duplicated(const RS_Vector& p);
|
||||
void pop_back();
|
||||
double getArea() const;
|
||||
double getCircumference();
|
||||
int size();
|
||||
const RS_Vector& at(int i) const;
|
||||
/**
|
||||
* @brief getArea of polygon
|
||||
* @param polygon
|
||||
* @return area
|
||||
*/
|
||||
static double getArea(const QPolygon& polygon);
|
||||
|
||||
private:
|
||||
void calculate();
|
||||
double calcSubArea(const RS_Vector& p1, const RS_Vector& p2);
|
||||
|
||||
std::vector<RS_Vector> thePoints;
|
||||
double baseY;
|
||||
double area;
|
||||
double circumference;
|
||||
bool calculationNeeded;
|
||||
};
|
||||
|
||||
#endif
|
||||
1007
lib/information/rs_information.cpp
Normal file
1007
lib/information/rs_information.cpp
Normal file
File diff suppressed because it is too large
Load Diff
109
lib/information/rs_information.h
Normal file
109
lib/information/rs_information.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** This file is part of the LibreCAD project, a 2D CAD program
|
||||
**
|
||||
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
|
||||
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
|
||||
**
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file gpl-2.0.txt included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**
|
||||
** This copyright notice MUST APPEAR in all copies of the script!
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RS_INFORMATION_H
|
||||
#define RS_INFORMATION_H
|
||||
|
||||
#include "rs.h"
|
||||
|
||||
class RS_Ellipse;
|
||||
class RS_Entity;
|
||||
class RS_EntityContainer;
|
||||
class RS_Vector;
|
||||
class RS_VectorSolutions;
|
||||
class RS_Arc;
|
||||
class RS_Circle;
|
||||
class RS_Line;
|
||||
|
||||
/**
|
||||
* Class for getting information about entities. This includes
|
||||
* also things like the end point of an element which is
|
||||
* nearest to a given coordinate.
|
||||
* There's no interaction handled in this class.
|
||||
* This class is bound to an entity container.
|
||||
*
|
||||
* @author Andrew Mustun
|
||||
*/
|
||||
class RS_Information {
|
||||
public:
|
||||
RS_Information(RS_EntityContainer& entityContainer);
|
||||
|
||||
static bool isDimension(RS2::EntityType type);
|
||||
static bool isTrimmable(RS_Entity* e);
|
||||
static bool isTrimmable(RS_Entity* e1, RS_Entity* e2);
|
||||
|
||||
RS_Vector getNearestEndpoint(const RS_Vector& point,
|
||||
double* dist = nullptr) const;
|
||||
RS_Vector getNearestPointOnEntity(const RS_Vector& point,
|
||||
bool onEntity=true,
|
||||
double* dist = nullptr,
|
||||
RS_Entity** entity=nullptr) const;
|
||||
RS_Entity* getNearestEntity(const RS_Vector& point,
|
||||
double* dist = nullptr,
|
||||
RS2::ResolveLevel level=RS2::ResolveAll) const;
|
||||
|
||||
|
||||
static RS_VectorSolutions getIntersection(RS_Entity const* e1,
|
||||
RS_Entity const* e2,
|
||||
bool onEntities = false);
|
||||
|
||||
static RS_VectorSolutions getIntersectionLineLine(RS_Line* e1,
|
||||
RS_Line* e2);
|
||||
|
||||
static RS_VectorSolutions getIntersectionLineArc(RS_Line* line,
|
||||
RS_Arc* arc);
|
||||
|
||||
static RS_VectorSolutions getIntersectionArcArc(RS_Entity const* e1,
|
||||
RS_Entity const* e2);
|
||||
|
||||
static RS_VectorSolutions getIntersectionEllipseEllipse(
|
||||
RS_Ellipse const* e1,
|
||||
RS_Ellipse const* e2);
|
||||
static RS_VectorSolutions getIntersectionArcEllipse(RS_Arc* e1,
|
||||
RS_Ellipse* e2);
|
||||
static RS_VectorSolutions getIntersectionCircleEllipse(RS_Circle* e1,
|
||||
RS_Ellipse* e2);
|
||||
|
||||
static RS_VectorSolutions getIntersectionEllipseLine(RS_Line* line,
|
||||
RS_Ellipse* ellipse);
|
||||
/**
|
||||
* @brief createQuadrilateral form quadrilateral from 4 straight lines
|
||||
* @param container contains 4 straight lines
|
||||
* @return ordered vertices of quadrilateral formed by the 4 lines
|
||||
*/
|
||||
static RS_VectorSolutions createQuadrilateral(const RS_EntityContainer& container);
|
||||
|
||||
static bool isPointInsideContour(const RS_Vector& point,
|
||||
RS_EntityContainer* contour,
|
||||
bool* onContour=nullptr);
|
||||
|
||||
private:
|
||||
RS_EntityContainer* container;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
72
lib/information/rs_locale.cpp
Normal file
72
lib/information/rs_locale.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** This file is part of the LibreCAD project, a 2D CAD program
|
||||
**
|
||||
** Copyright (C) 2011 R. van Twisk (librecad@rvt.dds.nl)
|
||||
**
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file gpl-2.0.txt included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**
|
||||
** This copyright notice MUST APPEAR in all copies of the script!
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#include "rs_locale.h"
|
||||
|
||||
RS_Locale::RS_Locale() {
|
||||
}
|
||||
RS_Locale::RS_Locale(const QString &canonical):
|
||||
QLocale(toCanonical(canonical)){
|
||||
}
|
||||
|
||||
void RS_Locale::setCanonical(const QString &_canonical) {
|
||||
canonical=_canonical;
|
||||
}
|
||||
|
||||
QString RS_Locale::toCanonical(const QString &canonical){
|
||||
QString languageCode("C");
|
||||
int i1=canonical.indexOf('_');
|
||||
if(i1 >= 2 ) {
|
||||
languageCode= canonical.mid(0,i1).toLower();
|
||||
i1++;
|
||||
if(canonical.size() == i1+2 ){
|
||||
languageCode += QString('_')+canonical.mid(i1,canonical.size()-i1).toUpper();
|
||||
}
|
||||
}else{
|
||||
languageCode=canonical.toLower();
|
||||
}
|
||||
return languageCode;
|
||||
}
|
||||
|
||||
void RS_Locale::setDirection(RS2::TextLocaleDirection _direction) {
|
||||
direction=_direction;
|
||||
}
|
||||
void RS_Locale::setName(const QString &_name) {
|
||||
localeName=_name;
|
||||
}
|
||||
|
||||
QString RS_Locale::getCanonical() {
|
||||
return canonical;
|
||||
}
|
||||
QString RS_Locale::getName() {
|
||||
return localeName;
|
||||
}
|
||||
|
||||
QString RS_Locale::name() const{
|
||||
return languageToString(language())+QString(" (")+countryToString(country())+QString(")");
|
||||
}
|
||||
|
||||
//EOF
|
||||
|
||||
67
lib/information/rs_locale.h
Normal file
67
lib/information/rs_locale.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** This file is part of the LibreCAD project, a 2D CAD program
|
||||
**
|
||||
** Copyright (C) 2011 R. van Twisk (librecad@rvt.dds.nl)
|
||||
**
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file gpl-2.0.txt included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program; if not, write to the Free Software
|
||||
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
**
|
||||
** This copyright notice MUST APPEAR in all copies of the script!
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RS_LOCALE_H
|
||||
#define RS_LOCALE_H
|
||||
|
||||
#include <QLocale>
|
||||
#include "rs.h"
|
||||
|
||||
/**
|
||||
* Store Locale information in a class
|
||||
* (c) 2011 R. van Twisk
|
||||
*
|
||||
**/
|
||||
class RS_Locale :public QLocale {
|
||||
public:
|
||||
RS_Locale();
|
||||
RS_Locale(const QString &_canonical);
|
||||
/* without virtual destructor => warning: deleting object of polymorphic
|
||||
* class type 'RS_Locale' which has non-virtual destructor might cause
|
||||
* undefined behaviour [-Wdelete-non-virtual-dtor]
|
||||
*
|
||||
* TNick <nicu.tofan@gmail.com>
|
||||
*/
|
||||
virtual ~RS_Locale(){}
|
||||
|
||||
|
||||
virtual void setCanonical(const QString &_canonical);
|
||||
virtual void setDirection(RS2::TextLocaleDirection direction);
|
||||
virtual void setName(const QString &_name);
|
||||
virtual QString name() const;
|
||||
static QString toCanonical(const QString &canonical);
|
||||
|
||||
QString getCanonical();
|
||||
QString getName();
|
||||
|
||||
protected:
|
||||
QString canonical;
|
||||
QString localeName;
|
||||
int direction;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user