<commit_before>/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

/* poly.c
 */

#include "neato.h"
#include <assert.h>
#include <string.h>
#include <math.h>
#include "poly.h"
#include "mem.h"


#define BOX 1
#define ISBOX(p) ((p)->kind & BOX)
#define CIRCLE 2
#define ISCIRCLE(p) ((p)->kind & CIRCLE)

static int maxcnt = 0;
static Point *tp1 = NULL;
static Point *tp2 = NULL;
static Point *tp3 = NULL;

void polyFree()
{
    maxcnt = 0;
    free(tp1);
    free(tp2);
    free(tp3);
    tp1 = NULL;
    tp2 = NULL;
    tp3 = NULL;
}

void breakPoly(Poly * pp)
{
    free(pp->verts);
}

static void bbox(Point * verts, int cnt, Point * o, Point * c)
{
    double xmin, ymin, xmax, ymax;
    int i;

    xmin = xmax = verts->x;
    ymin = ymax = verts->y;
    for (i = 1; i < cnt; i++) {
	verts++;
	if (verts->x < xmin)
	    xmin = verts->x;
	if (verts->y < ymin)
	    ymin = verts->y;
	if (verts->x > xmax)
	    xmax = verts->x;
	if (verts->y > ymax)
	    ymax = verts->y;
    }
    o->x = xmin;
    o->y = ymin;
    c->x = xmax;
    c->y = ymax;
}

#ifdef OLD
static void inflate(Point * prev, Point * cur, Point * next, double margin)
{
    double theta = atan2(prev->y - cur->y, prev->x - cur->x);
    double phi = atan2(next->y - cur->y, next->x - cur->x);
    double beta = (theta + phi) / 2.0;
    double gamma = (PI + phi - theta) / 2.0;
    double denom;

    denom = cos(gamma);
    cur->x -= margin * (cos(beta)) / denom;
    cur->y -= margin * (sin(beta)) / denom;
}

static void inflatePts(Point * verts, int cnt, double margin)
{
    int i;
    Point first;
    Point savepoint;
    Point prevpoint;
    Point *prev = &prevpoint;
    Point *cur;
    Point *next;

    first = verts[0];
    prevpoint = verts[cnt - 1];
    cur = &verts[0];
    next = &verts[1];
    for (i = 0; i < cnt - 1; i++) {
	savepoint = *cur;
	inflate(prev, cur, next, margin);
	cur++;
	next++;
	prevpoint = savepoint;
    }

    next = &first;
    inflate(prev, cur, next, margin);
}
#else
static void inflatePts(Point * verts, int cnt, double margin)
{
    int i;
    Point *cur;

    cur = &verts[0];
    for (i = 0; i < cnt; i++) {
	cur->x *= margin;
	cur->y *= margin;
	cur++;
    }
}
#endif

static int isBox(Point * verts, int cnt)
{
    if (cnt != 4)
	return 0;

    if (verts[0].y == verts[1].y)
	return ((verts[2].y == verts[3].y) &&
		(verts[0].x == verts[3].x) && (verts[1].x == verts[2].x));
    else
	return ((verts[0].x == verts[1].x) &&
		(verts[2].x == verts[3].x) &&
		(verts[0].y == verts[3].y) && (verts[1].y == verts[2].y));
}

static Point makeScaledPoint(int x, int y)
{
    Point rv;
    rv.x = PS2INCH(x);
    rv.y = PS2INCH(y);
    return rv;
}

static Point *genRound(Agnode_t * n, int *sidep)
{
    int sides = 0;
    Point *verts;
    char *p = agget(n, "samplepoints");
    int i;

    if (p)
	sides = atoi(p);
    if (sides < 3)
	sides = DFLT_SAMPLE;
    verts = N_GNEW(sides, Point);
    for (i = 0; i < sides; i++) {
	verts[i].x =
	    ND_width(n) / 2.0 * cos(i / (double) sides * PI * 2.0);
	verts[i].y =
	    ND_height(n) / 2.0 * sin(i / (double) sides * PI * 2.0);
    }
    *sidep = sides;
    return verts;
}
<commit_msg>Rely on general constant for default sample size<commit_after>/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

/* poly.c
 */

#include "neato.h"
#include <assert.h>
#include <string.h>
#include <math.h>
#include "poly.h"
#include "mem.h"


