<commit_before># encoding: utf-8

###########################################################################################################
#
#
#   Reporter Plugin
#
#   Read the docs:
#   https://github.com/schriftgestalt/GlyphsSDK/tree/master/Python%20Templates/Reporter
#
#
###########################################################################################################

from GlyphsApp.plugins import *
from GlyphsApp import MOUSEMOVED
import traceback, objc, itertools, math

def distanceAB(A,B):
    sqA = (B.x - A.x) **2
    sqB = (B.y - A.y) **2
    sqC = sqA + sqB
    if sqC > 0:
        lengthAB = math.sqrt(sqC)
        return lengthAB
    else:
        return 0

def bezierCurve(t,Wx,Wy):

    t2 = t * t
    t3 = t2 * t
    mt = 1-t
    mt2 = mt * mt
    mt3 = mt2 * mt
    summaX = Wx[0]*mt3 + 3*Wx[1]*mt2*t + 3*Wx[2]*mt*t2 + Wx[3]*t3
    summaY = Wy[0]*mt3 + 3*Wy[1]*mt2*t + 3*Wy[2]*mt*t2 + Wy[3]*t3

    T = NSPoint(summaX,summaY)
    return T

def pathAB(t,Wx,Wy):
    summaX = Wx[0] + t*(Wx[1] - Wx[0])
    summaY = Wy[0] + t*(Wy[1] - Wy[0])

    T = NSPoint(summaX,summaY)
    return T

def getLut(segment, scale):
    # creates very big list of t-ratio values 't' and coordinates 'T' of every segment in active glyph window
    listOf_T   = []
    listOf_t = []
    dictOf_T_and_t_ratio = {'t' : listOf_t, 'T' : listOf_T}

    # divides segment into several t-points, calculate its coordinates and values and lists it in "listOf_T" and listoOf_t-ratio lists
    if len(segment) == 4: # for curves
        first = segment[0]
        last  = segment[3]
        lenthFirstToLast = distanceAB(first,last)
        # ratio = 1/(lenthFirstToLast/3)
        if scale == 1:
            ratio = 1/(lenthFirstToLast/3)
        else:
            ratio = 1/(scale*(round(lenthFirstToLast)/5))

        t = 0
        while t <= 1:

            T = bezierCurve(t,[segment[0].x,segment[1].x,segment[2].x,segment[3].x],[segment[0].y,segment[1].y,segment[2].y,segment[3].y])
            listOf_T.append(T)
            listOf_t.append(t)
            t += ratio

    elif len(segment) == 2: # for line
        first = segment[0]
        last  = segment[1]
        lenthFirstToLast = distanceAB(first,last)
        # ratio = 1/(lenthFirstToLast/3)
        if scale == 1:
            ratio = 1/(lenthFirstToLast/3)
        else:
            ratio = 1/(scale*(round(lenthFirstToLast)/5))

        t = 0
        while t <= 1:

            T = pathAB(t,[segment[0].x,segment[1].x],[segment[0].y,segment[1].y])
            listOf_T.append(T)
            listOf_t.append(t)
            t += ratio

    else:
        print "getLut(): ERROR"

    return dictOf_T_and_t_ratio

def closest (LUT, pointOffCurve):
    minimalDist = 10000
    position = -1
    distance = 0
    for n in range(len(LUT)):
        distance = distanceAB(pointOffCurve, LUT[n])

        if distance < minimalDist:
            minimalDist = distance
            position = n

    if position == -1:
        print "closest(): ERROR"
        return None

    return LUT[position]

