Add frozen TikZRefinery demo baseline and build pipeline
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "model/EditorTypes.h"
|
||||
#include "ShapeTypes.h"
|
||||
|
||||
namespace TikzRefinery {
|
||||
|
||||
// Shared with parsing: gesture bounds must include the same ink envelope.
|
||||
struct ShapeGeometryLimits
|
||||
{
|
||||
static constexpr qreal rMinimumRectangleCentimeters = ShapeApi::rMinimumRectangleCentimeters;
|
||||
static constexpr int iCoordinateDecimals = ShapeApi::iCoordinateDecimals;
|
||||
static constexpr qreal rCoordinateStepsPerCentimeter = ShapeApi::rCoordinateStepsPerCentimeter;
|
||||
static constexpr qreal rCentimetersPerInch = 2.54;
|
||||
static constexpr qreal rTexPointsPerInch = 72.27;
|
||||
static constexpr qreal rHalfStroke = 0.5;
|
||||
static constexpr qreal rArrowTipBasePoints = 0.28;
|
||||
static constexpr qreal rArrowTipWidthFactor = 0.3;
|
||||
static constexpr qreal rArrowTipSpanFactor = 4.0;
|
||||
static constexpr qreal rArrowStrokeFactor = 0.4;
|
||||
};
|
||||
|
||||
inline qreal outlineMarginCentimeters(const ElementRecord &element)
|
||||
{
|
||||
using Limits = ShapeGeometryLimits;
|
||||
const qreal rEnvelopePoints = element.elementKind == ElementKind::Arrow
|
||||
? Limits::rArrowTipSpanFactor * (Limits::rArrowTipBasePoints
|
||||
+ Limits::rArrowTipWidthFactor * element.rLineWidthPoints)
|
||||
+ Limits::rArrowStrokeFactor * element.rLineWidthPoints
|
||||
: Limits::rHalfStroke * element.rLineWidthPoints;
|
||||
return rEnvelopePoints * Limits::rCentimetersPerInch / Limits::rTexPointsPerInch;
|
||||
}
|
||||
|
||||
} // namespace TikzRefinery
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "geometry/tkrCoordinateMapper.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace TikzRefinery {
|
||||
|
||||
OperationResult tkrCoordinateMapper::configure(const QPointF &ptSceneOrigin,
|
||||
qreal rSceneUnitsPerCentimeter)
|
||||
{
|
||||
if (!std::isfinite(ptSceneOrigin.x()) || !std::isfinite(ptSceneOrigin.y())
|
||||
|| !std::isfinite(rSceneUnitsPerCentimeter) || rSceneUnitsPerCentimeter <= 0.0) {
|
||||
return {false, QStringLiteral("Coordinate mapping needs a finite origin and positive scale.")};
|
||||
}
|
||||
m_ptSceneOrigin = ptSceneOrigin;
|
||||
m_rSceneUnitsPerCentimeter = rSceneUnitsPerCentimeter;
|
||||
return {true, {}};
|
||||
}
|
||||
|
||||
QPointF tkrCoordinateMapper::mapToScene(const QPointF &ptTikzPosition) const
|
||||
{
|
||||
return QPointF(m_ptSceneOrigin.x() + m_rSceneUnitsPerCentimeter * ptTikzPosition.x(),
|
||||
m_ptSceneOrigin.y() - m_rSceneUnitsPerCentimeter * ptTikzPosition.y());
|
||||
}
|
||||
|
||||
QPointF tkrCoordinateMapper::mapToTikz(const QPointF &ptScenePosition) const
|
||||
{
|
||||
return QPointF((ptScenePosition.x() - m_ptSceneOrigin.x()) / m_rSceneUnitsPerCentimeter,
|
||||
(m_ptSceneOrigin.y() - ptScenePosition.y()) / m_rSceneUnitsPerCentimeter);
|
||||
}
|
||||
|
||||
} // namespace TikzRefinery
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "model/EditorTypes.h"
|
||||
|
||||
namespace TikzRefinery {
|
||||
|
||||
// Scene units are independent of viewport pixels, zoom and pan.
|
||||
class tkrCoordinateMapper final
|
||||
{
|
||||
public:
|
||||
OperationResult configure(const QPointF &ptSceneOrigin, qreal rSceneUnitsPerCentimeter);
|
||||
QPointF mapToScene(const QPointF &ptTikzPosition) const;
|
||||
QPointF mapToTikz(const QPointF &ptScenePosition) const;
|
||||
|
||||
private:
|
||||
QPointF m_ptSceneOrigin = QPointF(200.0, 300.0);
|
||||
qreal m_rSceneUnitsPerCentimeter = 100.0;
|
||||
};
|
||||
|
||||
} // namespace TikzRefinery
|
||||
Reference in New Issue
Block a user