Snap Smart Raster and Raster brushes to 15 degrees (#154)

This commit is contained in:
Jeremy Bullock 2020-09-13 12:42:34 -06:00 committed by GitHub
parent 299f21dce4
commit 74e0fbad65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 31 deletions

View file

@ -504,24 +504,51 @@ void FullColorBrushTool::leftButtonDrag(const TPointD &pos,
double denominator = m_lastPoint.x - m_firstPoint.x;
if (denominator == 0) denominator == 0.001;
double slope = ((m_lastPoint.y - m_firstPoint.y) / denominator);
double angle = std::atan(slope) * (180 / 3.14159);
if (abs(angle) > 67.5)
double radAngle = std::atan(abs(slope));
double angle = radAngle * (180 / 3.14159);
if (abs(angle) >= 82.5)
m_lastPoint.x = m_firstPoint.x;
else if (abs(angle) < 22.5)
else if (abs(angle) < 7.5)
m_lastPoint.y = m_firstPoint.y;
else {
double xDistance = m_lastPoint.x - m_firstPoint.x;
double yDistance = m_lastPoint.y - m_firstPoint.y;
if (abs(xDistance) > abs(yDistance)) {
if (abs(yDistance) == yDistance)
m_lastPoint.y = m_firstPoint.y + abs(xDistance);
else
m_lastPoint.y = m_firstPoint.y - abs(xDistance);
} else {
if (abs(xDistance) == xDistance)
m_lastPoint.x = m_firstPoint.x + abs(yDistance);
else
m_lastPoint.x = m_firstPoint.x - abs(yDistance);
double totalDistance = std::sqrt(std::pow(xDistance, 2) + std::pow(yDistance, 2));
double xLength = 0.0;
double yLength = 0.0;
if (angle >= 7.5 && angle < 22.5) {
yLength = std::sin(15 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(15 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 22.5 && angle < 37.5) {
yLength = std::sin(30 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(30 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 37.5 && angle < 52.5) {
yLength = std::sin(45 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(45 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 52.5 && angle < 67.5) {
yLength = std::sin(60 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(60 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 67.5 && angle < 82.5) {
yLength = std::sin(75 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(75 * (3.14159 / 180)) * totalDistance;
}
if (yDistance == abs(yDistance)) {
m_lastPoint.y = m_firstPoint.y + yLength;
}
else {
m_lastPoint.y = m_firstPoint.y - yLength;
}
if (xDistance == abs(xDistance)) {
m_lastPoint.x = m_firstPoint.x + xLength;
}
else {
m_lastPoint.x = m_firstPoint.x - xLength;
}
}
}

View file

@ -1534,27 +1534,59 @@ void ToonzRasterBrushTool::leftButtonDrag(const TPointD &pos,
TRectD(TPointD(m_brushPos.x - distance, m_brushPos.y - distance),
TPointD(m_brushPos.x + distance, m_brushPos.y + distance));
invalidateRect += (brushRect);
double denominator = m_lastPoint.x - m_firstPoint.x;
if (denominator == 0) denominator == 0.001;
double slope = ((m_lastPoint.y - m_firstPoint.y) / denominator);
double angle = std::atan(slope) * (180 / 3.14159);
if (abs(angle) > 67.5)
double radAngle = std::atan(abs(slope));
double angle = radAngle * (180 / 3.14159);
if (abs(angle) >= 82.5) {
// make it vertical
m_lastPoint.x = m_firstPoint.x;
else if (abs(angle) < 22.5)
}
else if (abs(angle) < 7.5) {
// make it horizontal
m_lastPoint.y = m_firstPoint.y;
}
else {
double xDistance = m_lastPoint.x - m_firstPoint.x;
double yDistance = m_lastPoint.y - m_firstPoint.y;
if (abs(xDistance) > abs(yDistance)) {
if (abs(yDistance) == yDistance)
m_lastPoint.y = m_firstPoint.y + abs(xDistance);
else
m_lastPoint.y = m_firstPoint.y - abs(xDistance);
} else {
if (abs(xDistance) == xDistance)
m_lastPoint.x = m_firstPoint.x + abs(yDistance);
else
m_lastPoint.x = m_firstPoint.x - abs(yDistance);
double totalDistance = std::sqrt(std::pow(xDistance, 2) + std::pow(yDistance, 2));
double xLength = 0.0;
double yLength = 0.0;
if (angle >= 7.5 && angle < 22.5) {
yLength = std::sin(15 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(15 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 22.5 && angle < 37.5) {
yLength = std::sin(30 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(30 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 37.5 && angle < 52.5) {
yLength = std::sin(45 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(45 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 52.5 && angle < 67.5) {
yLength = std::sin(60 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(60 * (3.14159 / 180)) * totalDistance;
}
else if (angle >= 67.5 && angle < 82.5) {
yLength = std::sin(75 * (3.14159 / 180)) * totalDistance;
xLength = std::cos(75 * (3.14159 / 180)) * totalDistance;
}
if (yDistance == abs(yDistance)) {
m_lastPoint.y = m_firstPoint.y + yLength;
}
else {
m_lastPoint.y = m_firstPoint.y - yLength;
}
if (xDistance == abs(xDistance)) {
m_lastPoint.x = m_firstPoint.x + xLength;
}
else {
m_lastPoint.x = m_firstPoint.x - xLength;
}
}
}