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 9041107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:09:33+00:00 2026-06-16T10:09:33+00:00

I’ve currently implemented the Bresenham line algorithm for a tile based world editor I’m

  • 0

I’ve currently implemented the Bresenham line algorithm for a tile based world editor I’m developing. For Shift + Click functionality, I would like to render a line based off the selection rectangle from a tileset. This is simple, as I can just find the points on the line from point1 to point2 using the algorithm and draw the selection at each point.

The issue with this is that the points overlap when the selection rectangle is larger than one tile. The result is as seen below.

Current

My question is given all the points on a line, and the selection size, how can I get a result like this? Note that I want to stop drawing the selection once it goes past point2.

Desired

Here’s what I have currently for rendering a line without respect to the selection size.

void renderPoint(Point point, bool invalidate = false)
{
    Rectangle selection = world.SelectionRectangle;

    int width = selection.Width / world.Settings.TileSize.Width,
        height = selection.Height / world.Settings.TileSize.Height,
        offsetX = (int)Math.Floor((float)width / 2),
        offsetY = (int)Math.Floor((float)height / 2);

    for (int x = point.X, sx = 0; x < point.X + width; x++, sx++)
    {
        for (int y = point.Y, sy = 0; y < point.Y + height; y++, sy++)
        {
            Point change = new Point(x - offsetX, y - offsetY);

            if (!changesUndo.ContainsKey(change))
                changesUndo[change] = world.GetTile(change);

            WorldTile tile = new WorldTile(selection.X + (sx * world.Settings.TileSize.Width), selection.Y + (sy * world.Settings.TileSize.Height), 0);

            world.SetTile(change.X, change.Y, tile);

            changesRedo[change] = tile;
        }
    }

    lastRenderedPoint = point;

    if (invalidate)
        world.InvalidateCanvas();
}

void renderLine(Point p1, Point p2)
{
    List<Point> points = pointsOnLine(p1, p2);

    for (int i = 0; i < points.Count; i++)
        renderPoint(points[i], i == points.Count - 1);
}

Leave a comment if you need more context of my code.

  • 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-06-16T10:09:35+00:00Added an answer on June 16, 2026 at 10:09 am

    If the points are rendered with Bresenham, then you have to skip every ‘n-1’ out of ‘n’ points, where ‘n’ is the selection size in the major direction of the line (i.e. if it’s a mostly horizontal line, the width).

    Something like this? :

    void renderLine(Point p1, Point p2)
    {
        List<Point> points = pointsOnLine(p1, p2);
    
        int dx = Abs(p2.x - p1.x);
        int dy = Abs(p2.y - p1.y);
    
        Rectangle selection = world.SelectionRectangle;
    
        int incr = selection.Width / world.Settings.TileSize.Width;
        if(dy > dx)
        {
            incr = selection.Height / world.Settings.TileSize.Height;
        }
    
        int lastPoint = (points.Count-1) / incr;
        lastPoint *= incr;
    
        for (int i = 0; i <= lastPoint; i+=incr)
            renderPoint(points[i], i == lastPoint);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am currently running into a problem where an element is coming back from

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.