def calcTangent(t,segment):
    #print "__calcTangent", t, segment
    # calculates reference Tangent Point (from its coordinates plugin will be able to get tangent's direction)

    # interpolation points based on de Casteljau's algorithm (coordinates are interpolations between control points and interpolation points)
    if len(segment) == 4: # for curves
        divided = divideCurve(segment[0], segment[1], segment[2], segment[3], t)
        # Q01 = NSPoint(
        #            pathAB(t,[segment[0].x,segment[1].x],[segment[0].y,segment[1].y]).x,
        #            pathAB(t,[segment[0].x,segment[1].x],[segment[0].y,segment[1].y]).y,
        #            )
        #
        # Q12 = NSPoint(
        #            pathAB(t,[segment[1].x,segment[2].x],[segment[1].y,segment[2].y]).x,
        #            pathAB(t,[segment[1].x,segment[2].x],[segment[1].y,segment[2].y]).y,
        #            )
        #
        # Q23 = NSPoint(
        #            pathAB(t,[segment[2].x,segment[3].x],[segment[2].y,segment[3].y]).x,
        #            pathAB(t,[segment[2].x,segment[3].x],[segment[2].y,segment[3].y]).y,
        #            )
        #
        #
        # R2  = NSPoint(
        #            pathAB(t,[Q12.x,Q23.x],[Q12.y,Q23.y]).x,
        #            pathAB(t,[Q12.x,Q23.x],[Q12.y,Q23.y]).y,
        #            )
        R2 = divided[4]
        
    elif len(segment) == 2: # for line
        R2 = segment[1]
    
    Tangent = NSPoint(R2.x,R2.y)
    return Tangent

def angle( A, B ):
    try:
        """calc angle between AB and Xaxis """
        xDiff = A.x - B.x
        yDiff = A.y - B.y
        if yDiff== 0 or xDiff== 0:
            tangens = 0
        else:
            tangens = yDiff / xDiff

        angle = math.atan( tangens )
        return angle
    except:
        print(traceback.format_exc())

def rotatePoint( P,angle, originPoint):

        """Rotates x/y around x_orig/y_orig by angle and returns result as [x,y]."""
        alfa = math.radians(angle)
<commit_msg>Dead code removal.<commit_after># encoding: utf-8

###########################################################################################################
#
#
#   Reporter Plugin
#
#   Read the docs:
#   https://github.com/schriftgestalt/GlyphsSDK/tree/master/Python%20Templates/Reporter
#
#
###########################################################################################################

from GlyphsApp.plugins import *
from GlyphsApp import MOUSEMOVED
import traceback, objc, itertools, math

def distanceAB(A,B):
    sqA = (B.x - A.x) **2
    sqB = (B.y - A.y) **2
    sqC = sqA + sqB
    if sqC > 0:
        lengthAB = math.sqrt(sqC)
        return lengthAB
    else:
        return 0

def bezierCurve(t,Wx,Wy):

    t2 = t * t
    t3 = t2 * t
    mt = 1-t
    mt2 = mt * mt
    mt3 = mt2 * mt
    summaX = Wx[0]*mt3 + 3*Wx[1]*mt2*t + 3*Wx[2]*mt*t2 + Wx[3]*t3
    summaY = Wy[0]*mt3 + 3*Wy[1]*mt2*t + 3*Wy[2]*mt*t2 + Wy[3]*t3

    T = NSPoint(summaX,summaY)
    return T

def pathAB(t,Wx,Wy):
    summaX = Wx[0] + t*(Wx[1] - Wx[0])
    summaY = Wy[0] + t*(Wy[1] - Wy[0])

    T = NSPoint(summaX,summaY)
    return T

def calcTangent(t,segment):
    # calculates reference Tangent Point (from its coordinates plugin will be able to get tangent's direction)
    if len(segment) == 4: # for curves
        divided = divideCurve(segment[0], segment[1], segment[2], segment[3], t)
        R2 = divided[4]
    elif len(segment) == 2: # for line
        R2 = segment[1]
    
    Tangent = NSPoint(R2.x,R2.y)
    return Tangent

def angle( A, B ):
    try:
        """calc angle between AB and Xaxis """
        xDiff = A.x - B.x
        yDiff = A.y - B.y
        if yDiff== 0 or xDiff== 0:
            tangens = 0
        else:
            tangens = yDiff / xDiff

        angle = math.atan( tangens )
        return angle
    except:
        print(traceback.format_exc())

def rotatePoint( P,angle, originPoint):

        """Rotates x/y around x_orig/y_orig by angle and returns result as [x,y]."""
        alfa = math.radians(angle)

{'fraction_non_alphanumeric': 0.19704848910751932, 'fraction_numerical': 0.02825017568517217, 'mean_word_length': 2.265718219366682, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1087544', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2517, 'n_words': 552}