ToyDrawingUtils.cpp 1.73 KB
//
//  ToyDrawingUtils.cpp
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 20.05.2017.
//
//

#include <stdio.h>
#include "ToyDrawingUtils.h"
#include "ToyGeometryUtils.h"

//TODO: this is not so needed here, maybe for thinner lines in scribbles. but it needs to be improved, because it causes android to get stuck.
std::vector<cocos2d::Point> ToyDrawingUtils::calculateSmoothLinePoints(std::vector<cocos2d::Point> threeLastPoints)
{
//    if(threeLastPoints.size() != 3){
////        log("ToyDrawingUtils: calculateSmoothLinePoints: argument should be an array with exactly three elements");
//        return threeLastPoints;
//    }
//
//    std::vector<cocos2d::Point> smoothedPoints;
//
//    auto point1 = threeLastPoints[0], point2 = threeLastPoints[1], point3 = threeLastPoints[2];
//
//    auto midPoint1 = point1.getMidpoint(point2);
//    auto midPoint2 = point2.getMidpoint(point3);
//
//    auto distance = midPoint1.distance(midPoint2);
//    auto segmentDistance = 2; //2 pixels
//    auto numberOfSegments = MIN(128, MAX(floor(distance / segmentDistance), 32));
//
//    float t = 0;
//    float step = 1 / numberOfSegments;
//
//    for(int i = 0; i < numberOfSegments; ++i){
//
//        std::vector<cocos2d::Point> argumentPoints;
//        auto p1 = midPoint1 * (1-t)*(1-t);
//        auto p2 = point2 * t*(1-t)*2;
//        auto p3 = midPoint2 * t*t;
//        argumentPoints.push_back(p1);
//        argumentPoints.push_back(p2);
//        argumentPoints.push_back(p3);
//
//        auto newPoint = ToyGeometryUtils::addPoints(argumentPoints);
//
//        smoothedPoints.push_back(newPoint);
//        t += step;
//    }
//
//    smoothedPoints.push_back(midPoint2);

//    return smoothedPoints;
    return threeLastPoints;
}