<commit_before>import _mapValues from 'lodash/mapValues';

import {constantOrFormula} from '../utils/generic';

const keyToTransform = [
	'id',
	'transforms',
	'transformOrigin',
	'componentClass',
];

export default class Component {
	constructor(source) {
		if (Array.isArray(source.base)) {
			this.base = source.base.map(base => constantOrFormula(base));
		}
		else {
			this.base = [constantOrFormula(source.base)];
		}

		this.parameters = _mapValues(source.parameters, param => constantOrFormula(param));
		this.id = constantOrFormula(source.id);
		this.componentClass = constantOrFormula(source.class);
		this.anchors = (source.anchor || []).map((item, i) => _mapValues(
			item,
			(props, name) => constantOrFormula(props, `anchors.${i}.${name}`),
		));

		this.transforms = constantOrFormula(source.transforms);
		this.transformOrigin = constantOrFormula(source.transformOrigin);
	}

	constructComponent(params, contours, parentAnchors, utils, glyphs, parentTransformTuple) {
		const localParams = {
			...params,
			..._mapValues(
				this.parameters,
				param => param.getResult(params),
			),
		};

		let opDone = {anchors: []};

		for (let i = 0; i < Object.keys(this.anchors).length; i++) {
			const key = Object.keys(this.anchors)[i];
			const anchor = this.anchors[key];
			const accumulator = {};
			const anchorKeys = Object.keys(anchor);

			for (let j = 0; j < anchorKeys.length; j++) {
				const name = anchorKeys[j];

				accumulator[name] = anchor[name].getResult(localParams, contours, accumulator, parentAnchors, utils);
			}

			opDone.anchors[key] = accumulator;
		}

		const computedBase = params.componentChoice || this.base[0].getResult(
			localParams,
			contours,
			opDone.anchors,
			parentAnchors,<commit_msg>take contours and anchors into account for component parameters<commit_after>import _mapValues from 'lodash/mapValues';

import {constantOrFormula} from '../utils/generic';

const keyToTransform = [
	'id',
	'transforms',
	'transformOrigin',
	'componentClass',
];

export default class Component {
	constructor(source) {
		if (Array.isArray(source.base)) {
			this.base = source.base.map(base => constantOrFormula(base));
		}
		else {
			this.base = [constantOrFormula(source.base)];
		}

		this.parameters = _mapValues(source.parameters, param => constantOrFormula(param));
		this.id = constantOrFormula(source.id);
		this.componentClass = constantOrFormula(source.class);
		this.anchors = (source.anchor || []).map((item, i) => _mapValues(
			item,
			(props, name) => constantOrFormula(props, `anchors.${i}.${name}`),
		));

		this.transforms = constantOrFormula(source.transforms);
		this.transformOrigin = constantOrFormula(source.transformOrigin);
	}

	constructComponent(params, contours, parentAnchors, utils, glyphs, parentTransformTuple) {
		const localParams = {
			...params,
			..._mapValues(
				this.parameters,
				param => param.getResult(params, contours, [], parentAnchors, utils),
			),
		};

		let opDone = {anchors: []};

		for (let i = 0; i < Object.keys(this.anchors).length; i++) {
			const key = Object.keys(this.anchors)[i];
			const anchor = this.anchors[key];
			const accumulator = {};
			const anchorKeys = Object.keys(anchor);

			for (let j = 0; j < anchorKeys.length; j++) {
				const name = anchorKeys[j];

				accumulator[name] = anchor[name].getResult(
					localParams,
					contours,
					accumulator,
					parentAnchors,
					utils,
				);
			}

			opDone.anchors[key] = accumulator;
		}

		const computedBase = params.componentChoice || this.base[0].getResult(
			localParams,
			contours,
			opDone.anchors,
			parentAnchors,
{'fraction_non_alphanumeric': 0.14692861095738793, 'fraction_numerical': 0.0016602102933038186, 'mean_word_length': 4.134943181818182, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '6952413', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1172, 'n_words': 229}