Skip to content

Commit

Permalink
corrected min-max-calculation of ARCs
Browse files Browse the repository at this point in the history
  • Loading branch information
plc-user committed Jan 23, 2023
1 parent 2d5beae commit 9ebe947
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
30 changes: 28 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
// Result is a new file "FILENAME.SCALED.elmt" or output on stdout
// in both cases without the XML declaration-line
//
// Change(s) for 0.4beta9
// - added mathmatically correct calculation for Min-Max-Values of ARC
//
// Change(s) for 0.4beta8
// - graphical element "arc": normalize "start" and "angle" to positive values
// - internal: replaced struct for element's min-max-values by own class
Expand Down Expand Up @@ -108,7 +111,7 @@
#include "inc/pugixml/pugixml.hpp"
#include "main.h"

const string sVersion = "0.4beta8";
const string sVersion = "0.4beta9";

const int _debug_ = 0;
const int _debug_points_ = 0;
Expand Down Expand Up @@ -709,6 +712,29 @@ int InputFlipHor(pugi::xml_node &node){
/*****************************************************************************/


/*****************************************************************************/
void DetermineArcMinMax(pugi::xml_node &node){
// read values from XML:
double PosX = node.attribute("x").as_double();
double PosY = node.attribute("y").as_double();
double Height = node.attribute("height").as_double();
double Width = node.attribute("width").as_double();
int StartDeg = round(node.attribute("start").as_double());
int AngleDeg = round(node.attribute("angle").as_double());
const double pi = 3.14159265359;
// calculate points on ellipse-circumference:
// x = a ⋅ cos(t)
// y = b ⋅ sin(t)
// with t = 0 .. 2*pi = ([0 .. 360]/360)*2*pi
for (int i = StartDeg; i <= (StartDeg + AngleDeg); i++){
double x = PosX + (Width/2) * (1 + cos((i%360)/360.0*2*pi));
double y = PosY + (Height/2) * (1 - sin((i%360)/360.0*2*pi));
XYMinMax.add(x, y);
}
return;
}
/*****************************************************************************/

/*****************************************************************************/
void DetermineMinMax(pugi::xml_node &node){
// no need to make a difference, what node it is: non-existing attributes return "0.0"
Expand Down Expand Up @@ -871,7 +897,7 @@ int main(int argc, char *argv[]) {
if (xFlipHor==true) { ArcFlipHor(node); }
if (xFlipVert==true) { ArcFlipVert(node); }
NormalizeArc(node);
DetermineMinMax(node);
DetermineArcMinMax(node);
}
if ((string(node.name())) == "terminal") {
ScaleElement(node);
Expand Down
1 change: 1 addition & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ int ArcFlipVert(pugi::xml_node &node);
int ArcFlipHor(pugi::xml_node &node);
int InputFlipVert(pugi::xml_node &node);
int InputFlipHor(pugi::xml_node &node);
void DetermineArcMinMax(pugi::xml_node &node);
void DetermineMinMax(pugi::xml_node &node);


Expand Down

0 comments on commit 9ebe947

Please sign in to comment.