#define BOX 1
#define ISBOX(p) ((p)->kind & BOX)
#define CIRCLE 2
#define ISCIRCLE(p) ((p)->kind & CIRCLE)

static int maxcnt = 0;
static Point *tp1 = NULL;
static Point *tp2 = NULL;
static Point *tp3 = NULL;

void polyFree()
{
    maxcnt = 0;
    free(tp1);
    free(tp2);
    free(tp3);
    tp1 = NULL;
    tp2 = NULL;
    tp3 = NULL;
}

void breakPoly(Poly * pp)
{
    free(pp->verts);
}

static void bbox(Point * verts, int cnt, Point * o, Point * c)
{
    double xmin, ymin, xmax, ymax;
    int i;

    xmin = xmax = verts->x;
    ymin = ymax = verts->y;
    for (i = 1; i < cnt; i++) {
	verts++;
	if (verts->x < xmin)
	    xmin = verts->x;
	if (verts->y < ymin)
	    ymin = verts->y;
	if (verts->x > xmax)
	    xmax = verts->x;
	if (verts->y > ymax)
	    ymax = verts->y;
    }
    o->x = xmin;
    o->y = ymin;
    c->x = xmax;
    c->y = ymax;
}

#ifdef OLD
static void inflate(Point * prev, Point * cur, Point * next, double margin)
{
    double theta = atan2(prev->y - cur->y, prev->x - cur->x);
    double phi = atan2(next->y - cur->y, next->x - cur->x);
    double beta = (theta + phi) / 2.0;
    double gamma = (PI + phi - theta) / 2.0;
    double denom;

    denom = cos(gamma);
    cur->x -= margin * (cos(beta)) / denom;
    cur->y -= margin * (sin(beta)) / denom;
}

static void inflatePts(Point * verts, int cnt, double margin)
{
    int i;
    Point first;
    Point savepoint;
    Point prevpoint;
    Point *prev = &prevpoint;
    Point *cur;
    Point *next;

    first = verts[0];
    prevpoint = verts[cnt - 1];
    cur = &verts[0];
    next = &verts[1];
    for (i = 0; i < cnt - 1; i++) {
	savepoint = *cur;
	inflate(prev, cur, next, margin);
	cur++;
	next++;
	prevpoint = savepoint;
    }

    next = &first;
    inflate(prev, cur, next, margin);
}
#else
static void inflatePts(Point * verts, int cnt, double margin)
{
    int i;
    Point *cur;

    cur = &verts[0];
    for (i = 0; i < cnt; i++) {
	cur->x *= margin;
	cur->y *= margin;
	cur++;
    }
}
#endif

static int isBox(Point * verts, int cnt)
{
    if (cnt != 4)
	return 0;

    if (verts[0].y == verts[1].y)
	return ((verts[2].y == verts[3].y) &&
		(verts[0].x == verts[3].x) && (verts[1].x == verts[2].x));
    else
	return ((verts[0].x == verts[1].x) &&
		(verts[2].x == verts[3].x) &&
		(verts[0].y == verts[3].y) && (verts[1].y == verts[2].y));
}

#define DFLT_SAMPLE 20

static Point makeScaledPoint(int x, int y)
{
    Point rv;
    rv.x = PS2INCH(x);
    rv.y = PS2INCH(y);
    return rv;
}

static Point *genRound(Agnode_t * n, int *sidep)
{
    int sides = 0;
    Point *verts;
    char *p = agget(n, "samplepoints");
    int i;

    if (p)
	sides = atoi(p);
    if (sides < 3)
	sides = DFLT_SAMPLE;
    verts = N_GNEW(sides, Point);
    for (i = 0; i < sides; i++) {
	verts[i].x =
	    ND_width(n) / 2.0 * cos(i / (double) sides * PI * 2.0);
	verts[i].y =
	    ND_height(n) / 2.0 * sin(i / (double) sides * PI * 2.0);
    }
    *sidep = sides;
    return verts;
}

{'fraction_non_alphanumeric': 0.19651326752980386, 'fraction_numerical': 0.018459171901038327, 'mean_word_length': 2.005392912172573, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1734304', 'n_tokens_mistral': 3066, 'n_tokens_neox': 2957, 'n_words': 790}