<commit_before># -*- coding: utf-8 -*-
"""
    femagtools.dxfsl.fslreader
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    renders geometry to fsl


"""
import numpy as np
from .shape import Shape
import logging
from .. import __version__
logger = logging.getLogger(__name__)


def agndst(da1, da2, Q, p, nodedist=1):
    """ build agndst from set of useful number of nodes"""
    num_nodes = [30, 48, 60, 96, 120, 144, 180, 240, 288, 336, 360,
                 432, 480]
    r = (da1 + da2)/4
    dagset = [2*np.pi/p/i for i in num_nodes]
    ag = abs(da1 - da2)/6
    i = max(np.argmin(np.abs(np.array(dagset) - np.arctan2(ag, r))), 1)
    nd = min(round(nodedist), i)
    try:
        logger.info("Num nodes/p %d Num nodes/slot %g nodedist %g",
                    num_nodes[i-1], p*num_nodes[i-1]/Q, nodedist)
        if nodedist > 1:
            return dagset[i-nd]*r
        elif nodedist < 1 or i == 0:
            return dagset[i]*r
    except IndexError:
        pass
    return dagset[i-1]*r


class FslRenderer(object):
    """a model that can created by FSL"""

    def __init__(self, name):
        self.model = name
        self.mirror_axis = None
        self.fm_nlin = None
        self.shaft = None
        self.agndst = 1

    def mirror_nodechains(self, p0, p1):
        self.mirror_axis = np.array((p0, p1)).ravel().tolist()

    def material(self, p0):
        self.fm_nlin = p0

    def circle(self, center, radius, color='blue'):
        num = int(2*np.pi*radius)
        if num < 8:
            num = 8
        circle = [u'cx, cy = {}, {}'.format(center[0],
                                            center[1]),
                  u'nc_circle_m(cx,cy,{}, {})'.format(radius, num),
                  u'create_mesh_se(cx, cy)\n']
        self.content += circle

    def arc(self, startangle, endangle, center, radius, color='blue'):
        num = 0
        d = (endangle - startangle) % 2*np.pi
        #num = int(radius*d/self.agndst + 1)
        # if num < 3 and d > np.pi/6:
        #    num = 3
        # else:
        #    num = 0

        p1 = (center[0] + radius*np.cos(startangle),
              center[1] + radius*np.sin(startangle))
        p2 = (center[0] + radius*np.cos(endangle),
              center[1] + radius*np.sin(endangle))
        self.content.append(
            u"nc_circle_m({}, {}, {}, {}, {}, {}, {})".format(
                p1[0], p1[1], p2[0], p2[1],
                center[0], center[1], num))

    def ellipse(self, center, width, height,<commit_msg>arcs with default node density<commit_after># -*- coding: utf-8 -*-
"""
    femagtools.dxfsl.fslreader
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    renders geometry to fsl


"""
import numpy as np
from .shape import Shape
import logging
from .. import __version__
logger = logging.getLogger(__name__)


def agndst(da1, da2, Q, p, nodedist=1):
    """ build agndst from set of useful number of nodes"""
    num_nodes = [30, 48, 60, 96, 120, 144, 180, 240, 288, 336, 360,
                 432, 480]
    r = (da1 + da2)/4
    dagset = [2*np.pi/p/i for i in num_nodes]
    ag = abs(da1 - da2)/6
    i = max(np.argmin(np.abs(np.array(dagset) - np.arctan2(ag, r))), 1)
    nd = min(round(nodedist), i)
    try:
        logger.info("Num nodes/p %d Num nodes/slot %g nodedist %g",
                    num_nodes[i-1], p*num_nodes[i-1]/Q, nodedist)
        if nodedist > 1:
            return dagset[i-nd]*r
        elif nodedist < 1 or i == 0:
            return dagset[i]*r
    except IndexError:
        pass
    return dagset[i-1]*r


class FslRenderer(object):
    """a model that can created by FSL"""

    def __init__(self, name):
        self.model = name
        self.mirror_axis = None
        self.fm_nlin = None
        self.shaft = None
        self.agndst = 1

    def mirror_nodechains(self, p0, p1):
        self.mirror_axis = np.array((p0, p1)).ravel().tolist()

    def material(self, p0):
        self.fm_nlin = p0

    def circle(self, center, radius, color='blue'):
        num = int(2*np.pi*radius)
        if num < 8:
            num = 8
        circle = [u'cx, cy = {}, {}'.format(center[0],
                                            center[1]),
                  u'nc_circle_m(cx,cy,{}, {})'.format(radius, num),
                  u'create_mesh_se(cx, cy)\n']
        self.content += circle

    def arc(self, startangle, endangle, center, radius, color='blue'):
        num = 0
        #d = (endangle - startangle) % 2*np.pi
        #num = int(radius*d/self.agndst + 1)
        # if num < 3 and d > np.pi/6:
        #    num = 3
        # else:
        #    num = 0

        p1 = (center[0] + radius*np.cos(startangle),
              center[1] + radius*np.sin(startangle))
        p2 = (center[0] + radius*np.cos(endangle),
              center[1] + radius*np.sin(endangle))
        self.content.append(
            u"nc_circle_m({}, {}, {}, {}, {}, {}, {})".format(
                p1[0], p1[1], p2[0], p2[1],
                center[0], center[1], num))

    def ellipse(self, center, width, height,
{'fraction_non_alphanumeric': 0.16173530587764895, 'fraction_numerical': 0.03558576569372251, 'mean_word_length': 1.924021040327294, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1858873', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1724, 'n_words': 427}