Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 843211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:05:20+00:00 2026-05-15T06:05:20+00:00

I’m stuck thinking about the best way to go about setting a line segment’s

  • 0

I’m stuck thinking about the best way to go about setting a line segment’s position, I have a class Line(length, angle, previous) being called from a class Polygon.. Right now I have:

public class Line extends Sprite {
    public function Line(length:Number, angle:Number, previous:Line = null) {
        if (previous != null) {
            this.x = previous.end.x;
            this.y = previous.end.y;
        } else {
            this.x = 0;
            this.y = 0;
        }
        /**/
    }
}

Now, is this the best practice or should I be doing:

Polygon.addLine(length:Number, angle:Number):void {
    var previous = (_line.length == 0) ? null : _line[_line.length - 1]; // Array containing all Lines
    var line:Line = new Line(length, angle, previous);
    line.x = (_line.length == 0) ? 0 : previous.end.x;
    line.y = (_line.length == 0) ? 0 : previous.end.y;
    /**/
}

One thing to add, Line is only used by Polygon in this application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:05:21+00:00Added an answer on May 15, 2026 at 6:05 am

    Edit: Completely rewrote my answer based on your comments…

    Ok, so you always have a Line class and the question is where to put the logic to add a line to a polygon.

    Your Line CTor assumes that there is an optional predecessor Line object. If you change that so the CTor takes an optional Point, there will be less coupling. Other classes, that might come in the future, can also construct lines using a starting point, length and angle. So the CTor approach looks good from that perspective.

    Also, a polygon is basically a bunch of connected lines (and arcs as your comment suggests) so the logic for calculating the end point of a line seems to really belong into the Line class. Again, this way possible other users of Line won’t have to duplicate Polygon‘s code.

    As already mentioned, there is a third way:
    You can for example create a LineFactory class that creates a Line object based on start point, length and angle. That factory function would then do the calculation and set the start and in the end set end points of the line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.