Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is my polygon component worth a PR #351

Closed
dagda1 opened this issue Sep 7, 2018 · 4 comments
Closed

Is my polygon component worth a PR #351

dagda1 opened this issue Sep 7, 2018 · 4 comments

Comments

@dagda1
Copy link

dagda1 commented Sep 7, 2018

I've created a polygon react component:

import * as React from 'react';
import { Point } from '../../model';
import { range } from 'lodash';
import { degreesToRadians } from '../../util/trigonometry';

export interface PolygonProps {
  sides: number;
  size: number;
  center?: Point;
  className?: string;
  rotate?: number;
}

export const getPoints = ({
  sides,
  size,
  center,
  rotate
}: {
  sides: number;
  size: number;
  center: Point;
  rotate: number;
}): Point[] => {
  return range(0, sides).map((n) => {
    const degrees = (360 / sides) * n - rotate;
    const radians = degreesToRadians(degrees);

    return new Point({
      x: center.x + size * Math.cos(radians),
      y: center.y + size * Math.sin(radians)
    });
  });
};

export const Polygon: React.SFC<PolygonProps> = ({
  sides,
  size = 25,
  center = new Point({ x: 0, y: 0 }),
  rotate = 0,
  className
}) => {
  const points = getPoints({ sides, size, center, rotate })
    .map((p) => p.toArray())
    .join(' ');

  return <polygon points={points} className={className} />;
};

I've just blogged about it here.

Do you think this is something worth putting into the vx?

It can create any equal sided polygon. I've been using vx recently and it might be useful to others or maybe not :).

@hshoff
Copy link
Member

hshoff commented Sep 10, 2018

nice! yeah happy to take a look at PR.

@dagda1
Copy link
Author

dagda1 commented Sep 13, 2018

@hshoff I have created a PR #355

@dagda1
Copy link
Author

dagda1 commented Sep 17, 2018

@hshoff whenever you have time, no rush from me.

@hshoff
Copy link
Member

hshoff commented Sep 18, 2018

landed in #355

@hshoff hshoff closed this as completed Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants